Finish un-exporting symbols.
This commit is contained in:
parent
4e6528a75b
commit
55e85f3f75
|
@ -53,7 +53,7 @@ func createBackwardReferences(num_bytes uint, position uint, ringbuffer []byte,
|
|||
} else {
|
||||
store_end = position
|
||||
}
|
||||
var random_heuristics_window_size uint = LiteralSpreeLengthForSparseSearch(params)
|
||||
var random_heuristics_window_size uint = literalSpreeLengthForSparseSearch(params)
|
||||
var apply_random_heuristics uint = position + random_heuristics_window_size
|
||||
var gap uint = 0
|
||||
/* Set maximum distance, see section 9.1. of the spec. */
|
||||
|
@ -81,7 +81,7 @@ func createBackwardReferences(num_bytes uint, position uint, ringbuffer []byte,
|
|||
for ; ; max_length-- {
|
||||
var cost_diff_lazy uint = 175
|
||||
var sr2 hasherSearchResult
|
||||
if params.quality < MIN_QUALITY_FOR_EXTENSIVE_REFERENCE_SEARCH {
|
||||
if params.quality < minQualityForExtensiveReferenceSearch {
|
||||
sr2.len = brotli_min_size_t(sr.len-1, max_length)
|
||||
} else {
|
||||
sr2.len = 0
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brotli
|
||||
|
||||
import "math"
|
||||
|
||||
type zopfliNode struct {
|
||||
length uint32
|
||||
distance uint32
|
||||
|
@ -387,8 +389,8 @@ func updateNodes(num_bytes uint, block_start uint, pos uint, ringbuffer []byte,
|
|||
var cur_ix_masked uint = cur_ix & ringbuffer_mask
|
||||
var max_distance uint = brotli_min_size_t(cur_ix, max_backward_limit)
|
||||
var max_len uint = num_bytes - pos
|
||||
var max_zopfli_len uint = MaxZopfliLen(params)
|
||||
var max_iters uint = MaxZopfliCandidates(params)
|
||||
var max_zopfli_len uint = maxZopfliLen(params)
|
||||
var max_iters uint = maxZopfliCandidates(params)
|
||||
var min_len uint
|
||||
var result uint = 0
|
||||
var k uint
|
||||
|
@ -487,7 +489,7 @@ func updateNodes(num_bytes uint, block_start uint, pos uint, ringbuffer []byte,
|
|||
var max_match_len uint
|
||||
/* We already tried all possible last distance matches, so we can use
|
||||
normal distance code here. */
|
||||
PrefixEncodeCopyDistance(dist_code, uint(params.dist.num_direct_distance_codes), uint(params.dist.distance_postfix_bits), &dist_symbol, &distextra)
|
||||
prefixEncodeCopyDistance(dist_code, uint(params.dist.num_direct_distance_codes), uint(params.dist.distance_postfix_bits), &dist_symbol, &distextra)
|
||||
|
||||
distnumextra = uint32(dist_symbol) >> 10
|
||||
dist_cost = base_cost + float32(distnumextra) + zopfliCostModelGetDistanceCost(model, uint(dist_symbol)&0x3FF)
|
||||
|
@ -529,7 +531,7 @@ func computeShortestPathFromNodes(num_bytes uint, nodes []zopfliNode) uint {
|
|||
for nodes[index].dcode_insert_length&0x7FFFFFF == 0 && nodes[index].length == 1 {
|
||||
index--
|
||||
}
|
||||
nodes[index].u.next = BROTLI_UINT32_MAX
|
||||
nodes[index].u.next = math.MaxUint32
|
||||
for index != 0 {
|
||||
var len uint = uint(zopfliNodeCommandLength(&nodes[index]))
|
||||
index -= uint(len)
|
||||
|
@ -547,7 +549,7 @@ func zopfliCreateCommands(num_bytes uint, block_start uint, nodes []zopfliNode,
|
|||
var offset uint32 = nodes[0].u.next
|
||||
var i uint
|
||||
var gap uint = 0
|
||||
for i = 0; offset != BROTLI_UINT32_MAX; i++ {
|
||||
for i = 0; offset != math.MaxUint32; i++ {
|
||||
var next *zopfliNode = &nodes[uint32(pos)+offset]
|
||||
var copy_length uint = uint(zopfliNodeCopyLength(next))
|
||||
var insert_length uint = uint(next.dcode_insert_length & 0x7FFFFFF)
|
||||
|
@ -582,7 +584,7 @@ func zopfliCreateCommands(num_bytes uint, block_start uint, nodes []zopfliNode,
|
|||
|
||||
func zopfliIterate(num_bytes uint, position uint, ringbuffer []byte, ringbuffer_mask uint, params *encoderParams, gap uint, dist_cache []int, model *zopfliCostModel, num_matches []uint32, matches []backwardMatch, nodes []zopfliNode) uint {
|
||||
var max_backward_limit uint = maxBackwardLimit(params.lgwin)
|
||||
var max_zopfli_len uint = MaxZopfliLen(params)
|
||||
var max_zopfli_len uint = maxZopfliLen(params)
|
||||
var queue startPosQueue
|
||||
var cur_match_pos uint = 0
|
||||
var i uint
|
||||
|
@ -591,7 +593,7 @@ func zopfliIterate(num_bytes uint, position uint, ringbuffer []byte, ringbuffer_
|
|||
initStartPosQueue(&queue)
|
||||
for i = 0; i+3 < num_bytes; i++ {
|
||||
var skip uint = updateNodes(num_bytes, position, i, ringbuffer, ringbuffer_mask, params, max_backward_limit, dist_cache, uint(num_matches[i]), matches[cur_match_pos:], model, &queue, nodes)
|
||||
if skip < BROTLI_LONG_COPY_QUICK_STEP {
|
||||
if skip < longCopyQuickStep {
|
||||
skip = 0
|
||||
}
|
||||
cur_match_pos += uint(num_matches[i])
|
||||
|
@ -619,7 +621,7 @@ func zopfliIterate(num_bytes uint, position uint, ringbuffer []byte, ringbuffer_
|
|||
/* REQUIRES: nodes != NULL and len(nodes) >= num_bytes + 1 */
|
||||
func zopfliComputeShortestPath(num_bytes uint, position uint, ringbuffer []byte, ringbuffer_mask uint, params *encoderParams, dist_cache []int, hasher *h10, nodes []zopfliNode) uint {
|
||||
var max_backward_limit uint = maxBackwardLimit(params.lgwin)
|
||||
var max_zopfli_len uint = MaxZopfliLen(params)
|
||||
var max_zopfli_len uint = maxZopfliLen(params)
|
||||
var model zopfliCostModel
|
||||
var queue startPosQueue
|
||||
var matches [2 * (maxNumMatchesH10 + 64)]backwardMatch
|
||||
|
@ -649,7 +651,7 @@ func zopfliComputeShortestPath(num_bytes uint, position uint, ringbuffer []byte,
|
|||
}
|
||||
|
||||
skip = updateNodes(num_bytes, position, i, ringbuffer, ringbuffer_mask, params, max_backward_limit, dist_cache, num_matches, matches[:], &model, &queue, nodes)
|
||||
if skip < BROTLI_LONG_COPY_QUICK_STEP {
|
||||
if skip < longCopyQuickStep {
|
||||
skip = 0
|
||||
}
|
||||
if num_matches == 1 && backwardMatchLength(&matches[0]) > max_zopfli_len {
|
||||
|
@ -744,7 +746,7 @@ func createHqZopfliBackwardReferences(num_bytes uint, position uint, ringbuffer
|
|||
num_matches[i] = uint32(num_found_matches)
|
||||
if num_found_matches > 0 {
|
||||
var match_len uint = backwardMatchLength(&matches[cur_match_end-1])
|
||||
if match_len > MAX_ZOPFLI_LEN_QUALITY_11 {
|
||||
if match_len > maxZopfliLenQuality11 {
|
||||
var skip uint = match_len - 1
|
||||
matches[cur_match_pos] = matches[cur_match_end-1]
|
||||
cur_match_pos++
|
||||
|
|
|
@ -154,7 +154,7 @@ func get16BitsUnmasked(br *bitReader) uint32 {
|
|||
|
||||
/* Returns the specified number of bits from |br| without advancing bit
|
||||
position. */
|
||||
func BrotliGetBits(br *bitReader, n_bits uint32) uint32 {
|
||||
func getBits(br *bitReader, n_bits uint32) uint32 {
|
||||
fillBitWindow(br, n_bits)
|
||||
return uint32(getBitsUnmasked(br)) & bitMask(n_bits)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brotli
|
||||
|
||||
import "math"
|
||||
|
||||
/* NOLINT(build/header_guard) */
|
||||
/* Copyright 2013 Google Inc. All Rights Reserved.
|
||||
|
||||
|
@ -184,7 +186,7 @@ func buildBlockHistogramsCommand(data []uint16, length uint, block_ids []byte, n
|
|||
}
|
||||
}
|
||||
|
||||
var clusterBlocksCommand_kInvalidIndex uint32 = BROTLI_UINT32_MAX
|
||||
var clusterBlocksCommand_kInvalidIndex uint32 = math.MaxUint32
|
||||
|
||||
func clusterBlocksCommand(data []uint16, length uint, num_blocks uint, block_ids []byte, split *blockSplit) {
|
||||
var histogram_symbols []uint32 = make([]uint32, num_blocks)
|
||||
|
@ -406,7 +408,7 @@ func splitByteVectorCommand(data []uint16, length uint, literals_per_histogram u
|
|||
var switch_signal []byte = make([]byte, (length * bitmaplen))
|
||||
var new_id []uint16 = make([]uint16, num_histograms)
|
||||
var iters uint
|
||||
if params.quality < HQ_ZOPFLIFICATION_QUALITY {
|
||||
if params.quality < hqZopflificationQuality {
|
||||
iters = 3
|
||||
} else {
|
||||
iters = 10
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brotli
|
||||
|
||||
import "math"
|
||||
|
||||
/* NOLINT(build/header_guard) */
|
||||
/* Copyright 2013 Google Inc. All Rights Reserved.
|
||||
|
||||
|
@ -184,7 +186,7 @@ func buildBlockHistogramsDistance(data []uint16, length uint, block_ids []byte,
|
|||
}
|
||||
}
|
||||
|
||||
var clusterBlocksDistance_kInvalidIndex uint32 = BROTLI_UINT32_MAX
|
||||
var clusterBlocksDistance_kInvalidIndex uint32 = math.MaxUint32
|
||||
|
||||
func clusterBlocksDistance(data []uint16, length uint, num_blocks uint, block_ids []byte, split *blockSplit) {
|
||||
var histogram_symbols []uint32 = make([]uint32, num_blocks)
|
||||
|
@ -406,7 +408,7 @@ func splitByteVectorDistance(data []uint16, length uint, literals_per_histogram
|
|||
var switch_signal []byte = make([]byte, (length * bitmaplen))
|
||||
var new_id []uint16 = make([]uint16, num_histograms)
|
||||
var iters uint
|
||||
if params.quality < HQ_ZOPFLIFICATION_QUALITY {
|
||||
if params.quality < hqZopflificationQuality {
|
||||
iters = 3
|
||||
} else {
|
||||
iters = 10
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brotli
|
||||
|
||||
import "math"
|
||||
|
||||
/* NOLINT(build/header_guard) */
|
||||
/* Copyright 2013 Google Inc. All Rights Reserved.
|
||||
|
||||
|
@ -184,7 +186,7 @@ func buildBlockHistogramsLiteral(data []byte, length uint, block_ids []byte, num
|
|||
}
|
||||
}
|
||||
|
||||
var clusterBlocksLiteral_kInvalidIndex uint32 = BROTLI_UINT32_MAX
|
||||
var clusterBlocksLiteral_kInvalidIndex uint32 = math.MaxUint32
|
||||
|
||||
func clusterBlocksLiteral(data []byte, length uint, num_blocks uint, block_ids []byte, split *blockSplit) {
|
||||
var histogram_symbols []uint32 = make([]uint32, num_blocks)
|
||||
|
@ -406,7 +408,7 @@ func splitByteVectorLiteral(data []byte, length uint, literals_per_histogram uin
|
|||
var switch_signal []byte = make([]byte, (length * bitmaplen))
|
||||
var new_id []uint16 = make([]uint16, num_histograms)
|
||||
var iters uint
|
||||
if params.quality < HQ_ZOPFLIFICATION_QUALITY {
|
||||
if params.quality < hqZopflificationQuality {
|
||||
iters = 3
|
||||
} else {
|
||||
iters = 10
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brotli
|
||||
|
||||
import "math"
|
||||
|
||||
const maxHuffmanTreeSize = (2*numCommandSymbols + 1)
|
||||
|
||||
/* The maximum size of Huffman dictionary for distances assuming that
|
||||
|
@ -124,7 +126,7 @@ func storeCommandExtra(cmd *command, storage_ix *uint, storage []byte) {
|
|||
var insextraval uint64 = uint64(cmd.insert_len_) - uint64(getInsertBase(inscode))
|
||||
var copyextraval uint64 = uint64(copylen_code) - uint64(getCopyBase(copycode))
|
||||
var bits uint64 = copyextraval<<insnumextra | insextraval
|
||||
BrotliWriteBits(uint(insnumextra+getCopyExtra(copycode)), bits, storage_ix, storage)
|
||||
writeBits(uint(insnumextra+getCopyExtra(copycode)), bits, storage_ix, storage)
|
||||
}
|
||||
|
||||
/* Data structure that stores almost everything that is needed to encode each
|
||||
|
@ -140,12 +142,12 @@ type blockSplitCode struct {
|
|||
/* Stores a number between 0 and 255. */
|
||||
func storeVarLenUint8(n uint, storage_ix *uint, storage []byte) {
|
||||
if n == 0 {
|
||||
BrotliWriteBits(1, 0, storage_ix, storage)
|
||||
writeBits(1, 0, storage_ix, storage)
|
||||
} else {
|
||||
var nbits uint = uint(log2FloorNonZero(n))
|
||||
BrotliWriteBits(1, 1, storage_ix, storage)
|
||||
BrotliWriteBits(3, uint64(nbits), storage_ix, storage)
|
||||
BrotliWriteBits(nbits, uint64(n)-(uint64(uint(1))<<nbits), storage_ix, storage)
|
||||
writeBits(1, 1, storage_ix, storage)
|
||||
writeBits(3, uint64(nbits), storage_ix, storage)
|
||||
writeBits(nbits, uint64(n)-(uint64(uint(1))<<nbits), storage_ix, storage)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,20 +166,20 @@ func storeCompressedMetaBlockHeader(is_final_block bool, length uint, storage_ix
|
|||
}
|
||||
|
||||
/* Write ISLAST bit. */
|
||||
BrotliWriteBits(1, is_final, storage_ix, storage)
|
||||
writeBits(1, is_final, storage_ix, storage)
|
||||
|
||||
/* Write ISEMPTY bit. */
|
||||
if is_final_block {
|
||||
BrotliWriteBits(1, 0, storage_ix, storage)
|
||||
writeBits(1, 0, storage_ix, storage)
|
||||
}
|
||||
|
||||
encodeMlen(length, &lenbits, &nlenbits, &nibblesbits)
|
||||
BrotliWriteBits(2, nibblesbits, storage_ix, storage)
|
||||
BrotliWriteBits(nlenbits, lenbits, storage_ix, storage)
|
||||
writeBits(2, nibblesbits, storage_ix, storage)
|
||||
writeBits(nlenbits, lenbits, storage_ix, storage)
|
||||
|
||||
if !is_final_block {
|
||||
/* Write ISUNCOMPRESSED bit. */
|
||||
BrotliWriteBits(1, 0, storage_ix, storage)
|
||||
writeBits(1, 0, storage_ix, storage)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,14 +193,14 @@ func storeUncompressedMetaBlockHeader(length uint, storage_ix *uint, storage []b
|
|||
|
||||
/* Write ISLAST bit.
|
||||
Uncompressed block cannot be the last one, so set to 0. */
|
||||
BrotliWriteBits(1, 0, storage_ix, storage)
|
||||
writeBits(1, 0, storage_ix, storage)
|
||||
|
||||
encodeMlen(length, &lenbits, &nlenbits, &nibblesbits)
|
||||
BrotliWriteBits(2, nibblesbits, storage_ix, storage)
|
||||
BrotliWriteBits(nlenbits, lenbits, storage_ix, storage)
|
||||
writeBits(2, nibblesbits, storage_ix, storage)
|
||||
writeBits(nlenbits, lenbits, storage_ix, storage)
|
||||
|
||||
/* Write ISUNCOMPRESSED bit. */
|
||||
BrotliWriteBits(1, 1, storage_ix, storage)
|
||||
writeBits(1, 1, storage_ix, storage)
|
||||
}
|
||||
|
||||
var storeHuffmanTreeOfHuffmanTreeToBitMask_kStorageOrder = [codeLengthCodes]byte{1, 2, 3, 4, 0, 5, 17, 6, 16, 7, 8, 9, 10, 11, 12, 13, 14, 15}
|
||||
|
@ -236,12 +238,12 @@ func storeHuffmanTreeOfHuffmanTreeToBitMask(num_codes int, code_length_bitdepth
|
|||
}
|
||||
}
|
||||
|
||||
BrotliWriteBits(2, uint64(skip_some), storage_ix, storage)
|
||||
writeBits(2, uint64(skip_some), storage_ix, storage)
|
||||
{
|
||||
var i uint
|
||||
for i = skip_some; i < codes_to_store; i++ {
|
||||
var l uint = uint(code_length_bitdepth[storeHuffmanTreeOfHuffmanTreeToBitMask_kStorageOrder[i]])
|
||||
BrotliWriteBits(uint(storeHuffmanTreeOfHuffmanTreeToBitMask_kHuffmanBitLengthHuffmanCodeBitLengths[l]), uint64(storeHuffmanTreeOfHuffmanTreeToBitMask_kHuffmanBitLengthHuffmanCodeSymbols[l]), storage_ix, storage)
|
||||
writeBits(uint(storeHuffmanTreeOfHuffmanTreeToBitMask_kHuffmanBitLengthHuffmanCodeBitLengths[l]), uint64(storeHuffmanTreeOfHuffmanTreeToBitMask_kHuffmanBitLengthHuffmanCodeSymbols[l]), storage_ix, storage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -250,24 +252,24 @@ func storeHuffmanTreeToBitMask(huffman_tree_size uint, huffman_tree []byte, huff
|
|||
var i uint
|
||||
for i = 0; i < huffman_tree_size; i++ {
|
||||
var ix uint = uint(huffman_tree[i])
|
||||
BrotliWriteBits(uint(code_length_bitdepth[ix]), uint64(code_length_bitdepth_symbols[ix]), storage_ix, storage)
|
||||
writeBits(uint(code_length_bitdepth[ix]), uint64(code_length_bitdepth_symbols[ix]), storage_ix, storage)
|
||||
|
||||
/* Extra bits */
|
||||
switch ix {
|
||||
case repeatPreviousCodeLength:
|
||||
BrotliWriteBits(2, uint64(huffman_tree_extra_bits[i]), storage_ix, storage)
|
||||
writeBits(2, uint64(huffman_tree_extra_bits[i]), storage_ix, storage)
|
||||
|
||||
case repeatZeroCodeLength:
|
||||
BrotliWriteBits(3, uint64(huffman_tree_extra_bits[i]), storage_ix, storage)
|
||||
writeBits(3, uint64(huffman_tree_extra_bits[i]), storage_ix, storage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func storeSimpleHuffmanTree(depths []byte, symbols []uint, num_symbols uint, max_bits uint, storage_ix *uint, storage []byte) {
|
||||
/* value of 1 indicates a simple Huffman code */
|
||||
BrotliWriteBits(2, 1, storage_ix, storage)
|
||||
writeBits(2, 1, storage_ix, storage)
|
||||
|
||||
BrotliWriteBits(2, uint64(num_symbols)-1, storage_ix, storage) /* NSYM - 1 */
|
||||
writeBits(2, uint64(num_symbols)-1, storage_ix, storage) /* NSYM - 1 */
|
||||
{
|
||||
/* Sort */
|
||||
var i uint
|
||||
|
@ -284,17 +286,17 @@ func storeSimpleHuffmanTree(depths []byte, symbols []uint, num_symbols uint, max
|
|||
}
|
||||
|
||||
if num_symbols == 2 {
|
||||
BrotliWriteBits(max_bits, uint64(symbols[0]), storage_ix, storage)
|
||||
BrotliWriteBits(max_bits, uint64(symbols[1]), storage_ix, storage)
|
||||
writeBits(max_bits, uint64(symbols[0]), storage_ix, storage)
|
||||
writeBits(max_bits, uint64(symbols[1]), storage_ix, storage)
|
||||
} else if num_symbols == 3 {
|
||||
BrotliWriteBits(max_bits, uint64(symbols[0]), storage_ix, storage)
|
||||
BrotliWriteBits(max_bits, uint64(symbols[1]), storage_ix, storage)
|
||||
BrotliWriteBits(max_bits, uint64(symbols[2]), storage_ix, storage)
|
||||
writeBits(max_bits, uint64(symbols[0]), storage_ix, storage)
|
||||
writeBits(max_bits, uint64(symbols[1]), storage_ix, storage)
|
||||
writeBits(max_bits, uint64(symbols[2]), storage_ix, storage)
|
||||
} else {
|
||||
BrotliWriteBits(max_bits, uint64(symbols[0]), storage_ix, storage)
|
||||
BrotliWriteBits(max_bits, uint64(symbols[1]), storage_ix, storage)
|
||||
BrotliWriteBits(max_bits, uint64(symbols[2]), storage_ix, storage)
|
||||
BrotliWriteBits(max_bits, uint64(symbols[3]), storage_ix, storage)
|
||||
writeBits(max_bits, uint64(symbols[0]), storage_ix, storage)
|
||||
writeBits(max_bits, uint64(symbols[1]), storage_ix, storage)
|
||||
writeBits(max_bits, uint64(symbols[2]), storage_ix, storage)
|
||||
writeBits(max_bits, uint64(symbols[3]), storage_ix, storage)
|
||||
|
||||
/* tree-select */
|
||||
var tmp int
|
||||
|
@ -303,7 +305,7 @@ func storeSimpleHuffmanTree(depths []byte, symbols []uint, num_symbols uint, max
|
|||
} else {
|
||||
tmp = 0
|
||||
}
|
||||
BrotliWriteBits(1, uint64(tmp), storage_ix, storage)
|
||||
writeBits(1, uint64(tmp), storage_ix, storage)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -389,8 +391,8 @@ func buildAndStoreHuffmanTree(histogram []uint32, histogram_length uint, alphabe
|
|||
}
|
||||
|
||||
if count <= 1 {
|
||||
BrotliWriteBits(4, 1, storage_ix, storage)
|
||||
BrotliWriteBits(max_bits, uint64(s4[0]), storage_ix, storage)
|
||||
writeBits(4, 1, storage_ix, storage)
|
||||
writeBits(max_bits, uint64(s4[0]), storage_ix, storage)
|
||||
depth[s4[0]] = 0
|
||||
bits[s4[0]] = 0
|
||||
return
|
||||
|
@ -432,8 +434,8 @@ func buildAndStoreHuffmanTreeFast(histogram []uint32, histogram_total uint, max_
|
|||
}
|
||||
|
||||
if count <= 1 {
|
||||
BrotliWriteBits(4, 1, storage_ix, storage)
|
||||
BrotliWriteBits(max_bits, uint64(symbols[0]), storage_ix, storage)
|
||||
writeBits(4, 1, storage_ix, storage)
|
||||
writeBits(max_bits, uint64(symbols[0]), storage_ix, storage)
|
||||
depth[symbols[0]] = 0
|
||||
bits[symbols[0]] = 0
|
||||
return
|
||||
|
@ -478,7 +480,7 @@ func buildAndStoreHuffmanTreeFast(histogram []uint32, histogram_total uint, max_
|
|||
(n+1). These are naturally in ascending order.
|
||||
[2n]: we add a sentinel at the end as well.
|
||||
There will be (2n+1) elements at the end. */
|
||||
initHuffmanTree(&sentinel, BROTLI_UINT32_MAX, -1, -1)
|
||||
initHuffmanTree(&sentinel, math.MaxUint32, -1, -1)
|
||||
|
||||
tree[node] = sentinel
|
||||
node++
|
||||
|
@ -531,9 +533,9 @@ func buildAndStoreHuffmanTreeFast(histogram []uint32, histogram_total uint, max_
|
|||
var i uint
|
||||
|
||||
/* value of 1 indicates a simple Huffman code */
|
||||
BrotliWriteBits(2, 1, storage_ix, storage)
|
||||
writeBits(2, 1, storage_ix, storage)
|
||||
|
||||
BrotliWriteBits(2, uint64(count)-1, storage_ix, storage) /* NSYM - 1 */
|
||||
writeBits(2, uint64(count)-1, storage_ix, storage) /* NSYM - 1 */
|
||||
|
||||
/* Sort */
|
||||
for i = 0; i < count; i++ {
|
||||
|
@ -548,17 +550,17 @@ func buildAndStoreHuffmanTreeFast(histogram []uint32, histogram_total uint, max_
|
|||
}
|
||||
|
||||
if count == 2 {
|
||||
BrotliWriteBits(max_bits, uint64(symbols[0]), storage_ix, storage)
|
||||
BrotliWriteBits(max_bits, uint64(symbols[1]), storage_ix, storage)
|
||||
writeBits(max_bits, uint64(symbols[0]), storage_ix, storage)
|
||||
writeBits(max_bits, uint64(symbols[1]), storage_ix, storage)
|
||||
} else if count == 3 {
|
||||
BrotliWriteBits(max_bits, uint64(symbols[0]), storage_ix, storage)
|
||||
BrotliWriteBits(max_bits, uint64(symbols[1]), storage_ix, storage)
|
||||
BrotliWriteBits(max_bits, uint64(symbols[2]), storage_ix, storage)
|
||||
writeBits(max_bits, uint64(symbols[0]), storage_ix, storage)
|
||||
writeBits(max_bits, uint64(symbols[1]), storage_ix, storage)
|
||||
writeBits(max_bits, uint64(symbols[2]), storage_ix, storage)
|
||||
} else {
|
||||
BrotliWriteBits(max_bits, uint64(symbols[0]), storage_ix, storage)
|
||||
BrotliWriteBits(max_bits, uint64(symbols[1]), storage_ix, storage)
|
||||
BrotliWriteBits(max_bits, uint64(symbols[2]), storage_ix, storage)
|
||||
BrotliWriteBits(max_bits, uint64(symbols[3]), storage_ix, storage)
|
||||
writeBits(max_bits, uint64(symbols[0]), storage_ix, storage)
|
||||
writeBits(max_bits, uint64(symbols[1]), storage_ix, storage)
|
||||
writeBits(max_bits, uint64(symbols[2]), storage_ix, storage)
|
||||
writeBits(max_bits, uint64(symbols[3]), storage_ix, storage)
|
||||
|
||||
/* tree-select */
|
||||
var tmp int
|
||||
|
@ -567,14 +569,14 @@ func buildAndStoreHuffmanTreeFast(histogram []uint32, histogram_total uint, max_
|
|||
} else {
|
||||
tmp = 0
|
||||
}
|
||||
BrotliWriteBits(1, uint64(tmp), storage_ix, storage)
|
||||
writeBits(1, uint64(tmp), storage_ix, storage)
|
||||
}
|
||||
} else {
|
||||
var previous_value byte = 8
|
||||
var i uint
|
||||
|
||||
/* Complex Huffman Tree */
|
||||
StoreStaticCodeLengthCode(storage_ix, storage)
|
||||
storeStaticCodeLengthCode(storage_ix, storage)
|
||||
|
||||
/* Actual RLE coding. */
|
||||
for i = 0; i < length; {
|
||||
|
@ -587,21 +589,21 @@ func buildAndStoreHuffmanTreeFast(histogram []uint32, histogram_total uint, max_
|
|||
|
||||
i += reps
|
||||
if value == 0 {
|
||||
BrotliWriteBits(uint(kZeroRepsDepth[reps]), kZeroRepsBits[reps], storage_ix, storage)
|
||||
writeBits(uint(kZeroRepsDepth[reps]), kZeroRepsBits[reps], storage_ix, storage)
|
||||
} else {
|
||||
if previous_value != value {
|
||||
BrotliWriteBits(uint(kCodeLengthDepth[value]), uint64(kCodeLengthBits[value]), storage_ix, storage)
|
||||
writeBits(uint(kCodeLengthDepth[value]), uint64(kCodeLengthBits[value]), storage_ix, storage)
|
||||
reps--
|
||||
}
|
||||
|
||||
if reps < 3 {
|
||||
for reps != 0 {
|
||||
reps--
|
||||
BrotliWriteBits(uint(kCodeLengthDepth[value]), uint64(kCodeLengthBits[value]), storage_ix, storage)
|
||||
writeBits(uint(kCodeLengthDepth[value]), uint64(kCodeLengthBits[value]), storage_ix, storage)
|
||||
}
|
||||
} else {
|
||||
reps -= 3
|
||||
BrotliWriteBits(uint(kNonZeroRepsDepth[reps]), kNonZeroRepsBits[reps], storage_ix, storage)
|
||||
writeBits(uint(kNonZeroRepsDepth[reps]), kNonZeroRepsBits[reps], storage_ix, storage)
|
||||
}
|
||||
|
||||
previous_value = value
|
||||
|
@ -750,9 +752,9 @@ func encodeContextMap(context_map []uint32, context_map_size uint, num_clusters
|
|||
}
|
||||
{
|
||||
var use_rle bool = (max_run_length_prefix > 0)
|
||||
BrotliWriteSingleBit(use_rle, storage_ix, storage)
|
||||
writeSingleBit(use_rle, storage_ix, storage)
|
||||
if use_rle {
|
||||
BrotliWriteBits(4, uint64(max_run_length_prefix)-1, storage_ix, storage)
|
||||
writeBits(4, uint64(max_run_length_prefix)-1, storage_ix, storage)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -760,13 +762,13 @@ func encodeContextMap(context_map []uint32, context_map_size uint, num_clusters
|
|||
for i = 0; i < num_rle_symbols; i++ {
|
||||
var rle_symbol uint32 = rle_symbols[i] & encodeContextMap_kSymbolMask
|
||||
var extra_bits_val uint32 = rle_symbols[i] >> symbolBits
|
||||
BrotliWriteBits(uint(depths[rle_symbol]), uint64(bits[rle_symbol]), storage_ix, storage)
|
||||
writeBits(uint(depths[rle_symbol]), uint64(bits[rle_symbol]), storage_ix, storage)
|
||||
if rle_symbol > 0 && rle_symbol <= max_run_length_prefix {
|
||||
BrotliWriteBits(uint(rle_symbol), uint64(extra_bits_val), storage_ix, storage)
|
||||
writeBits(uint(rle_symbol), uint64(extra_bits_val), storage_ix, storage)
|
||||
}
|
||||
}
|
||||
|
||||
BrotliWriteBits(1, 1, storage_ix, storage) /* use move-to-front */
|
||||
writeBits(1, 1, storage_ix, storage) /* use move-to-front */
|
||||
rle_symbols = nil
|
||||
}
|
||||
|
||||
|
@ -777,13 +779,13 @@ func storeBlockSwitch(code *blockSplitCode, block_len uint32, block_type byte, i
|
|||
var len_nextra uint32
|
||||
var len_extra uint32
|
||||
if !is_first_block {
|
||||
BrotliWriteBits(uint(code.type_depths[typecode]), uint64(code.type_bits[typecode]), storage_ix, storage)
|
||||
writeBits(uint(code.type_depths[typecode]), uint64(code.type_bits[typecode]), storage_ix, storage)
|
||||
}
|
||||
|
||||
getBlockLengthPrefixCode(block_len, &lencode, &len_nextra, &len_extra)
|
||||
|
||||
BrotliWriteBits(uint(code.length_depths[lencode]), uint64(code.length_bits[lencode]), storage_ix, storage)
|
||||
BrotliWriteBits(uint(len_nextra), uint64(len_extra), storage_ix, storage)
|
||||
writeBits(uint(code.length_depths[lencode]), uint64(code.length_bits[lencode]), storage_ix, storage)
|
||||
writeBits(uint(len_nextra), uint64(len_extra), storage_ix, storage)
|
||||
}
|
||||
|
||||
/* Builds a BlockSplitCode data structure from the block split given by the
|
||||
|
@ -830,9 +832,9 @@ func storeTrivialContextMap(num_types uint, context_bits uint, tree []huffmanTre
|
|||
}
|
||||
|
||||
/* Write RLEMAX. */
|
||||
BrotliWriteBits(1, 1, storage_ix, storage)
|
||||
writeBits(1, 1, storage_ix, storage)
|
||||
|
||||
BrotliWriteBits(4, uint64(repeat_code)-1, storage_ix, storage)
|
||||
writeBits(4, uint64(repeat_code)-1, storage_ix, storage)
|
||||
histogram[repeat_code] = uint32(num_types)
|
||||
histogram[0] = 1
|
||||
for i = context_bits; i < alphabet_size; i++ {
|
||||
|
@ -848,13 +850,13 @@ func storeTrivialContextMap(num_types uint, context_bits uint, tree []huffmanTre
|
|||
tmp = i + context_bits - 1
|
||||
}
|
||||
var code uint = tmp
|
||||
BrotliWriteBits(uint(depths[code]), uint64(bits[code]), storage_ix, storage)
|
||||
BrotliWriteBits(uint(depths[repeat_code]), uint64(bits[repeat_code]), storage_ix, storage)
|
||||
BrotliWriteBits(repeat_code, uint64(repeat_bits), storage_ix, storage)
|
||||
writeBits(uint(depths[code]), uint64(bits[code]), storage_ix, storage)
|
||||
writeBits(uint(depths[repeat_code]), uint64(bits[repeat_code]), storage_ix, storage)
|
||||
writeBits(repeat_code, uint64(repeat_bits), storage_ix, storage)
|
||||
}
|
||||
|
||||
/* Write IMTF (inverse-move-to-front) bit. */
|
||||
BrotliWriteBits(1, 1, storage_ix, storage)
|
||||
writeBits(1, 1, storage_ix, storage)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -918,7 +920,7 @@ func storeSymbol(self *blockEncoder, symbol uint, storage_ix *uint, storage []by
|
|||
self.block_len_--
|
||||
{
|
||||
var ix uint = self.entropy_ix_ + symbol
|
||||
BrotliWriteBits(uint(self.depths_[ix]), uint64(self.bits_[ix]), storage_ix, storage)
|
||||
writeBits(uint(self.depths_[ix]), uint64(self.bits_[ix]), storage_ix, storage)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -940,7 +942,7 @@ func storeSymbolWithContext(self *blockEncoder, symbol uint, context uint, conte
|
|||
{
|
||||
var histo_ix uint = uint(context_map[self.entropy_ix_+context])
|
||||
var ix uint = histo_ix*self.histogram_length_ + symbol
|
||||
BrotliWriteBits(uint(self.depths_[ix]), uint64(self.bits_[ix]), storage_ix, storage)
|
||||
writeBits(uint(self.depths_[ix]), uint64(self.bits_[ix]), storage_ix, storage)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1014,10 +1016,10 @@ func storeMetaBlock(input []byte, start_pos uint, length uint, mask uint, prev_b
|
|||
buildAndStoreBlockSwitchEntropyCodes(&command_enc, tree, storage_ix, storage)
|
||||
buildAndStoreBlockSwitchEntropyCodes(&distance_enc, tree, storage_ix, storage)
|
||||
|
||||
BrotliWriteBits(2, uint64(dist.distance_postfix_bits), storage_ix, storage)
|
||||
BrotliWriteBits(4, uint64(dist.num_direct_distance_codes)>>dist.distance_postfix_bits, storage_ix, storage)
|
||||
writeBits(2, uint64(dist.distance_postfix_bits), storage_ix, storage)
|
||||
writeBits(4, uint64(dist.num_direct_distance_codes)>>dist.distance_postfix_bits, storage_ix, storage)
|
||||
for i = 0; i < mb.literal_split.num_types; i++ {
|
||||
BrotliWriteBits(2, uint64(literal_context_mode), storage_ix, storage)
|
||||
writeBits(2, uint64(literal_context_mode), storage_ix, storage)
|
||||
}
|
||||
|
||||
if mb.literal_context_map_size == 0 {
|
||||
|
@ -1075,7 +1077,7 @@ func storeMetaBlock(input []byte, start_pos uint, length uint, mask uint, prev_b
|
|||
storeSymbolWithContext(&distance_enc, dist_code, context, mb.distance_context_map, storage_ix, storage, distanceContextBits)
|
||||
}
|
||||
|
||||
BrotliWriteBits(uint(distnumextra), distextra, storage_ix, storage)
|
||||
writeBits(uint(distnumextra), distextra, storage_ix, storage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1114,11 +1116,11 @@ func storeDataWithHuffmanCodes(input []byte, start_pos uint, mask uint, commands
|
|||
var cmd command = commands[i]
|
||||
var cmd_code uint = uint(cmd.cmd_prefix_)
|
||||
var j uint
|
||||
BrotliWriteBits(uint(cmd_depth[cmd_code]), uint64(cmd_bits[cmd_code]), storage_ix, storage)
|
||||
writeBits(uint(cmd_depth[cmd_code]), uint64(cmd_bits[cmd_code]), storage_ix, storage)
|
||||
storeCommandExtra(&cmd, storage_ix, storage)
|
||||
for j = uint(cmd.insert_len_); j != 0; j-- {
|
||||
var literal byte = input[pos&mask]
|
||||
BrotliWriteBits(uint(lit_depth[literal]), uint64(lit_bits[literal]), storage_ix, storage)
|
||||
writeBits(uint(lit_depth[literal]), uint64(lit_bits[literal]), storage_ix, storage)
|
||||
pos++
|
||||
}
|
||||
|
||||
|
@ -1127,8 +1129,8 @@ func storeDataWithHuffmanCodes(input []byte, start_pos uint, mask uint, commands
|
|||
var dist_code uint = uint(cmd.dist_prefix_) & 0x3FF
|
||||
var distnumextra uint32 = uint32(cmd.dist_prefix_) >> 10
|
||||
var distextra uint32 = cmd.dist_extra_
|
||||
BrotliWriteBits(uint(dist_depth[dist_code]), uint64(dist_bits[dist_code]), storage_ix, storage)
|
||||
BrotliWriteBits(uint(distnumextra), uint64(distextra), storage_ix, storage)
|
||||
writeBits(uint(dist_depth[dist_code]), uint64(dist_bits[dist_code]), storage_ix, storage)
|
||||
writeBits(uint(distnumextra), uint64(distextra), storage_ix, storage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1154,7 +1156,7 @@ func storeMetaBlockTrivial(input []byte, start_pos uint, length uint, mask uint,
|
|||
|
||||
buildHistograms(input, start_pos, mask, commands, n_commands, &lit_histo, &cmd_histo, &dist_histo)
|
||||
|
||||
BrotliWriteBits(13, 0, storage_ix, storage)
|
||||
writeBits(13, 0, storage_ix, storage)
|
||||
|
||||
tree = make([]huffmanTree, maxHuffmanTreeSize)
|
||||
buildAndStoreHuffmanTree(lit_histo.data_[:], numLiteralSymbols, numLiteralSymbols, tree, lit_depth[:], lit_bits[:], storage_ix, storage)
|
||||
|
@ -1173,7 +1175,7 @@ func storeMetaBlockFast(input []byte, start_pos uint, length uint, mask uint, is
|
|||
|
||||
storeCompressedMetaBlockHeader(is_last, length, storage_ix, storage)
|
||||
|
||||
BrotliWriteBits(13, 0, storage_ix, storage)
|
||||
writeBits(13, 0, storage_ix, storage)
|
||||
|
||||
if n_commands <= 128 {
|
||||
var histogram = [numLiteralSymbols]uint32{0}
|
||||
|
@ -1251,13 +1253,13 @@ func storeUncompressedMetaBlock(is_final_block bool, input []byte, position uint
|
|||
|
||||
/* We need to clear the next 4 bytes to continue to be
|
||||
compatible with BrotliWriteBits. */
|
||||
BrotliWriteBitsPrepareStorage(*storage_ix, storage)
|
||||
writeBitsPrepareStorage(*storage_ix, storage)
|
||||
|
||||
/* Since the uncompressed block itself may not be the final block, add an
|
||||
empty one after this. */
|
||||
if is_final_block {
|
||||
BrotliWriteBits(1, 1, storage_ix, storage) /* islast */
|
||||
BrotliWriteBits(1, 1, storage_ix, storage) /* isempty */
|
||||
writeBits(1, 1, storage_ix, storage) /* islast */
|
||||
writeBits(1, 1, storage_ix, storage) /* isempty */
|
||||
jumpToByteBoundary(storage_ix, storage)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brotli
|
||||
|
||||
import "math"
|
||||
|
||||
/* NOLINT(build/header_guard) */
|
||||
/* Copyright 2013 Google Inc. All Rights Reserved.
|
||||
|
||||
|
@ -211,7 +213,7 @@ func histogramRemapCommand(in []histogramCommand, in_size uint, clusters []uint3
|
|||
increasing order.
|
||||
Returns N, the number of unique values in symbols[]. */
|
||||
|
||||
var histogramReindexCommand_kInvalidIndex uint32 = BROTLI_UINT32_MAX
|
||||
var histogramReindexCommand_kInvalidIndex uint32 = math.MaxUint32
|
||||
|
||||
func histogramReindexCommand(out []histogramCommand, symbols []uint32, length uint) uint {
|
||||
var new_index []uint32 = make([]uint32, length)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brotli
|
||||
|
||||
import "math"
|
||||
|
||||
/* NOLINT(build/header_guard) */
|
||||
/* Copyright 2013 Google Inc. All Rights Reserved.
|
||||
|
||||
|
@ -211,7 +213,7 @@ func histogramRemapDistance(in []histogramDistance, in_size uint, clusters []uin
|
|||
increasing order.
|
||||
Returns N, the number of unique values in symbols[]. */
|
||||
|
||||
var histogramReindexDistance_kInvalidIndex uint32 = BROTLI_UINT32_MAX
|
||||
var histogramReindexDistance_kInvalidIndex uint32 = math.MaxUint32
|
||||
|
||||
func histogramReindexDistance(out []histogramDistance, symbols []uint32, length uint) uint {
|
||||
var new_index []uint32 = make([]uint32, length)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brotli
|
||||
|
||||
import "math"
|
||||
|
||||
/* NOLINT(build/header_guard) */
|
||||
/* Copyright 2013 Google Inc. All Rights Reserved.
|
||||
|
||||
|
@ -211,7 +213,7 @@ func histogramRemapLiteral(in []histogramLiteral, in_size uint, clusters []uint3
|
|||
increasing order.
|
||||
Returns N, the number of unique values in symbols[]. */
|
||||
|
||||
var histogramReindexLiteral_kInvalidIndex uint32 = BROTLI_UINT32_MAX
|
||||
var histogramReindexLiteral_kInvalidIndex uint32 = math.MaxUint32
|
||||
|
||||
func histogramReindexLiteral(out []histogramLiteral, symbols []uint32, length uint) uint {
|
||||
var new_index []uint32 = make([]uint32, length)
|
||||
|
|
|
@ -203,7 +203,7 @@ func initCommand(self *command, dist *distanceParams, insertlen uint, copylen ui
|
|||
/* The distance prefix and extra bits are stored in this Command as if
|
||||
npostfix and ndirect were 0, they are only recomputed later after the
|
||||
clustering if needed. */
|
||||
PrefixEncodeCopyDistance(distance_code, uint(dist.num_direct_distance_codes), uint(dist.distance_postfix_bits), &self.dist_prefix_, &self.dist_extra_)
|
||||
prefixEncodeCopyDistance(distance_code, uint(dist.num_direct_distance_codes), uint(dist.distance_postfix_bits), &self.dist_prefix_, &self.dist_extra_)
|
||||
|
||||
getLengthCode(insertlen, uint(int(copylen)+copylen_code_delta), (self.dist_prefix_&0x3FF == 0), &self.cmd_prefix_)
|
||||
}
|
||||
|
|
|
@ -191,101 +191,101 @@ func buildAndStoreCommandPrefixCode1(histogram []uint32, depth []byte, bits []ui
|
|||
func emitInsertLen1(insertlen uint, depth []byte, bits []uint16, histo []uint32, storage_ix *uint, storage []byte) {
|
||||
if insertlen < 6 {
|
||||
var code uint = insertlen + 40
|
||||
BrotliWriteBits(uint(depth[code]), uint64(bits[code]), storage_ix, storage)
|
||||
writeBits(uint(depth[code]), uint64(bits[code]), storage_ix, storage)
|
||||
histo[code]++
|
||||
} else if insertlen < 130 {
|
||||
var tail uint = insertlen - 2
|
||||
var nbits uint32 = log2FloorNonZero(tail) - 1
|
||||
var prefix uint = tail >> nbits
|
||||
var inscode uint = uint((nbits << 1) + uint32(prefix) + 42)
|
||||
BrotliWriteBits(uint(depth[inscode]), uint64(bits[inscode]), storage_ix, storage)
|
||||
BrotliWriteBits(uint(nbits), uint64(tail)-(uint64(prefix)<<nbits), storage_ix, storage)
|
||||
writeBits(uint(depth[inscode]), uint64(bits[inscode]), storage_ix, storage)
|
||||
writeBits(uint(nbits), uint64(tail)-(uint64(prefix)<<nbits), storage_ix, storage)
|
||||
histo[inscode]++
|
||||
} else if insertlen < 2114 {
|
||||
var tail uint = insertlen - 66
|
||||
var nbits uint32 = log2FloorNonZero(tail)
|
||||
var code uint = uint(nbits + 50)
|
||||
BrotliWriteBits(uint(depth[code]), uint64(bits[code]), storage_ix, storage)
|
||||
BrotliWriteBits(uint(nbits), uint64(tail)-(uint64(uint(1))<<nbits), storage_ix, storage)
|
||||
writeBits(uint(depth[code]), uint64(bits[code]), storage_ix, storage)
|
||||
writeBits(uint(nbits), uint64(tail)-(uint64(uint(1))<<nbits), storage_ix, storage)
|
||||
histo[code]++
|
||||
} else {
|
||||
BrotliWriteBits(uint(depth[61]), uint64(bits[61]), storage_ix, storage)
|
||||
BrotliWriteBits(12, uint64(insertlen)-2114, storage_ix, storage)
|
||||
writeBits(uint(depth[61]), uint64(bits[61]), storage_ix, storage)
|
||||
writeBits(12, uint64(insertlen)-2114, storage_ix, storage)
|
||||
histo[61]++
|
||||
}
|
||||
}
|
||||
|
||||
func emitLongInsertLen(insertlen uint, depth []byte, bits []uint16, histo []uint32, storage_ix *uint, storage []byte) {
|
||||
if insertlen < 22594 {
|
||||
BrotliWriteBits(uint(depth[62]), uint64(bits[62]), storage_ix, storage)
|
||||
BrotliWriteBits(14, uint64(insertlen)-6210, storage_ix, storage)
|
||||
writeBits(uint(depth[62]), uint64(bits[62]), storage_ix, storage)
|
||||
writeBits(14, uint64(insertlen)-6210, storage_ix, storage)
|
||||
histo[62]++
|
||||
} else {
|
||||
BrotliWriteBits(uint(depth[63]), uint64(bits[63]), storage_ix, storage)
|
||||
BrotliWriteBits(24, uint64(insertlen)-22594, storage_ix, storage)
|
||||
writeBits(uint(depth[63]), uint64(bits[63]), storage_ix, storage)
|
||||
writeBits(24, uint64(insertlen)-22594, storage_ix, storage)
|
||||
histo[63]++
|
||||
}
|
||||
}
|
||||
|
||||
func emitCopyLen1(copylen uint, depth []byte, bits []uint16, histo []uint32, storage_ix *uint, storage []byte) {
|
||||
if copylen < 10 {
|
||||
BrotliWriteBits(uint(depth[copylen+14]), uint64(bits[copylen+14]), storage_ix, storage)
|
||||
writeBits(uint(depth[copylen+14]), uint64(bits[copylen+14]), storage_ix, storage)
|
||||
histo[copylen+14]++
|
||||
} else if copylen < 134 {
|
||||
var tail uint = copylen - 6
|
||||
var nbits uint32 = log2FloorNonZero(tail) - 1
|
||||
var prefix uint = tail >> nbits
|
||||
var code uint = uint((nbits << 1) + uint32(prefix) + 20)
|
||||
BrotliWriteBits(uint(depth[code]), uint64(bits[code]), storage_ix, storage)
|
||||
BrotliWriteBits(uint(nbits), uint64(tail)-(uint64(prefix)<<nbits), storage_ix, storage)
|
||||
writeBits(uint(depth[code]), uint64(bits[code]), storage_ix, storage)
|
||||
writeBits(uint(nbits), uint64(tail)-(uint64(prefix)<<nbits), storage_ix, storage)
|
||||
histo[code]++
|
||||
} else if copylen < 2118 {
|
||||
var tail uint = copylen - 70
|
||||
var nbits uint32 = log2FloorNonZero(tail)
|
||||
var code uint = uint(nbits + 28)
|
||||
BrotliWriteBits(uint(depth[code]), uint64(bits[code]), storage_ix, storage)
|
||||
BrotliWriteBits(uint(nbits), uint64(tail)-(uint64(uint(1))<<nbits), storage_ix, storage)
|
||||
writeBits(uint(depth[code]), uint64(bits[code]), storage_ix, storage)
|
||||
writeBits(uint(nbits), uint64(tail)-(uint64(uint(1))<<nbits), storage_ix, storage)
|
||||
histo[code]++
|
||||
} else {
|
||||
BrotliWriteBits(uint(depth[39]), uint64(bits[39]), storage_ix, storage)
|
||||
BrotliWriteBits(24, uint64(copylen)-2118, storage_ix, storage)
|
||||
writeBits(uint(depth[39]), uint64(bits[39]), storage_ix, storage)
|
||||
writeBits(24, uint64(copylen)-2118, storage_ix, storage)
|
||||
histo[39]++
|
||||
}
|
||||
}
|
||||
|
||||
func emitCopyLenLastDistance1(copylen uint, depth []byte, bits []uint16, histo []uint32, storage_ix *uint, storage []byte) {
|
||||
if copylen < 12 {
|
||||
BrotliWriteBits(uint(depth[copylen-4]), uint64(bits[copylen-4]), storage_ix, storage)
|
||||
writeBits(uint(depth[copylen-4]), uint64(bits[copylen-4]), storage_ix, storage)
|
||||
histo[copylen-4]++
|
||||
} else if copylen < 72 {
|
||||
var tail uint = copylen - 8
|
||||
var nbits uint32 = log2FloorNonZero(tail) - 1
|
||||
var prefix uint = tail >> nbits
|
||||
var code uint = uint((nbits << 1) + uint32(prefix) + 4)
|
||||
BrotliWriteBits(uint(depth[code]), uint64(bits[code]), storage_ix, storage)
|
||||
BrotliWriteBits(uint(nbits), uint64(tail)-(uint64(prefix)<<nbits), storage_ix, storage)
|
||||
writeBits(uint(depth[code]), uint64(bits[code]), storage_ix, storage)
|
||||
writeBits(uint(nbits), uint64(tail)-(uint64(prefix)<<nbits), storage_ix, storage)
|
||||
histo[code]++
|
||||
} else if copylen < 136 {
|
||||
var tail uint = copylen - 8
|
||||
var code uint = (tail >> 5) + 30
|
||||
BrotliWriteBits(uint(depth[code]), uint64(bits[code]), storage_ix, storage)
|
||||
BrotliWriteBits(5, uint64(tail)&31, storage_ix, storage)
|
||||
BrotliWriteBits(uint(depth[64]), uint64(bits[64]), storage_ix, storage)
|
||||
writeBits(uint(depth[code]), uint64(bits[code]), storage_ix, storage)
|
||||
writeBits(5, uint64(tail)&31, storage_ix, storage)
|
||||
writeBits(uint(depth[64]), uint64(bits[64]), storage_ix, storage)
|
||||
histo[code]++
|
||||
histo[64]++
|
||||
} else if copylen < 2120 {
|
||||
var tail uint = copylen - 72
|
||||
var nbits uint32 = log2FloorNonZero(tail)
|
||||
var code uint = uint(nbits + 28)
|
||||
BrotliWriteBits(uint(depth[code]), uint64(bits[code]), storage_ix, storage)
|
||||
BrotliWriteBits(uint(nbits), uint64(tail)-(uint64(uint(1))<<nbits), storage_ix, storage)
|
||||
BrotliWriteBits(uint(depth[64]), uint64(bits[64]), storage_ix, storage)
|
||||
writeBits(uint(depth[code]), uint64(bits[code]), storage_ix, storage)
|
||||
writeBits(uint(nbits), uint64(tail)-(uint64(uint(1))<<nbits), storage_ix, storage)
|
||||
writeBits(uint(depth[64]), uint64(bits[64]), storage_ix, storage)
|
||||
histo[code]++
|
||||
histo[64]++
|
||||
} else {
|
||||
BrotliWriteBits(uint(depth[39]), uint64(bits[39]), storage_ix, storage)
|
||||
BrotliWriteBits(24, uint64(copylen)-2120, storage_ix, storage)
|
||||
BrotliWriteBits(uint(depth[64]), uint64(bits[64]), storage_ix, storage)
|
||||
writeBits(uint(depth[39]), uint64(bits[39]), storage_ix, storage)
|
||||
writeBits(24, uint64(copylen)-2120, storage_ix, storage)
|
||||
writeBits(uint(depth[64]), uint64(bits[64]), storage_ix, storage)
|
||||
histo[39]++
|
||||
histo[64]++
|
||||
}
|
||||
|
@ -297,8 +297,8 @@ func emitDistance1(distance uint, depth []byte, bits []uint16, histo []uint32, s
|
|||
var prefix uint = (d >> nbits) & 1
|
||||
var offset uint = (2 + prefix) << nbits
|
||||
var distcode uint = uint(2*(nbits-1) + uint32(prefix) + 80)
|
||||
BrotliWriteBits(uint(depth[distcode]), uint64(bits[distcode]), storage_ix, storage)
|
||||
BrotliWriteBits(uint(nbits), uint64(d)-uint64(offset), storage_ix, storage)
|
||||
writeBits(uint(depth[distcode]), uint64(bits[distcode]), storage_ix, storage)
|
||||
writeBits(uint(nbits), uint64(d)-uint64(offset), storage_ix, storage)
|
||||
histo[distcode]++
|
||||
}
|
||||
|
||||
|
@ -306,7 +306,7 @@ func emitLiterals(input []byte, len uint, depth []byte, bits []uint16, storage_i
|
|||
var j uint
|
||||
for j = 0; j < len; j++ {
|
||||
var lit byte = input[j]
|
||||
BrotliWriteBits(uint(depth[lit]), uint64(bits[lit]), storage_ix, storage)
|
||||
writeBits(uint(depth[lit]), uint64(bits[lit]), storage_ix, storage)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -315,7 +315,7 @@ func storeMetaBlockHeader1(len uint, is_uncompressed bool, storage_ix *uint, sto
|
|||
var nibbles uint = 6
|
||||
|
||||
/* ISLAST */
|
||||
BrotliWriteBits(1, 0, storage_ix, storage)
|
||||
writeBits(1, 0, storage_ix, storage)
|
||||
|
||||
if len <= 1<<16 {
|
||||
nibbles = 4
|
||||
|
@ -323,11 +323,11 @@ func storeMetaBlockHeader1(len uint, is_uncompressed bool, storage_ix *uint, sto
|
|||
nibbles = 5
|
||||
}
|
||||
|
||||
BrotliWriteBits(2, uint64(nibbles)-4, storage_ix, storage)
|
||||
BrotliWriteBits(nibbles*4, uint64(len)-1, storage_ix, storage)
|
||||
writeBits(2, uint64(nibbles)-4, storage_ix, storage)
|
||||
writeBits(nibbles*4, uint64(len)-1, storage_ix, storage)
|
||||
|
||||
/* ISUNCOMPRESSED */
|
||||
BrotliWriteSingleBit(is_uncompressed, storage_ix, storage)
|
||||
writeSingleBit(is_uncompressed, storage_ix, storage)
|
||||
}
|
||||
|
||||
func updateBits(n_bits uint, bits uint32, pos uint, array []byte) {
|
||||
|
@ -556,18 +556,18 @@ func compressFragmentFastImpl(in []byte, input_size uint, is_last bool, table []
|
|||
storeMetaBlockHeader1(block_size, false, storage_ix, storage)
|
||||
|
||||
/* No block splits, no contexts. */
|
||||
BrotliWriteBits(13, 0, storage_ix, storage)
|
||||
writeBits(13, 0, storage_ix, storage)
|
||||
|
||||
literal_ratio = buildAndStoreLiteralPrefixCode(in[input:], block_size, lit_depth[:], lit_bits[:], storage_ix, storage)
|
||||
{
|
||||
/* Store the pre-compressed command and distance prefix codes. */
|
||||
var i uint
|
||||
for i = 0; i+7 < *cmd_code_numbits; i += 8 {
|
||||
BrotliWriteBits(8, uint64(cmd_code[i>>3]), storage_ix, storage)
|
||||
writeBits(8, uint64(cmd_code[i>>3]), storage_ix, storage)
|
||||
}
|
||||
}
|
||||
|
||||
BrotliWriteBits(*cmd_code_numbits&7, uint64(cmd_code[*cmd_code_numbits>>3]), storage_ix, storage)
|
||||
writeBits(*cmd_code_numbits&7, uint64(cmd_code[*cmd_code_numbits>>3]), storage_ix, storage)
|
||||
|
||||
/* Initialize the command and distance histograms. We will gather
|
||||
statistics of command and distance codes during the processing
|
||||
|
@ -679,7 +679,7 @@ emit_commands:
|
|||
|
||||
emitLiterals(in[next_emit:], insert, lit_depth[:], lit_bits[:], storage_ix, storage)
|
||||
if distance == last_distance {
|
||||
BrotliWriteBits(uint(cmd_depth[64]), uint64(cmd_bits[64]), storage_ix, storage)
|
||||
writeBits(uint(cmd_depth[64]), uint64(cmd_bits[64]), storage_ix, storage)
|
||||
cmd_histo[64]++
|
||||
} else {
|
||||
emitDistance1(uint(distance), cmd_depth, cmd_bits, cmd_histo[:], storage_ix, storage)
|
||||
|
@ -804,7 +804,7 @@ next_block:
|
|||
storeMetaBlockHeader1(block_size, false, storage_ix, storage)
|
||||
|
||||
/* No block splits, no contexts. */
|
||||
BrotliWriteBits(13, 0, storage_ix, storage)
|
||||
writeBits(13, 0, storage_ix, storage)
|
||||
|
||||
literal_ratio = buildAndStoreLiteralPrefixCode(in[input:], block_size, lit_depth[:], lit_bits[:], storage_ix, storage)
|
||||
buildAndStoreCommandPrefixCode1(cmd_histo[:], cmd_depth, cmd_bits, storage_ix, storage)
|
||||
|
@ -827,8 +827,8 @@ func compressFragmentFast(input []byte, input_size uint, is_last bool, table []i
|
|||
|
||||
if input_size == 0 {
|
||||
assert(is_last)
|
||||
BrotliWriteBits(1, 1, storage_ix, storage) /* islast */
|
||||
BrotliWriteBits(1, 1, storage_ix, storage) /* isempty */
|
||||
writeBits(1, 1, storage_ix, storage) /* islast */
|
||||
writeBits(1, 1, storage_ix, storage) /* isempty */
|
||||
*storage_ix = (*storage_ix + 7) &^ 7
|
||||
return
|
||||
}
|
||||
|
@ -841,8 +841,8 @@ func compressFragmentFast(input []byte, input_size uint, is_last bool, table []i
|
|||
}
|
||||
|
||||
if is_last {
|
||||
BrotliWriteBits(1, 1, storage_ix, storage) /* islast */
|
||||
BrotliWriteBits(1, 1, storage_ix, storage) /* isempty */
|
||||
writeBits(1, 1, storage_ix, storage) /* islast */
|
||||
writeBits(1, 1, storage_ix, storage) /* isempty */
|
||||
*storage_ix = (*storage_ix + 7) &^ 7
|
||||
}
|
||||
}
|
||||
|
|
|
@ -212,7 +212,7 @@ func storeMetaBlockHeader(len uint, is_uncompressed bool, storage_ix *uint, stor
|
|||
var nibbles uint = 6
|
||||
|
||||
/* ISLAST */
|
||||
BrotliWriteBits(1, 0, storage_ix, storage)
|
||||
writeBits(1, 0, storage_ix, storage)
|
||||
|
||||
if len <= 1<<16 {
|
||||
nibbles = 4
|
||||
|
@ -220,11 +220,11 @@ func storeMetaBlockHeader(len uint, is_uncompressed bool, storage_ix *uint, stor
|
|||
nibbles = 5
|
||||
}
|
||||
|
||||
BrotliWriteBits(2, uint64(nibbles)-4, storage_ix, storage)
|
||||
BrotliWriteBits(nibbles*4, uint64(len)-1, storage_ix, storage)
|
||||
writeBits(2, uint64(nibbles)-4, storage_ix, storage)
|
||||
writeBits(nibbles*4, uint64(len)-1, storage_ix, storage)
|
||||
|
||||
/* ISUNCOMPRESSED */
|
||||
BrotliWriteSingleBit(is_uncompressed, storage_ix, storage)
|
||||
writeSingleBit(is_uncompressed, storage_ix, storage)
|
||||
}
|
||||
|
||||
func createCommands(input []byte, block_size uint, input_size uint, base_ip_ptr []byte, table []int, table_bits uint, min_match uint, literals *[]byte, commands *[]uint32) {
|
||||
|
@ -639,14 +639,14 @@ func storeCommands(literals []byte, num_literals uint, commands []uint32, num_co
|
|||
var code uint32 = cmd & 0xFF
|
||||
var extra uint32 = cmd >> 8
|
||||
assert(code < 128)
|
||||
BrotliWriteBits(uint(cmd_depths[code]), uint64(cmd_bits[code]), storage_ix, storage)
|
||||
BrotliWriteBits(uint(storeCommands_kNumExtraBits[code]), uint64(extra), storage_ix, storage)
|
||||
writeBits(uint(cmd_depths[code]), uint64(cmd_bits[code]), storage_ix, storage)
|
||||
writeBits(uint(storeCommands_kNumExtraBits[code]), uint64(extra), storage_ix, storage)
|
||||
if code < 24 {
|
||||
var insert uint32 = storeCommands_kInsertOffset[code] + extra
|
||||
var j uint32
|
||||
for j = 0; j < insert; j++ {
|
||||
var lit byte = literals[0]
|
||||
BrotliWriteBits(uint(lit_depths[lit]), uint64(lit_bits[lit]), storage_ix, storage)
|
||||
writeBits(uint(lit_depths[lit]), uint64(lit_bits[lit]), storage_ix, storage)
|
||||
literals = literals[1:]
|
||||
}
|
||||
}
|
||||
|
@ -706,7 +706,7 @@ func compressFragmentTwoPassImpl(input []byte, input_size uint, is_last bool, co
|
|||
storeMetaBlockHeader(block_size, false, storage_ix, storage)
|
||||
|
||||
/* No block splits, no contexts. */
|
||||
BrotliWriteBits(13, 0, storage_ix, storage)
|
||||
writeBits(13, 0, storage_ix, storage)
|
||||
|
||||
storeCommands(literal_buf, num_literals, command_buf, num_commands, storage_ix, storage)
|
||||
} else {
|
||||
|
@ -739,8 +739,8 @@ func compressFragmentTwoPass(input []byte, input_size uint, is_last bool, comman
|
|||
}
|
||||
|
||||
if is_last {
|
||||
BrotliWriteBits(1, 1, storage_ix, storage) /* islast */
|
||||
BrotliWriteBits(1, 1, storage_ix, storage) /* isempty */
|
||||
writeBits(1, 1, storage_ix, storage) /* islast */
|
||||
writeBits(1, 1, storage_ix, storage) /* isempty */
|
||||
*storage_ix = (*storage_ix + 7) &^ 7
|
||||
}
|
||||
}
|
||||
|
|
306
decode.go
306
decode.go
|
@ -115,7 +115,7 @@ var kCodeLengthPrefixLength = [16]byte{2, 2, 2, 3, 2, 2, 2, 4, 2, 2, 2, 3, 2, 2,
|
|||
var kCodeLengthPrefixValue = [16]byte{0, 4, 3, 2, 0, 4, 3, 1, 0, 4, 3, 2, 0, 4, 3, 5}
|
||||
|
||||
func decoderSetParameter(state *Reader, p int, value uint32) bool {
|
||||
if state.state != BROTLI_STATE_UNINITED {
|
||||
if state.state != stateUninited {
|
||||
return false
|
||||
}
|
||||
switch p {
|
||||
|
@ -200,7 +200,7 @@ func decodeWindowBits(s *Reader, br *bitReader) int {
|
|||
func decodeVarLenUint8(s *Reader, br *bitReader, value *uint32) int {
|
||||
var bits uint32
|
||||
switch s.substate_decode_uint8 {
|
||||
case BROTLI_STATE_DECODE_UINT8_NONE:
|
||||
case stateDecodeUint8None:
|
||||
if !safeReadBits(br, 1, &bits) {
|
||||
return decoderNeedsMoreInput
|
||||
}
|
||||
|
@ -212,15 +212,15 @@ func decodeVarLenUint8(s *Reader, br *bitReader, value *uint32) int {
|
|||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_DECODE_UINT8_SHORT:
|
||||
case stateDecodeUint8Short:
|
||||
if !safeReadBits(br, 3, &bits) {
|
||||
s.substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_SHORT
|
||||
s.substate_decode_uint8 = stateDecodeUint8Short
|
||||
return decoderNeedsMoreInput
|
||||
}
|
||||
|
||||
if bits == 0 {
|
||||
*value = 1
|
||||
s.substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_NONE
|
||||
s.substate_decode_uint8 = stateDecodeUint8None
|
||||
return decoderSuccess
|
||||
}
|
||||
|
||||
|
@ -229,14 +229,14 @@ func decodeVarLenUint8(s *Reader, br *bitReader, value *uint32) int {
|
|||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_DECODE_UINT8_LONG:
|
||||
case stateDecodeUint8Long:
|
||||
if !safeReadBits(br, *value, &bits) {
|
||||
s.substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_LONG
|
||||
s.substate_decode_uint8 = stateDecodeUint8Long
|
||||
return decoderNeedsMoreInput
|
||||
}
|
||||
|
||||
*value = (1 << *value) + bits
|
||||
s.substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_NONE
|
||||
s.substate_decode_uint8 = stateDecodeUint8None
|
||||
return decoderSuccess
|
||||
|
||||
default:
|
||||
|
@ -250,7 +250,7 @@ func decodeMetaBlockLength(s *Reader, br *bitReader) int {
|
|||
var i int
|
||||
for {
|
||||
switch s.substate_metablock_header {
|
||||
case BROTLI_STATE_METABLOCK_HEADER_NONE:
|
||||
case stateMetablockHeaderNone:
|
||||
if !safeReadBits(br, 1, &bits) {
|
||||
return decoderNeedsMoreInput
|
||||
}
|
||||
|
@ -264,29 +264,29 @@ func decodeMetaBlockLength(s *Reader, br *bitReader) int {
|
|||
s.is_uncompressed = 0
|
||||
s.is_metadata = 0
|
||||
if s.is_last_metablock == 0 {
|
||||
s.substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NIBBLES
|
||||
s.substate_metablock_header = stateMetablockHeaderNibbles
|
||||
break
|
||||
}
|
||||
|
||||
s.substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_EMPTY
|
||||
s.substate_metablock_header = stateMetablockHeaderEmpty
|
||||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_METABLOCK_HEADER_EMPTY:
|
||||
case stateMetablockHeaderEmpty:
|
||||
if !safeReadBits(br, 1, &bits) {
|
||||
return decoderNeedsMoreInput
|
||||
}
|
||||
|
||||
if bits != 0 {
|
||||
s.substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NONE
|
||||
s.substate_metablock_header = stateMetablockHeaderNone
|
||||
return decoderSuccess
|
||||
}
|
||||
|
||||
s.substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NIBBLES
|
||||
s.substate_metablock_header = stateMetablockHeaderNibbles
|
||||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_METABLOCK_HEADER_NIBBLES:
|
||||
case stateMetablockHeaderNibbles:
|
||||
if !safeReadBits(br, 2, &bits) {
|
||||
return decoderNeedsMoreInput
|
||||
}
|
||||
|
@ -295,15 +295,15 @@ func decodeMetaBlockLength(s *Reader, br *bitReader) int {
|
|||
s.loop_counter = 0
|
||||
if bits == 3 {
|
||||
s.is_metadata = 1
|
||||
s.substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_RESERVED
|
||||
s.substate_metablock_header = stateMetablockHeaderReserved
|
||||
break
|
||||
}
|
||||
|
||||
s.substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_SIZE
|
||||
s.substate_metablock_header = stateMetablockHeaderSize
|
||||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_METABLOCK_HEADER_SIZE:
|
||||
case stateMetablockHeaderSize:
|
||||
i = s.loop_counter
|
||||
|
||||
for ; i < int(s.size_nibbles); i++ {
|
||||
|
@ -319,11 +319,11 @@ func decodeMetaBlockLength(s *Reader, br *bitReader) int {
|
|||
s.meta_block_remaining_len |= int(bits << uint(i*4))
|
||||
}
|
||||
|
||||
s.substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED
|
||||
s.substate_metablock_header = stateMetablockHeaderUncompressed
|
||||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED:
|
||||
case stateMetablockHeaderUncompressed:
|
||||
if s.is_last_metablock == 0 {
|
||||
if !safeReadBits(br, 1, &bits) {
|
||||
return decoderNeedsMoreInput
|
||||
|
@ -337,10 +337,10 @@ func decodeMetaBlockLength(s *Reader, br *bitReader) int {
|
|||
}
|
||||
|
||||
s.meta_block_remaining_len++
|
||||
s.substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NONE
|
||||
s.substate_metablock_header = stateMetablockHeaderNone
|
||||
return decoderSuccess
|
||||
|
||||
case BROTLI_STATE_METABLOCK_HEADER_RESERVED:
|
||||
case stateMetablockHeaderReserved:
|
||||
if !safeReadBits(br, 1, &bits) {
|
||||
return decoderNeedsMoreInput
|
||||
}
|
||||
|
@ -349,26 +349,26 @@ func decodeMetaBlockLength(s *Reader, br *bitReader) int {
|
|||
return decoderErrorFormatReserved
|
||||
}
|
||||
|
||||
s.substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_BYTES
|
||||
s.substate_metablock_header = stateMetablockHeaderBytes
|
||||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_METABLOCK_HEADER_BYTES:
|
||||
case stateMetablockHeaderBytes:
|
||||
if !safeReadBits(br, 2, &bits) {
|
||||
return decoderNeedsMoreInput
|
||||
}
|
||||
|
||||
if bits == 0 {
|
||||
s.substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NONE
|
||||
s.substate_metablock_header = stateMetablockHeaderNone
|
||||
return decoderSuccess
|
||||
}
|
||||
|
||||
s.size_nibbles = uint(byte(bits))
|
||||
s.substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_METADATA
|
||||
s.substate_metablock_header = stateMetablockHeaderMetadata
|
||||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_METABLOCK_HEADER_METADATA:
|
||||
case stateMetablockHeaderMetadata:
|
||||
i = s.loop_counter
|
||||
|
||||
for ; i < int(s.size_nibbles); i++ {
|
||||
|
@ -385,7 +385,7 @@ func decodeMetaBlockLength(s *Reader, br *bitReader) int {
|
|||
}
|
||||
|
||||
s.meta_block_remaining_len++
|
||||
s.substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NONE
|
||||
s.substate_metablock_header = stateMetablockHeaderNone
|
||||
return decoderSuccess
|
||||
|
||||
default:
|
||||
|
@ -476,7 +476,7 @@ func preloadSymbol(safe int, table []huffmanCode, br *bitReader, bits *uint32, v
|
|||
return
|
||||
}
|
||||
|
||||
table = table[BrotliGetBits(br, huffmanTableBits):]
|
||||
table = table[getBits(br, huffmanTableBits):]
|
||||
*bits = uint32(table[0].bits)
|
||||
*value = uint32(table[0].value)
|
||||
}
|
||||
|
@ -526,7 +526,7 @@ func readSimpleHuffmanSymbols(alphabet_size uint32, max_symbol uint32, s *Reader
|
|||
var v uint32
|
||||
if !safeReadBits(br, max_bits, &v) {
|
||||
s.sub_loop_counter = i
|
||||
s.substate_huffman = BROTLI_STATE_HUFFMAN_SIMPLE_READ
|
||||
s.substate_huffman = stateHuffmanSimpleRead
|
||||
return decoderNeedsMoreInput
|
||||
}
|
||||
|
||||
|
@ -556,10 +556,10 @@ func readSimpleHuffmanSymbols(alphabet_size uint32, max_symbol uint32, s *Reader
|
|||
C) extend corresponding index-chain
|
||||
D) reduce the Huffman space
|
||||
E) update the histogram */
|
||||
func processSingleCodeLength(code_len uint32, symbol *uint32, repeat *uint32, space *uint32, prev_code_len *uint32, symbol_lists SymbolList, code_length_histo []uint16, next_symbol []int) {
|
||||
func processSingleCodeLength(code_len uint32, symbol *uint32, repeat *uint32, space *uint32, prev_code_len *uint32, symbol_lists symbolList, code_length_histo []uint16, next_symbol []int) {
|
||||
*repeat = 0
|
||||
if code_len != 0 { /* code_len == 1..15 */
|
||||
SymbolListPut(symbol_lists, next_symbol[code_len], uint16(*symbol))
|
||||
symbolListPut(symbol_lists, next_symbol[code_len], uint16(*symbol))
|
||||
next_symbol[code_len] = int(*symbol)
|
||||
*prev_code_len = code_len
|
||||
*space -= 32768 >> code_len
|
||||
|
@ -579,7 +579,7 @@ func processSingleCodeLength(code_len uint32, symbol *uint32, repeat *uint32, sp
|
|||
|
||||
PRECONDITION: code_len == BROTLI_REPEAT_PREVIOUS_CODE_LENGTH or
|
||||
code_len == BROTLI_REPEAT_ZERO_CODE_LENGTH */
|
||||
func processRepeatedCodeLength(code_len uint32, repeat_delta uint32, alphabet_size uint32, symbol *uint32, repeat *uint32, space *uint32, prev_code_len *uint32, repeat_code_len *uint32, symbol_lists SymbolList, code_length_histo []uint16, next_symbol []int) {
|
||||
func processRepeatedCodeLength(code_len uint32, repeat_delta uint32, alphabet_size uint32, symbol *uint32, repeat *uint32, space *uint32, prev_code_len *uint32, repeat_code_len *uint32, symbol_lists symbolList, code_length_histo []uint16, next_symbol []int) {
|
||||
var old_repeat uint32 /* for BROTLI_REPEAT_ZERO_CODE_LENGTH */ /* for BROTLI_REPEAT_ZERO_CODE_LENGTH */
|
||||
var extra_bits uint32 = 3
|
||||
var new_len uint32 = 0
|
||||
|
@ -611,7 +611,7 @@ func processRepeatedCodeLength(code_len uint32, repeat_delta uint32, alphabet_si
|
|||
var last uint = uint(*symbol + repeat_delta)
|
||||
var next int = next_symbol[*repeat_code_len]
|
||||
for {
|
||||
SymbolListPut(symbol_lists, next, uint16(*symbol))
|
||||
symbolListPut(symbol_lists, next, uint16(*symbol))
|
||||
next = int(*symbol)
|
||||
(*symbol)++
|
||||
if (*symbol) == uint32(last) {
|
||||
|
@ -635,7 +635,7 @@ func readSymbolCodeLengths(alphabet_size uint32, s *Reader) int {
|
|||
var space uint32 = s.space
|
||||
var prev_code_len uint32 = s.prev_code_len
|
||||
var repeat_code_len uint32 = s.repeat_code_len
|
||||
var symbol_lists SymbolList = s.symbol_lists
|
||||
var symbol_lists symbolList = s.symbol_lists
|
||||
var code_length_histo []uint16 = s.code_length_histo[:]
|
||||
var next_symbol []int = s.next_symbol[:]
|
||||
if !warmupBitReader(br) {
|
||||
|
@ -744,7 +744,7 @@ func readCodeLengthCodeLengths(s *Reader) int {
|
|||
s.sub_loop_counter = i
|
||||
s.repeat = num_codes
|
||||
s.space = space
|
||||
s.substate_huffman = BROTLI_STATE_HUFFMAN_COMPLEX
|
||||
s.substate_huffman = stateHuffmanComplex
|
||||
return decoderNeedsMoreInput
|
||||
}
|
||||
}
|
||||
|
@ -790,7 +790,7 @@ func readHuffmanCode(alphabet_size uint32, max_symbol uint32, table []huffmanCod
|
|||
/* State machine. */
|
||||
for {
|
||||
switch s.substate_huffman {
|
||||
case BROTLI_STATE_HUFFMAN_NONE:
|
||||
case stateHuffmanNone:
|
||||
if !safeReadBits(br, 2, &s.sub_loop_counter) {
|
||||
return decoderNeedsMoreInput
|
||||
}
|
||||
|
@ -810,23 +810,23 @@ func readHuffmanCode(alphabet_size uint32, max_symbol uint32, table []huffmanCod
|
|||
s.code_length_code_lengths[i] = 0
|
||||
}
|
||||
|
||||
s.substate_huffman = BROTLI_STATE_HUFFMAN_COMPLEX
|
||||
s.substate_huffman = stateHuffmanComplex
|
||||
continue
|
||||
}
|
||||
fallthrough
|
||||
|
||||
/* Read symbols, codes & code lengths directly. */
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_HUFFMAN_SIMPLE_SIZE:
|
||||
case stateHuffmanSimpleSize:
|
||||
if !safeReadBits(br, 2, &s.symbol) { /* num_symbols */
|
||||
s.substate_huffman = BROTLI_STATE_HUFFMAN_SIMPLE_SIZE
|
||||
s.substate_huffman = stateHuffmanSimpleSize
|
||||
return decoderNeedsMoreInput
|
||||
}
|
||||
|
||||
s.sub_loop_counter = 0
|
||||
fallthrough
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_HUFFMAN_SIMPLE_READ:
|
||||
case stateHuffmanSimpleRead:
|
||||
{
|
||||
var result int = readSimpleHuffmanSymbols(alphabet_size, max_symbol, s)
|
||||
if result != decoderSuccess {
|
||||
|
@ -836,13 +836,13 @@ func readHuffmanCode(alphabet_size uint32, max_symbol uint32, table []huffmanCod
|
|||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_HUFFMAN_SIMPLE_BUILD:
|
||||
case stateHuffmanSimpleBuild:
|
||||
{
|
||||
var table_size uint32
|
||||
if s.symbol == 3 {
|
||||
var bits uint32
|
||||
if !safeReadBits(br, 1, &bits) {
|
||||
s.substate_huffman = BROTLI_STATE_HUFFMAN_SIMPLE_BUILD
|
||||
s.substate_huffman = stateHuffmanSimpleBuild
|
||||
return decoderNeedsMoreInput
|
||||
}
|
||||
|
||||
|
@ -854,13 +854,13 @@ func readHuffmanCode(alphabet_size uint32, max_symbol uint32, table []huffmanCod
|
|||
*opt_table_size = table_size
|
||||
}
|
||||
|
||||
s.substate_huffman = BROTLI_STATE_HUFFMAN_NONE
|
||||
s.substate_huffman = stateHuffmanNone
|
||||
return decoderSuccess
|
||||
}
|
||||
fallthrough
|
||||
|
||||
/* Decode Huffman-coded code lengths. */
|
||||
case BROTLI_STATE_HUFFMAN_COMPLEX:
|
||||
case stateHuffmanComplex:
|
||||
{
|
||||
var i uint32
|
||||
var result int = readCodeLengthCodeLengths(s)
|
||||
|
@ -875,7 +875,7 @@ func readHuffmanCode(alphabet_size uint32, max_symbol uint32, table []huffmanCod
|
|||
|
||||
for i = 0; i <= huffmanMaxCodeLength; i++ {
|
||||
s.next_symbol[i] = int(i) - (huffmanMaxCodeLength + 1)
|
||||
SymbolListPut(s.symbol_lists, s.next_symbol[i], 0xFFFF)
|
||||
symbolListPut(s.symbol_lists, s.next_symbol[i], 0xFFFF)
|
||||
}
|
||||
|
||||
s.symbol = 0
|
||||
|
@ -883,12 +883,12 @@ func readHuffmanCode(alphabet_size uint32, max_symbol uint32, table []huffmanCod
|
|||
s.repeat = 0
|
||||
s.repeat_code_len = 0
|
||||
s.space = 32768
|
||||
s.substate_huffman = BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS
|
||||
s.substate_huffman = stateHuffmanLengthSymbols
|
||||
}
|
||||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS:
|
||||
case stateHuffmanLengthSymbols:
|
||||
{
|
||||
var table_size uint32
|
||||
var result int = readSymbolCodeLengths(max_symbol, s)
|
||||
|
@ -909,7 +909,7 @@ func readHuffmanCode(alphabet_size uint32, max_symbol uint32, table []huffmanCod
|
|||
*opt_table_size = table_size
|
||||
}
|
||||
|
||||
s.substate_huffman = BROTLI_STATE_HUFFMAN_NONE
|
||||
s.substate_huffman = stateHuffmanNone
|
||||
return decoderSuccess
|
||||
}
|
||||
fallthrough
|
||||
|
@ -933,7 +933,7 @@ func readBlockLength(table []huffmanCode, br *bitReader) uint32 {
|
|||
reading can't be continued with ReadBlockLength. */
|
||||
func safeReadBlockLength(s *Reader, result *uint32, table []huffmanCode, br *bitReader) bool {
|
||||
var index uint32
|
||||
if s.substate_read_block_length == BROTLI_STATE_READ_BLOCK_LENGTH_NONE {
|
||||
if s.substate_read_block_length == stateReadBlockLengthNone {
|
||||
if !safeReadSymbol(table, br, &index) {
|
||||
return false
|
||||
}
|
||||
|
@ -945,12 +945,12 @@ func safeReadBlockLength(s *Reader, result *uint32, table []huffmanCode, br *bit
|
|||
var nbits uint32 = kBlockLengthPrefixCode[index].nbits
|
||||
if !safeReadBits(br, nbits, &bits) {
|
||||
s.block_length_index = index
|
||||
s.substate_read_block_length = BROTLI_STATE_READ_BLOCK_LENGTH_SUFFIX
|
||||
s.substate_read_block_length = stateReadBlockLengthSuffix
|
||||
return false
|
||||
}
|
||||
|
||||
*result = kBlockLengthPrefixCode[index].offset + bits
|
||||
s.substate_read_block_length = BROTLI_STATE_READ_BLOCK_LENGTH_NONE
|
||||
s.substate_read_block_length = stateReadBlockLengthNone
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -994,10 +994,10 @@ func inverseMoveToFrontTransform(v []byte, v_len uint32, state *Reader) {
|
|||
|
||||
/* Decodes a series of Huffman table using ReadHuffmanCode function. */
|
||||
func huffmanTreeGroupDecode(group *huffmanTreeGroup, s *Reader) int {
|
||||
if s.substate_tree_group != BROTLI_STATE_TREE_GROUP_LOOP {
|
||||
if s.substate_tree_group != stateTreeGroupLoop {
|
||||
s.next = group.codes
|
||||
s.htree_index = 0
|
||||
s.substate_tree_group = BROTLI_STATE_TREE_GROUP_LOOP
|
||||
s.substate_tree_group = stateTreeGroupLoop
|
||||
}
|
||||
|
||||
for s.htree_index < int(group.num_htrees) {
|
||||
|
@ -1011,7 +1011,7 @@ func huffmanTreeGroupDecode(group *huffmanTreeGroup, s *Reader) int {
|
|||
s.htree_index++
|
||||
}
|
||||
|
||||
s.substate_tree_group = BROTLI_STATE_TREE_GROUP_NONE
|
||||
s.substate_tree_group = stateTreeGroupNone
|
||||
return decoderSuccess
|
||||
}
|
||||
|
||||
|
@ -1028,7 +1028,7 @@ func decodeContextMap(context_map_size uint32, num_htrees *uint32, context_map_a
|
|||
var result int = decoderSuccess
|
||||
|
||||
switch int(s.substate_context_map) {
|
||||
case BROTLI_STATE_CONTEXT_MAP_NONE:
|
||||
case stateContextMapNone:
|
||||
result = decodeVarLenUint8(s, br, num_htrees)
|
||||
if result != decoderSuccess {
|
||||
return result
|
||||
|
@ -1048,10 +1048,10 @@ func decodeContextMap(context_map_size uint32, num_htrees *uint32, context_map_a
|
|||
return decoderSuccess
|
||||
}
|
||||
|
||||
s.substate_context_map = BROTLI_STATE_CONTEXT_MAP_READ_PREFIX
|
||||
s.substate_context_map = stateContextMapReadPrefix
|
||||
fallthrough
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_CONTEXT_MAP_READ_PREFIX:
|
||||
case stateContextMapReadPrefix:
|
||||
{
|
||||
var bits uint32
|
||||
|
||||
|
@ -1069,12 +1069,12 @@ func decodeContextMap(context_map_size uint32, num_htrees *uint32, context_map_a
|
|||
dropBits(br, 1)
|
||||
}
|
||||
|
||||
s.substate_context_map = BROTLI_STATE_CONTEXT_MAP_HUFFMAN
|
||||
s.substate_context_map = stateContextMapHuffman
|
||||
}
|
||||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_CONTEXT_MAP_HUFFMAN:
|
||||
case stateContextMapHuffman:
|
||||
{
|
||||
var alphabet_size uint32 = *num_htrees + s.max_run_length_prefix
|
||||
result = readHuffmanCode(alphabet_size, alphabet_size, s.context_map_table[:], nil, s)
|
||||
|
@ -1082,12 +1082,12 @@ func decodeContextMap(context_map_size uint32, num_htrees *uint32, context_map_a
|
|||
return result
|
||||
}
|
||||
s.code = 0xFFFF
|
||||
s.substate_context_map = BROTLI_STATE_CONTEXT_MAP_DECODE
|
||||
s.substate_context_map = stateContextMapDecode
|
||||
}
|
||||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_CONTEXT_MAP_DECODE:
|
||||
case stateContextMapDecode:
|
||||
{
|
||||
var context_index uint32 = s.context_index
|
||||
var max_run_length_prefix uint32 = s.max_run_length_prefix
|
||||
|
@ -1145,11 +1145,11 @@ func decodeContextMap(context_map_size uint32, num_htrees *uint32, context_map_a
|
|||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_CONTEXT_MAP_TRANSFORM:
|
||||
case stateContextMapTransform:
|
||||
{
|
||||
var bits uint32
|
||||
if !safeReadBits(br, 1, &bits) {
|
||||
s.substate_context_map = BROTLI_STATE_CONTEXT_MAP_TRANSFORM
|
||||
s.substate_context_map = stateContextMapTransform
|
||||
return decoderNeedsMoreInput
|
||||
}
|
||||
|
||||
|
@ -1157,7 +1157,7 @@ func decodeContextMap(context_map_size uint32, num_htrees *uint32, context_map_a
|
|||
inverseMoveToFrontTransform(*context_map_arg, context_map_size, s)
|
||||
}
|
||||
|
||||
s.substate_context_map = BROTLI_STATE_CONTEXT_MAP_NONE
|
||||
s.substate_context_map = stateContextMapNone
|
||||
return decoderSuccess
|
||||
}
|
||||
fallthrough
|
||||
|
@ -1193,7 +1193,7 @@ func decodeBlockTypeAndLength(safe int, s *Reader, tree_type int) bool {
|
|||
return false
|
||||
}
|
||||
if !safeReadBlockLength(s, &s.block_length[tree_type], len_tree, br) {
|
||||
s.substate_read_block_length = BROTLI_STATE_READ_BLOCK_LENGTH_NONE
|
||||
s.substate_read_block_length = stateReadBlockLengthNone
|
||||
bitReaderRestoreState(br, &memento)
|
||||
return false
|
||||
}
|
||||
|
@ -1428,7 +1428,7 @@ func copyUncompressedBlockToOutput(available_out *uint, next_out *[]byte, total_
|
|||
/* State machine */
|
||||
for {
|
||||
switch s.substate_uncompressed {
|
||||
case BROTLI_STATE_UNCOMPRESSED_NONE:
|
||||
case stateUncompressedNone:
|
||||
{
|
||||
var nbytes int = int(getRemainingBytes(&s.br))
|
||||
if nbytes > s.meta_block_remaining_len {
|
||||
|
@ -1452,12 +1452,12 @@ func copyUncompressedBlockToOutput(available_out *uint, next_out *[]byte, total_
|
|||
return decoderNeedsMoreInput
|
||||
}
|
||||
|
||||
s.substate_uncompressed = BROTLI_STATE_UNCOMPRESSED_WRITE
|
||||
s.substate_uncompressed = stateUncompressedWrite
|
||||
}
|
||||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_UNCOMPRESSED_WRITE:
|
||||
case stateUncompressedWrite:
|
||||
{
|
||||
var result int
|
||||
result = writeRingBuffer(s, available_out, next_out, total_out, false)
|
||||
|
@ -1469,7 +1469,7 @@ func copyUncompressedBlockToOutput(available_out *uint, next_out *[]byte, total_
|
|||
s.max_distance = s.max_backward_distance
|
||||
}
|
||||
|
||||
s.substate_uncompressed = BROTLI_STATE_UNCOMPRESSED_NONE
|
||||
s.substate_uncompressed = stateUncompressedNone
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -1668,7 +1668,7 @@ func readCommandInternal(safe int, s *Reader, br *bitReader, insert_length *int)
|
|||
var cmd_code uint32
|
||||
var insert_len_extra uint32 = 0
|
||||
var copy_length uint32
|
||||
var v CmdLutElement
|
||||
var v cmdLutElement
|
||||
var memento bitReaderState
|
||||
if safe == 0 {
|
||||
cmd_code = readSymbol(s.htree_command, br)
|
||||
|
@ -1736,13 +1736,13 @@ func processCommandsInternal(safe int, s *Reader) int {
|
|||
}
|
||||
|
||||
/* Jump into state machine. */
|
||||
if s.state == BROTLI_STATE_COMMAND_BEGIN {
|
||||
if s.state == stateCommandBegin {
|
||||
goto CommandBegin
|
||||
} else if s.state == BROTLI_STATE_COMMAND_INNER {
|
||||
} else if s.state == stateCommandInner {
|
||||
goto CommandInner
|
||||
} else if s.state == BROTLI_STATE_COMMAND_POST_DECODE_LITERALS {
|
||||
} else if s.state == stateCommandPostDecodeLiterals {
|
||||
goto CommandPostDecodeLiterals
|
||||
} else if s.state == BROTLI_STATE_COMMAND_POST_WRAP_COPY {
|
||||
} else if s.state == stateCommandPostWrapCopy {
|
||||
goto CommandPostWrapCopy
|
||||
} else {
|
||||
return decoderErrorUnreachable
|
||||
|
@ -1750,11 +1750,11 @@ func processCommandsInternal(safe int, s *Reader) int {
|
|||
|
||||
CommandBegin:
|
||||
if safe != 0 {
|
||||
s.state = BROTLI_STATE_COMMAND_BEGIN
|
||||
s.state = stateCommandBegin
|
||||
}
|
||||
|
||||
if !checkInputAmountMaybeSafe(safe, br, 28) { /* 156 bits + 7 bytes */
|
||||
s.state = BROTLI_STATE_COMMAND_BEGIN
|
||||
s.state = stateCommandBegin
|
||||
result = decoderNeedsMoreInput
|
||||
goto saveStateAndReturn
|
||||
}
|
||||
|
@ -1790,7 +1790,7 @@ CommandBegin:
|
|||
|
||||
CommandInner:
|
||||
if safe != 0 {
|
||||
s.state = BROTLI_STATE_COMMAND_INNER
|
||||
s.state = stateCommandInner
|
||||
}
|
||||
|
||||
/* Read the literals in the command. */
|
||||
|
@ -1800,7 +1800,7 @@ CommandInner:
|
|||
preloadSymbol(safe, s.literal_htree, br, &bits, &value)
|
||||
for {
|
||||
if !checkInputAmountMaybeSafe(safe, br, 28) { /* 162 bits + 7 bytes */
|
||||
s.state = BROTLI_STATE_COMMAND_INNER
|
||||
s.state = stateCommandInner
|
||||
result = decoderNeedsMoreInput
|
||||
goto saveStateAndReturn
|
||||
}
|
||||
|
@ -1836,7 +1836,7 @@ CommandInner:
|
|||
s.block_length[0]--
|
||||
pos++
|
||||
if pos == s.ringbuffer_size {
|
||||
s.state = BROTLI_STATE_COMMAND_INNER_WRITE
|
||||
s.state = stateCommandInnerWrite
|
||||
i--
|
||||
goto saveStateAndReturn
|
||||
}
|
||||
|
@ -1851,7 +1851,7 @@ CommandInner:
|
|||
for {
|
||||
var context byte
|
||||
if !checkInputAmountMaybeSafe(safe, br, 28) { /* 162 bits + 7 bytes */
|
||||
s.state = BROTLI_STATE_COMMAND_INNER
|
||||
s.state = stateCommandInner
|
||||
result = decoderNeedsMoreInput
|
||||
goto saveStateAndReturn
|
||||
}
|
||||
|
@ -1890,7 +1890,7 @@ CommandInner:
|
|||
s.block_length[0]--
|
||||
pos++
|
||||
if pos == s.ringbuffer_size {
|
||||
s.state = BROTLI_STATE_COMMAND_INNER_WRITE
|
||||
s.state = stateCommandInnerWrite
|
||||
i--
|
||||
goto saveStateAndReturn
|
||||
}
|
||||
|
@ -1902,13 +1902,13 @@ CommandInner:
|
|||
}
|
||||
|
||||
if s.meta_block_remaining_len <= 0 {
|
||||
s.state = BROTLI_STATE_METABLOCK_DONE
|
||||
s.state = stateMetablockDone
|
||||
goto saveStateAndReturn
|
||||
}
|
||||
|
||||
CommandPostDecodeLiterals:
|
||||
if safe != 0 {
|
||||
s.state = BROTLI_STATE_COMMAND_POST_DECODE_LITERALS
|
||||
s.state = stateCommandPostDecodeLiterals
|
||||
}
|
||||
|
||||
if s.distance_code >= 0 {
|
||||
|
@ -1967,7 +1967,7 @@ CommandPostDecodeLiterals:
|
|||
if i >= minDictionaryWordLength && i <= maxDictionaryWordLength {
|
||||
var address int = s.distance_code - s.max_distance - 1
|
||||
var words *dictionary = s.dictionary
|
||||
var transforms *BrotliTransforms = s.transforms
|
||||
var trans *transforms = s.transforms
|
||||
var offset int = int(s.dictionary.offsets_by_length[i])
|
||||
var shift uint32 = uint32(s.dictionary.size_bits_by_length[i])
|
||||
var mask int = int(bitMask(shift))
|
||||
|
@ -1982,20 +1982,20 @@ CommandPostDecodeLiterals:
|
|||
return decoderErrorDictionaryNotSet
|
||||
}
|
||||
|
||||
if transform_idx < int(transforms.num_transforms) {
|
||||
if transform_idx < int(trans.num_transforms) {
|
||||
var word []byte
|
||||
word = words.data[offset:]
|
||||
var len int = i
|
||||
if transform_idx == int(transforms.cutOffTransforms[0]) {
|
||||
if transform_idx == int(trans.cutOffTransforms[0]) {
|
||||
copy(s.ringbuffer[pos:], word[:uint(len)])
|
||||
} else {
|
||||
len = BrotliTransformDictionaryWord(s.ringbuffer[pos:], word, int(len), transforms, transform_idx)
|
||||
len = transformDictionaryWord(s.ringbuffer[pos:], word, int(len), trans, transform_idx)
|
||||
}
|
||||
|
||||
pos += int(len)
|
||||
s.meta_block_remaining_len -= int(len)
|
||||
if pos >= s.ringbuffer_size {
|
||||
s.state = BROTLI_STATE_COMMAND_POST_WRITE_1
|
||||
s.state = stateCommandPostWrite1
|
||||
goto saveStateAndReturn
|
||||
}
|
||||
} else {
|
||||
|
@ -2048,7 +2048,7 @@ CommandPostDecodeLiterals:
|
|||
|
||||
if s.meta_block_remaining_len <= 0 {
|
||||
/* Next metablock, if any. */
|
||||
s.state = BROTLI_STATE_METABLOCK_DONE
|
||||
s.state = stateMetablockDone
|
||||
|
||||
goto saveStateAndReturn
|
||||
} else {
|
||||
|
@ -2066,7 +2066,7 @@ CommandPostWrapCopy:
|
|||
pos++
|
||||
wrap_guard--
|
||||
if wrap_guard == 0 {
|
||||
s.state = BROTLI_STATE_COMMAND_POST_WRITE_2
|
||||
s.state = stateCommandPostWrite2
|
||||
goto saveStateAndReturn
|
||||
}
|
||||
}
|
||||
|
@ -2074,7 +2074,7 @@ CommandPostWrapCopy:
|
|||
|
||||
if s.meta_block_remaining_len <= 0 {
|
||||
/* Next metablock, if any. */
|
||||
s.state = BROTLI_STATE_METABLOCK_DONE
|
||||
s.state = stateMetablockDone
|
||||
|
||||
goto saveStateAndReturn
|
||||
} else {
|
||||
|
@ -2238,7 +2238,7 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
|
|||
|
||||
switch s.state {
|
||||
/* Prepare to the first read. */
|
||||
case BROTLI_STATE_UNINITED:
|
||||
case stateUninited:
|
||||
if !warmupBitReader(br) {
|
||||
result = decoderNeedsMoreInput
|
||||
break
|
||||
|
@ -2251,13 +2251,13 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
|
|||
}
|
||||
|
||||
if s.large_window {
|
||||
s.state = BROTLI_STATE_LARGE_WINDOW_BITS
|
||||
s.state = stateLargeWindowBits
|
||||
break
|
||||
}
|
||||
|
||||
s.state = BROTLI_STATE_INITIALIZE
|
||||
s.state = stateInitialize
|
||||
|
||||
case BROTLI_STATE_LARGE_WINDOW_BITS:
|
||||
case stateLargeWindowBits:
|
||||
if !safeReadBits(br, 6, &s.window_bits) {
|
||||
result = decoderNeedsMoreInput
|
||||
break
|
||||
|
@ -2268,12 +2268,12 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
|
|||
break
|
||||
}
|
||||
|
||||
s.state = BROTLI_STATE_INITIALIZE
|
||||
s.state = stateInitialize
|
||||
fallthrough
|
||||
|
||||
/* Maximum distance, see section 9.1. of the spec. */
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_INITIALIZE:
|
||||
case stateInitialize:
|
||||
s.max_backward_distance = (1 << s.window_bits) - windowGap
|
||||
|
||||
/* Allocate memory for both block_type_trees and block_len_trees. */
|
||||
|
@ -2286,18 +2286,18 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
|
|||
|
||||
s.block_len_trees = s.block_type_trees[3*huffmanMaxSize258:]
|
||||
|
||||
s.state = BROTLI_STATE_METABLOCK_BEGIN
|
||||
s.state = stateMetablockBegin
|
||||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_METABLOCK_BEGIN:
|
||||
BrotliDecoderStateMetablockBegin(s)
|
||||
case stateMetablockBegin:
|
||||
decoderStateMetablockBegin(s)
|
||||
|
||||
s.state = BROTLI_STATE_METABLOCK_HEADER
|
||||
s.state = stateMetablockHeader
|
||||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_METABLOCK_HEADER:
|
||||
case stateMetablockHeader:
|
||||
result = decodeMetaBlockLength(s, br)
|
||||
/* Reads 2 - 31 bits. */
|
||||
if result != decoderSuccess {
|
||||
|
@ -2312,36 +2312,36 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
|
|||
}
|
||||
|
||||
if s.is_metadata != 0 {
|
||||
s.state = BROTLI_STATE_METADATA
|
||||
s.state = stateMetadata
|
||||
break
|
||||
}
|
||||
|
||||
if s.meta_block_remaining_len == 0 {
|
||||
s.state = BROTLI_STATE_METABLOCK_DONE
|
||||
s.state = stateMetablockDone
|
||||
break
|
||||
}
|
||||
|
||||
calculateRingBufferSize(s)
|
||||
if s.is_uncompressed != 0 {
|
||||
s.state = BROTLI_STATE_UNCOMPRESSED
|
||||
s.state = stateUncompressed
|
||||
break
|
||||
}
|
||||
|
||||
s.loop_counter = 0
|
||||
s.state = BROTLI_STATE_HUFFMAN_CODE_0
|
||||
case BROTLI_STATE_UNCOMPRESSED:
|
||||
s.state = stateHuffmanCode0
|
||||
case stateUncompressed:
|
||||
{
|
||||
result = copyUncompressedBlockToOutput(available_out, next_out, nil, s)
|
||||
if result != decoderSuccess {
|
||||
break
|
||||
}
|
||||
|
||||
s.state = BROTLI_STATE_METABLOCK_DONE
|
||||
s.state = stateMetablockDone
|
||||
break
|
||||
}
|
||||
fallthrough
|
||||
|
||||
case BROTLI_STATE_METADATA:
|
||||
case stateMetadata:
|
||||
for ; s.meta_block_remaining_len > 0; s.meta_block_remaining_len-- {
|
||||
var bits uint32
|
||||
|
||||
|
@ -2353,12 +2353,12 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
|
|||
}
|
||||
|
||||
if result == decoderSuccess {
|
||||
s.state = BROTLI_STATE_METABLOCK_DONE
|
||||
s.state = stateMetablockDone
|
||||
}
|
||||
|
||||
case BROTLI_STATE_HUFFMAN_CODE_0:
|
||||
case stateHuffmanCode0:
|
||||
if s.loop_counter >= 3 {
|
||||
s.state = BROTLI_STATE_METABLOCK_HEADER_2
|
||||
s.state = stateMetablockHeader2
|
||||
break
|
||||
}
|
||||
|
||||
|
@ -2375,10 +2375,10 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
|
|||
break
|
||||
}
|
||||
|
||||
s.state = BROTLI_STATE_HUFFMAN_CODE_1
|
||||
s.state = stateHuffmanCode1
|
||||
fallthrough
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_HUFFMAN_CODE_1:
|
||||
case stateHuffmanCode1:
|
||||
{
|
||||
var alphabet_size uint32 = s.num_block_types[s.loop_counter] + 2
|
||||
var tree_offset int = s.loop_counter * huffmanMaxSize258
|
||||
|
@ -2386,12 +2386,12 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
|
|||
if result != decoderSuccess {
|
||||
break
|
||||
}
|
||||
s.state = BROTLI_STATE_HUFFMAN_CODE_2
|
||||
s.state = stateHuffmanCode2
|
||||
}
|
||||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_HUFFMAN_CODE_2:
|
||||
case stateHuffmanCode2:
|
||||
{
|
||||
var alphabet_size uint32 = numBlockLenSymbols
|
||||
var tree_offset int = s.loop_counter * huffmanMaxSize26
|
||||
|
@ -2399,12 +2399,12 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
|
|||
if result != decoderSuccess {
|
||||
break
|
||||
}
|
||||
s.state = BROTLI_STATE_HUFFMAN_CODE_3
|
||||
s.state = stateHuffmanCode3
|
||||
}
|
||||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_HUFFMAN_CODE_3:
|
||||
case stateHuffmanCode3:
|
||||
{
|
||||
var tree_offset int = s.loop_counter * huffmanMaxSize26
|
||||
if !safeReadBlockLength(s, &s.block_length[s.loop_counter], s.block_len_trees[tree_offset:], br) {
|
||||
|
@ -2413,11 +2413,11 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
|
|||
}
|
||||
|
||||
s.loop_counter++
|
||||
s.state = BROTLI_STATE_HUFFMAN_CODE_0
|
||||
s.state = stateHuffmanCode0
|
||||
break
|
||||
}
|
||||
fallthrough
|
||||
case BROTLI_STATE_METABLOCK_HEADER_2:
|
||||
case stateMetablockHeader2:
|
||||
{
|
||||
var bits uint32
|
||||
if !safeReadBits(br, 6, &bits) {
|
||||
|
@ -2436,23 +2436,23 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
|
|||
}
|
||||
|
||||
s.loop_counter = 0
|
||||
s.state = BROTLI_STATE_CONTEXT_MODES
|
||||
s.state = stateContextModes
|
||||
}
|
||||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_CONTEXT_MODES:
|
||||
case stateContextModes:
|
||||
result = readContextModes(s)
|
||||
|
||||
if result != decoderSuccess {
|
||||
break
|
||||
}
|
||||
|
||||
s.state = BROTLI_STATE_CONTEXT_MAP_1
|
||||
s.state = stateContextMap1
|
||||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_CONTEXT_MAP_1:
|
||||
case stateContextMap1:
|
||||
result = decodeContextMap(s.num_block_types[0]<<literalContextBits, &s.num_literal_htrees, &s.context_map, s)
|
||||
|
||||
if result != decoderSuccess {
|
||||
|
@ -2460,10 +2460,10 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
|
|||
}
|
||||
|
||||
detectTrivialLiteralBlockTypes(s)
|
||||
s.state = BROTLI_STATE_CONTEXT_MAP_2
|
||||
s.state = stateContextMap2
|
||||
fallthrough
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_CONTEXT_MAP_2:
|
||||
case stateContextMap2:
|
||||
{
|
||||
var num_direct_codes uint32 = s.num_direct_distance_codes - numDistanceShortCodes
|
||||
var num_distance_codes uint32
|
||||
|
@ -2481,15 +2481,15 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
|
|||
break
|
||||
}
|
||||
|
||||
if !BrotliDecoderHuffmanTreeGroupInit(s, &s.literal_hgroup, numLiteralSymbols, numLiteralSymbols, s.num_literal_htrees) {
|
||||
if !decoderHuffmanTreeGroupInit(s, &s.literal_hgroup, numLiteralSymbols, numLiteralSymbols, s.num_literal_htrees) {
|
||||
allocation_success = false
|
||||
}
|
||||
|
||||
if !BrotliDecoderHuffmanTreeGroupInit(s, &s.insert_copy_hgroup, numCommandSymbols, numCommandSymbols, s.num_block_types[1]) {
|
||||
if !decoderHuffmanTreeGroupInit(s, &s.insert_copy_hgroup, numCommandSymbols, numCommandSymbols, s.num_block_types[1]) {
|
||||
allocation_success = false
|
||||
}
|
||||
|
||||
if !BrotliDecoderHuffmanTreeGroupInit(s, &s.distance_hgroup, num_distance_codes, max_distance_symbol, s.num_dist_htrees) {
|
||||
if !decoderHuffmanTreeGroupInit(s, &s.distance_hgroup, num_distance_codes, max_distance_symbol, s.num_dist_htrees) {
|
||||
allocation_success = false
|
||||
}
|
||||
|
||||
|
@ -2498,12 +2498,12 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
|
|||
}
|
||||
|
||||
s.loop_counter = 0
|
||||
s.state = BROTLI_STATE_TREE_GROUP
|
||||
s.state = stateTreeGroup
|
||||
}
|
||||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_TREE_GROUP:
|
||||
case stateTreeGroup:
|
||||
{
|
||||
var hgroup *huffmanTreeGroup = nil
|
||||
switch s.loop_counter {
|
||||
|
@ -2531,34 +2531,34 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
|
|||
break
|
||||
}
|
||||
|
||||
s.state = BROTLI_STATE_COMMAND_BEGIN
|
||||
s.state = stateCommandBegin
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
fallthrough
|
||||
|
||||
case BROTLI_STATE_COMMAND_BEGIN,
|
||||
case stateCommandBegin,
|
||||
/* Fall through. */
|
||||
BROTLI_STATE_COMMAND_INNER,
|
||||
stateCommandInner,
|
||||
|
||||
/* Fall through. */
|
||||
BROTLI_STATE_COMMAND_POST_DECODE_LITERALS,
|
||||
stateCommandPostDecodeLiterals,
|
||||
|
||||
/* Fall through. */
|
||||
BROTLI_STATE_COMMAND_POST_WRAP_COPY:
|
||||
stateCommandPostWrapCopy:
|
||||
result = processCommands(s)
|
||||
|
||||
if result == decoderNeedsMoreInput {
|
||||
result = safeProcessCommands(s)
|
||||
}
|
||||
|
||||
case BROTLI_STATE_COMMAND_INNER_WRITE,
|
||||
case stateCommandInnerWrite,
|
||||
/* Fall through. */
|
||||
BROTLI_STATE_COMMAND_POST_WRITE_1,
|
||||
stateCommandPostWrite1,
|
||||
|
||||
/* Fall through. */
|
||||
BROTLI_STATE_COMMAND_POST_WRITE_2:
|
||||
stateCommandPostWrite2:
|
||||
result = writeRingBuffer(s, available_out, next_out, nil, false)
|
||||
|
||||
if result != decoderSuccess {
|
||||
|
@ -2570,40 +2570,40 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
|
|||
s.max_distance = s.max_backward_distance
|
||||
}
|
||||
|
||||
if s.state == BROTLI_STATE_COMMAND_POST_WRITE_1 {
|
||||
if s.state == stateCommandPostWrite1 {
|
||||
if s.meta_block_remaining_len == 0 {
|
||||
/* Next metablock, if any. */
|
||||
s.state = BROTLI_STATE_METABLOCK_DONE
|
||||
s.state = stateMetablockDone
|
||||
} else {
|
||||
s.state = BROTLI_STATE_COMMAND_BEGIN
|
||||
s.state = stateCommandBegin
|
||||
}
|
||||
|
||||
break
|
||||
} else if s.state == BROTLI_STATE_COMMAND_POST_WRITE_2 {
|
||||
s.state = BROTLI_STATE_COMMAND_POST_WRAP_COPY /* BROTLI_STATE_COMMAND_INNER_WRITE */
|
||||
} else if s.state == stateCommandPostWrite2 {
|
||||
s.state = stateCommandPostWrapCopy /* BROTLI_STATE_COMMAND_INNER_WRITE */
|
||||
} else {
|
||||
if s.loop_counter == 0 {
|
||||
if s.meta_block_remaining_len == 0 {
|
||||
s.state = BROTLI_STATE_METABLOCK_DONE
|
||||
s.state = stateMetablockDone
|
||||
} else {
|
||||
s.state = BROTLI_STATE_COMMAND_POST_DECODE_LITERALS
|
||||
s.state = stateCommandPostDecodeLiterals
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
s.state = BROTLI_STATE_COMMAND_INNER
|
||||
s.state = stateCommandInner
|
||||
}
|
||||
|
||||
case BROTLI_STATE_METABLOCK_DONE:
|
||||
case stateMetablockDone:
|
||||
if s.meta_block_remaining_len < 0 {
|
||||
result = decoderErrorFormatBlockLength2
|
||||
break
|
||||
}
|
||||
|
||||
BrotliDecoderStateCleanupAfterMetablock(s)
|
||||
decoderStateCleanupAfterMetablock(s)
|
||||
if s.is_last_metablock == 0 {
|
||||
s.state = BROTLI_STATE_METABLOCK_BEGIN
|
||||
s.state = stateMetablockBegin
|
||||
break
|
||||
}
|
||||
|
||||
|
@ -2618,11 +2618,11 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
|
|||
*next_in = br.input[br.byte_pos:]
|
||||
}
|
||||
|
||||
s.state = BROTLI_STATE_DONE
|
||||
s.state = stateDone
|
||||
fallthrough
|
||||
|
||||
/* Fall through. */
|
||||
case BROTLI_STATE_DONE:
|
||||
case stateDone:
|
||||
if s.ringbuffer != nil {
|
||||
result = writeRingBuffer(s, available_out, next_out, nil, true)
|
||||
if result != decoderSuccess {
|
||||
|
|
85
encode.go
85
encode.go
|
@ -1,6 +1,9 @@
|
|||
package brotli
|
||||
|
||||
import "io"
|
||||
import (
|
||||
"io"
|
||||
"math"
|
||||
)
|
||||
|
||||
/* Copyright 2016 Google Inc. All Rights Reserved.
|
||||
|
||||
|
@ -87,7 +90,7 @@ type Writer struct {
|
|||
params encoderParams
|
||||
hasher_ hasherHandle
|
||||
input_pos_ uint64
|
||||
ringbuffer_ RingBuffer
|
||||
ringbuffer_ ringBuffer
|
||||
cmd_alloc_size_ uint
|
||||
commands_ []command
|
||||
num_commands_ uint
|
||||
|
@ -175,7 +178,7 @@ func hashTableSize(max_table_size uint, input_size uint) uint {
|
|||
}
|
||||
|
||||
func getHashTable(s *Writer, quality int, input_size uint, table_size *uint) []int {
|
||||
var max_table_size uint = MaxHashTableSize(quality)
|
||||
var max_table_size uint = maxHashTableSize(quality)
|
||||
var htsize uint = hashTableSize(max_table_size, input_size)
|
||||
/* Use smaller hash table when input.size() is smaller, since we
|
||||
fill the table, incurring O(hash table size) overhead for
|
||||
|
@ -184,7 +187,7 @@ func getHashTable(s *Writer, quality int, input_size uint, table_size *uint) []i
|
|||
|
||||
var table []int
|
||||
assert(max_table_size >= 256)
|
||||
if quality == FAST_ONE_PASS_COMPRESSION_QUALITY {
|
||||
if quality == fastOnePassCompressionQuality {
|
||||
/* Only odd shifts are supported by fast-one-pass. */
|
||||
if htsize&0xAAAAA == 0 {
|
||||
htsize <<= 1
|
||||
|
@ -724,7 +727,7 @@ func chooseContextMap(quality int, bigram_histo []uint32, num_literal_contexts *
|
|||
entropy[2] *= entropy[0]
|
||||
entropy[3] *= entropy[0]
|
||||
|
||||
if quality < MIN_QUALITY_FOR_HQ_CONTEXT_MODELING {
|
||||
if quality < minQualityForHqContextModeling {
|
||||
/* 3 context models is a bit slower, don't use it at lower qualities. */
|
||||
entropy[3] = entropy[1] * 10
|
||||
}
|
||||
|
@ -876,7 +879,7 @@ func shouldUseComplexStaticContextMap(input []byte, start_pos uint, length uint,
|
|||
}
|
||||
|
||||
func decideOverLiteralContextModeling(input []byte, start_pos uint, length uint, mask uint, quality int, size_hint uint, num_literal_contexts *uint, literal_context_map *[]uint32) {
|
||||
if quality < MIN_QUALITY_FOR_CONTEXT_MODELING || length < 64 {
|
||||
if quality < minQualityForContextModeling || length < 64 {
|
||||
return
|
||||
} else if shouldUseComplexStaticContextMap(input, start_pos, length, mask, quality, size_hint, num_literal_contexts, literal_context_map) {
|
||||
} else /* Context map was already set, nothing else to do. */
|
||||
|
@ -935,7 +938,7 @@ func shouldCompress_encode(data []byte, mask uint, last_flush_pos uint64, bytes
|
|||
func chooseContextMode(params *encoderParams, data []byte, pos uint, mask uint, length uint) int {
|
||||
/* We only do the computation for the option of something else than
|
||||
CONTEXT_UTF8 for the highest qualities */
|
||||
if params.quality >= MIN_QUALITY_FOR_HQ_BLOCK_SPLITTING && !BrotliIsMostlyUTF8(data, pos, mask, length, kMinUTF8Ratio) {
|
||||
if params.quality >= minQualityForHqBlockSplitting && !isMostlyUTF8(data, pos, mask, length, kMinUTF8Ratio) {
|
||||
return contextSigned
|
||||
}
|
||||
|
||||
|
@ -951,7 +954,7 @@ func writeMetaBlockInternal(data []byte, mask uint, last_flush_pos uint64, bytes
|
|||
|
||||
if bytes == 0 {
|
||||
/* Write the ISLAST and ISEMPTY bits. */
|
||||
BrotliWriteBits(2, 3, storage_ix, storage)
|
||||
writeBits(2, 3, storage_ix, storage)
|
||||
|
||||
*storage_ix = (*storage_ix + 7) &^ 7
|
||||
return
|
||||
|
@ -969,14 +972,14 @@ func writeMetaBlockInternal(data []byte, mask uint, last_flush_pos uint64, bytes
|
|||
assert(*storage_ix <= 14)
|
||||
last_bytes = uint16(storage[1]<<8 | storage[0])
|
||||
last_bytes_bits = byte(*storage_ix)
|
||||
if params.quality <= MAX_QUALITY_FOR_STATIC_ENTROPY_CODES {
|
||||
if params.quality <= maxQualityForStaticEntropyCodes {
|
||||
storeMetaBlockFast(data, uint(wrapped_last_flush_pos), bytes, mask, is_last, params, commands, num_commands, storage_ix, storage)
|
||||
} else if params.quality < MIN_QUALITY_FOR_BLOCK_SPLIT {
|
||||
} else if params.quality < minQualityForBlockSplit {
|
||||
storeMetaBlockTrivial(data, uint(wrapped_last_flush_pos), bytes, mask, is_last, params, commands, num_commands, storage_ix, storage)
|
||||
} else {
|
||||
var mb metaBlockSplit
|
||||
initMetaBlockSplit(&mb)
|
||||
if params.quality < MIN_QUALITY_FOR_HQ_BLOCK_SPLITTING {
|
||||
if params.quality < minQualityForHqBlockSplitting {
|
||||
var num_literal_contexts uint = 1
|
||||
var literal_context_map []uint32 = nil
|
||||
if !params.disable_literal_context_modeling {
|
||||
|
@ -988,7 +991,7 @@ func writeMetaBlockInternal(data []byte, mask uint, last_flush_pos uint64, bytes
|
|||
buildMetaBlock(data, uint(wrapped_last_flush_pos), mask, &block_params, prev_byte, prev_byte2, commands, num_commands, literal_context_mode, &mb)
|
||||
}
|
||||
|
||||
if params.quality >= MIN_QUALITY_FOR_OPTIMIZE_HISTOGRAMS {
|
||||
if params.quality >= minQualityForOptimizeHistograms {
|
||||
/* The number of distance symbols effectively used for distance
|
||||
histograms. It might be less than distance alphabet size
|
||||
for "Large Window Brotli" (32-bit). */
|
||||
|
@ -1019,7 +1022,7 @@ func chooseDistanceParams(params *encoderParams) {
|
|||
var distance_postfix_bits uint32 = 0
|
||||
var num_direct_distance_codes uint32 = 0
|
||||
|
||||
if params.quality >= MIN_QUALITY_FOR_NONZERO_DISTANCE_PARAMS {
|
||||
if params.quality >= minQualityForNonzeroDistanceParams {
|
||||
var ndirect_msb uint32
|
||||
if params.mode == modeFont {
|
||||
distance_postfix_bits = 1
|
||||
|
@ -1046,25 +1049,25 @@ func ensureInitialized(s *Writer) bool {
|
|||
|
||||
s.last_bytes_bits_ = 0
|
||||
s.last_bytes_ = 0
|
||||
s.remaining_metadata_bytes_ = BROTLI_UINT32_MAX
|
||||
s.remaining_metadata_bytes_ = math.MaxUint32
|
||||
|
||||
SanitizeParams(&s.params)
|
||||
s.params.lgblock = ComputeLgBlock(&s.params)
|
||||
sanitizeParams(&s.params)
|
||||
s.params.lgblock = computeLgBlock(&s.params)
|
||||
chooseDistanceParams(&s.params)
|
||||
|
||||
RingBufferSetup(&s.params, &s.ringbuffer_)
|
||||
ringBufferSetup(&s.params, &s.ringbuffer_)
|
||||
|
||||
/* Initialize last byte with stream header. */
|
||||
{
|
||||
var lgwin int = int(s.params.lgwin)
|
||||
if s.params.quality == FAST_ONE_PASS_COMPRESSION_QUALITY || s.params.quality == FAST_TWO_PASS_COMPRESSION_QUALITY {
|
||||
if s.params.quality == fastOnePassCompressionQuality || s.params.quality == fastTwoPassCompressionQuality {
|
||||
lgwin = brotli_max_int(lgwin, 18)
|
||||
}
|
||||
|
||||
encodeWindowBits(lgwin, s.params.large_window, &s.last_bytes_, &s.last_bytes_bits_)
|
||||
}
|
||||
|
||||
if s.params.quality == FAST_ONE_PASS_COMPRESSION_QUALITY {
|
||||
if s.params.quality == fastOnePassCompressionQuality {
|
||||
initCommandPrefixCodes(s.cmd_depths_[:], s.cmd_bits_[:], s.cmd_code_[:], &s.cmd_code_numbits_)
|
||||
}
|
||||
|
||||
|
@ -1112,7 +1115,7 @@ func encoderInitState(s *Writer) {
|
|||
s.is_last_block_emitted_ = false
|
||||
s.is_initialized_ = false
|
||||
|
||||
RingBufferInit(&s.ringbuffer_)
|
||||
ringBufferInit(&s.ringbuffer_)
|
||||
|
||||
s.commands_ = nil
|
||||
s.cmd_alloc_size_ = 0
|
||||
|
@ -1137,8 +1140,8 @@ func encoderInitState(s *Writer) {
|
|||
copied to the ring buffer, otherwise the next WriteBrotliData() will fail.
|
||||
*/
|
||||
func copyInputToRingBuffer(s *Writer, input_size uint, input_buffer []byte) {
|
||||
var ringbuffer_ *RingBuffer = &s.ringbuffer_
|
||||
RingBufferWrite(input_buffer, input_size, ringbuffer_)
|
||||
var ringbuffer_ *ringBuffer = &s.ringbuffer_
|
||||
ringBufferWrite(input_buffer, input_size, ringbuffer_)
|
||||
s.input_pos_ += uint64(input_size)
|
||||
|
||||
/* TL;DR: If needed, initialize 7 more bytes in the ring buffer to make the
|
||||
|
@ -1262,12 +1265,12 @@ func encodeData(s *Writer, is_last bool, force_flush bool, out_size *uint, outpu
|
|||
return false
|
||||
}
|
||||
|
||||
if s.params.quality == FAST_TWO_PASS_COMPRESSION_QUALITY && s.command_buf_ == nil {
|
||||
if s.params.quality == fastTwoPassCompressionQuality && s.command_buf_ == nil {
|
||||
s.command_buf_ = make([]uint32, kCompressFragmentTwoPassBlockSize)
|
||||
s.literal_buf_ = make([]byte, kCompressFragmentTwoPassBlockSize)
|
||||
}
|
||||
|
||||
if s.params.quality == FAST_ONE_PASS_COMPRESSION_QUALITY || s.params.quality == FAST_TWO_PASS_COMPRESSION_QUALITY {
|
||||
if s.params.quality == fastOnePassCompressionQuality || s.params.quality == fastTwoPassCompressionQuality {
|
||||
var storage []byte
|
||||
var storage_ix uint = uint(s.last_bytes_bits_)
|
||||
var table_size uint
|
||||
|
@ -1285,7 +1288,7 @@ func encodeData(s *Writer, is_last bool, force_flush bool, out_size *uint, outpu
|
|||
storage[0] = byte(s.last_bytes_)
|
||||
storage[1] = byte(s.last_bytes_ >> 8)
|
||||
table = getHashTable(s, s.params.quality, uint(bytes), &table_size)
|
||||
if s.params.quality == FAST_ONE_PASS_COMPRESSION_QUALITY {
|
||||
if s.params.quality == fastOnePassCompressionQuality {
|
||||
compressFragmentFast(data[wrapped_last_processed_pos&mask:], uint(bytes), is_last, table, table_size, s.cmd_depths_[:], s.cmd_bits_[:], &s.cmd_code_numbits_, s.cmd_code_[:], &storage_ix, storage)
|
||||
} else {
|
||||
compressFragmentTwoPass(data[wrapped_last_processed_pos&mask:], uint(bytes), is_last, s.command_buf_, s.literal_buf_, table, table_size, &storage_ix, storage)
|
||||
|
@ -1327,22 +1330,22 @@ func encodeData(s *Writer, is_last bool, force_flush bool, out_size *uint, outpu
|
|||
extendLastCommand(s, &bytes, &wrapped_last_processed_pos)
|
||||
}
|
||||
|
||||
if s.params.quality == ZOPFLIFICATION_QUALITY {
|
||||
if s.params.quality == zopflificationQuality {
|
||||
assert(s.params.hasher.type_ == 10)
|
||||
createZopfliBackwardReferences(uint(bytes), uint(wrapped_last_processed_pos), data, uint(mask), &s.params, s.hasher_.(*h10), s.dist_cache_[:], &s.last_insert_len_, s.commands_[s.num_commands_:], &s.num_commands_, &s.num_literals_)
|
||||
} else if s.params.quality == HQ_ZOPFLIFICATION_QUALITY {
|
||||
} else if s.params.quality == hqZopflificationQuality {
|
||||
assert(s.params.hasher.type_ == 10)
|
||||
createHqZopfliBackwardReferences(uint(bytes), uint(wrapped_last_processed_pos), data, uint(mask), &s.params, s.hasher_, s.dist_cache_[:], &s.last_insert_len_, s.commands_[s.num_commands_:], &s.num_commands_, &s.num_literals_)
|
||||
} else {
|
||||
createBackwardReferences(uint(bytes), uint(wrapped_last_processed_pos), data, uint(mask), &s.params, s.hasher_, s.dist_cache_[:], &s.last_insert_len_, s.commands_[s.num_commands_:], &s.num_commands_, &s.num_literals_)
|
||||
}
|
||||
{
|
||||
var max_length uint = MaxMetablockSize(&s.params)
|
||||
var max_length uint = maxMetablockSize(&s.params)
|
||||
var max_literals uint = max_length / 8
|
||||
var max_commands uint = max_length / 8
|
||||
var processed_bytes uint = uint(s.input_pos_ - s.last_flush_pos_)
|
||||
var next_input_fits_metablock bool = (processed_bytes+inputBlockSize(s) <= max_length)
|
||||
var should_flush bool = (s.params.quality < MIN_QUALITY_FOR_BLOCK_SPLIT && s.num_literals_+s.num_commands_ >= MAX_NUM_DELAYED_SYMBOLS)
|
||||
var should_flush bool = (s.params.quality < minQualityForBlockSplit && s.num_literals_+s.num_commands_ >= maxNumDelayedSymbols)
|
||||
/* If maximal possible additional block doesn't fit metablock, flush now. */
|
||||
/* TODO: Postpone decision until next block arrives? */
|
||||
|
||||
|
@ -1425,11 +1428,11 @@ func writeMetadataHeader(s *Writer, block_size uint, header []byte) uint {
|
|||
s.last_bytes_ = 0
|
||||
s.last_bytes_bits_ = 0
|
||||
|
||||
BrotliWriteBits(1, 0, &storage_ix, header)
|
||||
BrotliWriteBits(2, 3, &storage_ix, header)
|
||||
BrotliWriteBits(1, 0, &storage_ix, header)
|
||||
writeBits(1, 0, &storage_ix, header)
|
||||
writeBits(2, 3, &storage_ix, header)
|
||||
writeBits(1, 0, &storage_ix, header)
|
||||
if block_size == 0 {
|
||||
BrotliWriteBits(2, 0, &storage_ix, header)
|
||||
writeBits(2, 0, &storage_ix, header)
|
||||
} else {
|
||||
var nbits uint32
|
||||
if block_size == 1 {
|
||||
|
@ -1438,8 +1441,8 @@ func writeMetadataHeader(s *Writer, block_size uint, header []byte) uint {
|
|||
nbits = log2FloorNonZero(uint(uint32(block_size)-1)) + 1
|
||||
}
|
||||
var nbytes uint32 = (nbits + 7) / 8
|
||||
BrotliWriteBits(2, uint64(nbytes), &storage_ix, header)
|
||||
BrotliWriteBits(uint(8*nbytes), uint64(block_size)-1, &storage_ix, header)
|
||||
writeBits(2, uint64(nbytes), &storage_ix, header)
|
||||
writeBits(uint(8*nbytes), uint64(block_size)-1, &storage_ix, header)
|
||||
}
|
||||
|
||||
return (storage_ix + 7) >> 3
|
||||
|
@ -1490,11 +1493,11 @@ func encoderCompressStreamFast(s *Writer, op int, available_in *uint, next_in *[
|
|||
var command_buf []uint32 = nil
|
||||
var tmp_literal_buf []byte = nil
|
||||
var literal_buf []byte = nil
|
||||
if s.params.quality != FAST_ONE_PASS_COMPRESSION_QUALITY && s.params.quality != FAST_TWO_PASS_COMPRESSION_QUALITY {
|
||||
if s.params.quality != fastOnePassCompressionQuality && s.params.quality != fastTwoPassCompressionQuality {
|
||||
return false
|
||||
}
|
||||
|
||||
if s.params.quality == FAST_TWO_PASS_COMPRESSION_QUALITY {
|
||||
if s.params.quality == fastTwoPassCompressionQuality {
|
||||
if s.command_buf_ == nil && buf_size == kCompressFragmentTwoPassBlockSize {
|
||||
s.command_buf_ = make([]uint32, kCompressFragmentTwoPassBlockSize)
|
||||
s.literal_buf_ = make([]byte, kCompressFragmentTwoPassBlockSize)
|
||||
|
@ -1541,7 +1544,7 @@ func encoderCompressStreamFast(s *Writer, op int, available_in *uint, next_in *[
|
|||
storage[1] = byte(s.last_bytes_ >> 8)
|
||||
table = getHashTable(s, s.params.quality, block_size, &table_size)
|
||||
|
||||
if s.params.quality == FAST_ONE_PASS_COMPRESSION_QUALITY {
|
||||
if s.params.quality == fastOnePassCompressionQuality {
|
||||
compressFragmentFast(*next_in, block_size, is_last, table, table_size, s.cmd_depths_[:], s.cmd_bits_[:], &s.cmd_code_numbits_, s.cmd_code_[:], &storage_ix, storage)
|
||||
} else {
|
||||
compressFragmentTwoPass(*next_in, block_size, is_last, command_buf, literal_buf, table, table_size, &storage_ix, storage)
|
||||
|
@ -1616,7 +1619,7 @@ func processMetadata(s *Writer, available_in *uint, next_in *[]byte) bool {
|
|||
/* Exit workflow only when there is no more input and no more output.
|
||||
Otherwise client may continue producing empty metadata blocks. */
|
||||
if s.remaining_metadata_bytes_ == 0 {
|
||||
s.remaining_metadata_bytes_ = BROTLI_UINT32_MAX
|
||||
s.remaining_metadata_bytes_ = math.MaxUint32
|
||||
s.stream_state_ = streamProcessing
|
||||
break
|
||||
}
|
||||
|
@ -1659,7 +1662,7 @@ func encoderCompressStream(s *Writer, op int, available_in *uint, next_in *[]byt
|
|||
}
|
||||
|
||||
/* Unfinished metadata block; check requirements. */
|
||||
if s.remaining_metadata_bytes_ != BROTLI_UINT32_MAX {
|
||||
if s.remaining_metadata_bytes_ != math.MaxUint32 {
|
||||
if uint32(*available_in) != s.remaining_metadata_bytes_ {
|
||||
return false
|
||||
}
|
||||
|
@ -1681,7 +1684,7 @@ func encoderCompressStream(s *Writer, op int, available_in *uint, next_in *[]byt
|
|||
return false
|
||||
}
|
||||
|
||||
if s.params.quality == FAST_ONE_PASS_COMPRESSION_QUALITY || s.params.quality == FAST_TWO_PASS_COMPRESSION_QUALITY {
|
||||
if s.params.quality == fastOnePassCompressionQuality || s.params.quality == fastTwoPassCompressionQuality {
|
||||
return encoderCompressStreamFast(s, op, available_in, next_in)
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ type encoderDictionary struct {
|
|||
cutoffTransforms uint64
|
||||
hash_table []uint16
|
||||
buckets []uint16
|
||||
dict_words []DictWord
|
||||
dict_words []dictWord
|
||||
}
|
||||
|
||||
func initEncoderDictionary(dict *encoderDictionary) {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brotli
|
||||
|
||||
import "math"
|
||||
|
||||
/* Copyright 2010 Google Inc. All Rights Reserved.
|
||||
|
||||
Distributed under MIT license.
|
||||
|
@ -164,7 +166,7 @@ func sortHuffmanTree(v0 *huffmanTree, v1 *huffmanTree) bool {
|
|||
func createHuffmanTree(data []uint32, length uint, tree_limit int, tree []huffmanTree, depth []byte) {
|
||||
var count_limit uint32
|
||||
var sentinel huffmanTree
|
||||
initHuffmanTree(&sentinel, BROTLI_UINT32_MAX, -1, -1)
|
||||
initHuffmanTree(&sentinel, math.MaxUint32, -1, -1)
|
||||
|
||||
/* For block sizes below 64 kB, we never need to do a second iteration
|
||||
of this loop. Probably all of our block sizes will be smaller than
|
||||
|
|
|
@ -778,8 +778,8 @@ var kStaticDistanceCodeDepth = [64]byte{
|
|||
|
||||
var kCodeLengthBits = [18]uint32{0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 15, 31, 0, 11, 7}
|
||||
|
||||
func StoreStaticCodeLengthCode(storage_ix *uint, storage []byte) {
|
||||
BrotliWriteBits(40, 0x0000FF55555554, storage_ix, storage)
|
||||
func storeStaticCodeLengthCode(storage_ix *uint, storage []byte) {
|
||||
writeBits(40, 0x0000FF55555554, storage_ix, storage)
|
||||
}
|
||||
|
||||
var kZeroRepsBits = [numCommandSymbols]uint64{
|
||||
|
@ -4318,8 +4318,8 @@ var kStaticCommandCodeBits = [numCommandSymbols]uint16{
|
|||
}
|
||||
|
||||
func storeStaticCommandHuffmanTree(storage_ix *uint, storage []byte) {
|
||||
BrotliWriteBits(56, 0x92624416307003, storage_ix, storage)
|
||||
BrotliWriteBits(3, 0x00000000, storage_ix, storage)
|
||||
writeBits(56, 0x92624416307003, storage_ix, storage)
|
||||
writeBits(3, 0x00000000, storage_ix, storage)
|
||||
}
|
||||
|
||||
var kStaticDistanceCodeBits = [64]uint16{
|
||||
|
@ -4390,5 +4390,5 @@ var kStaticDistanceCodeBits = [64]uint16{
|
|||
}
|
||||
|
||||
func storeStaticDistanceHuffmanTree(storage_ix *uint, storage []byte) {
|
||||
BrotliWriteBits(28, 0x0369DC03, storage_ix, storage)
|
||||
writeBits(28, 0x0369DC03, storage_ix, storage)
|
||||
}
|
||||
|
|
10
h10.go
10
h10.go
|
@ -165,13 +165,13 @@ func findAllMatchesH10(handle *h10, dictionary *encoderDictionary, data []byte,
|
|||
var cur_ix_masked uint = cur_ix & ring_buffer_mask
|
||||
var best_len uint = 1
|
||||
var short_match_max_backward uint
|
||||
if params.quality != HQ_ZOPFLIFICATION_QUALITY {
|
||||
if params.quality != hqZopflificationQuality {
|
||||
short_match_max_backward = 16
|
||||
} else {
|
||||
short_match_max_backward = 64
|
||||
}
|
||||
var stop uint = cur_ix - short_match_max_backward
|
||||
var dict_matches [BROTLI_MAX_STATIC_DICTIONARY_MATCH_LEN + 1]uint32
|
||||
var dict_matches [maxStaticDictionaryMatchLen + 1]uint32
|
||||
var i uint
|
||||
if cur_ix < short_match_max_backward {
|
||||
stop = 0
|
||||
|
@ -201,13 +201,13 @@ func findAllMatchesH10(handle *h10, dictionary *encoderDictionary, data []byte,
|
|||
matches = storeAndFindMatchesH10(handle, data, cur_ix, ring_buffer_mask, max_length, max_backward, &best_len, matches)
|
||||
}
|
||||
|
||||
for i = 0; i <= BROTLI_MAX_STATIC_DICTIONARY_MATCH_LEN; i++ {
|
||||
for i = 0; i <= maxStaticDictionaryMatchLen; i++ {
|
||||
dict_matches[i] = kInvalidMatch
|
||||
}
|
||||
{
|
||||
var minlen uint = brotli_max_size_t(4, best_len+1)
|
||||
if BrotliFindAllStaticDictionaryMatches(dictionary, data[cur_ix_masked:], minlen, max_length, dict_matches[0:]) {
|
||||
var maxlen uint = brotli_min_size_t(BROTLI_MAX_STATIC_DICTIONARY_MATCH_LEN, max_length)
|
||||
if findAllStaticDictionaryMatches(dictionary, data[cur_ix_masked:], minlen, max_length, dict_matches[0:]) {
|
||||
var maxlen uint = brotli_min_size_t(maxStaticDictionaryMatchLen, max_length)
|
||||
var l uint
|
||||
for l = minlen; l <= maxlen; l++ {
|
||||
var dict_id uint32 = dict_matches[l]
|
||||
|
|
2
hash.go
2
hash.go
|
@ -331,7 +331,7 @@ func hasherSetup(handle *hasherHandle, params *encoderParams, data []byte, posit
|
|||
var common *hasherCommon = nil
|
||||
var one_shot bool = (position == 0 && is_last)
|
||||
if *handle == nil {
|
||||
ChooseHasher(params, ¶ms.hasher)
|
||||
chooseHasher(params, ¶ms.hasher)
|
||||
self = newHasher(params.hasher.type_)
|
||||
|
||||
*handle = self
|
||||
|
|
|
@ -477,7 +477,7 @@ func buildCodeLengthsHuffmanTable(table []huffmanCode, code_lengths []byte, coun
|
|||
}
|
||||
}
|
||||
|
||||
func buildHuffmanTable(root_table []huffmanCode, root_bits int, symbol_lists SymbolList, count []uint16) uint32 {
|
||||
func buildHuffmanTable(root_table []huffmanCode, root_bits int, symbol_lists symbolList, count []uint16) uint32 {
|
||||
var code huffmanCode /* current table entry */ /* next available space in table */ /* current code length */ /* symbol index in original or sorted table */ /* prefix code */ /* prefix code addend */ /* 2nd level table prefix code */ /* 2nd level table prefix code addend */ /* step size to replicate values in current table */ /* key length of current table */ /* size of current table */ /* sum of root table size and 2nd level table sizes */
|
||||
var table []huffmanCode
|
||||
var len int
|
||||
|
@ -497,7 +497,7 @@ func buildHuffmanTable(root_table []huffmanCode, root_bits int, symbol_lists Sym
|
|||
assert(root_bits <= reverseBitsMax)
|
||||
assert(huffmanMaxCodeLength-root_bits <= reverseBitsMax)
|
||||
|
||||
for SymbolListGet(symbol_lists, max_length) == 0xFFFF {
|
||||
for symbolListGet(symbol_lists, max_length) == 0xFFFF {
|
||||
max_length--
|
||||
}
|
||||
max_length += huffmanMaxCodeLength + 1
|
||||
|
@ -521,7 +521,7 @@ func buildHuffmanTable(root_table []huffmanCode, root_bits int, symbol_lists Sym
|
|||
for {
|
||||
symbol = bits - (huffmanMaxCodeLength + 1)
|
||||
for bits_count = int(count[bits]); bits_count != 0; bits_count-- {
|
||||
symbol = int(SymbolListGet(symbol_lists, symbol))
|
||||
symbol = int(symbolListGet(symbol_lists, symbol))
|
||||
code = constructHuffmanCode(byte(bits), uint16(symbol))
|
||||
replicateValue(table[reverseBits8(key):], step, table_size, code)
|
||||
key += key_step
|
||||
|
@ -562,7 +562,7 @@ func buildHuffmanTable(root_table []huffmanCode, root_bits int, symbol_lists Sym
|
|||
sub_key = 0
|
||||
}
|
||||
|
||||
symbol = int(SymbolListGet(symbol_lists, symbol))
|
||||
symbol = int(symbolListGet(symbol_lists, symbol))
|
||||
code = constructHuffmanCode(byte(len-root_bits), uint16(symbol))
|
||||
replicateValue(table[reverseBits8(sub_key):], step, table_size, code)
|
||||
sub_key += sub_key_step
|
||||
|
|
|
@ -133,7 +133,7 @@ func estimateBitCostsForLiteralsUTF8(pos uint, len uint, mask uint, data []byte,
|
|||
}
|
||||
|
||||
func estimateBitCostsForLiterals(pos uint, len uint, mask uint, data []byte, cost []float32) {
|
||||
if BrotliIsMostlyUTF8(data, pos, mask, uint(len), kMinUTF8Ratio) {
|
||||
if isMostlyUTF8(data, pos, mask, uint(len), kMinUTF8Ratio) {
|
||||
estimateBitCostsForLiteralsUTF8(pos, uint(len), mask, data, cost)
|
||||
return
|
||||
} else {
|
||||
|
|
|
@ -124,7 +124,7 @@ func recomputeDistancePrefixes(cmds []command, num_commands uint, orig_params *d
|
|||
for i = 0; i < num_commands; i++ {
|
||||
var cmd *command = &cmds[i]
|
||||
if commandCopyLen(cmd) != 0 && cmd.cmd_prefix_ >= 128 {
|
||||
PrefixEncodeCopyDistance(uint(commandRestoreDistanceCode(cmd, orig_params)), uint(new_params.num_direct_distance_codes), uint(new_params.distance_postfix_bits), &cmd.dist_prefix_, &cmd.dist_extra_)
|
||||
prefixEncodeCopyDistance(uint(commandRestoreDistanceCode(cmd, orig_params)), uint(new_params.num_direct_distance_codes), uint(new_params.distance_postfix_bits), &cmd.dist_prefix_, &cmd.dist_extra_)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ func computeDistanceCost(cmds []command, num_commands uint, orig_params *distanc
|
|||
return false
|
||||
}
|
||||
|
||||
PrefixEncodeCopyDistance(uint(distance), uint(new_params.num_direct_distance_codes), uint(new_params.distance_postfix_bits), &dist_prefix, &dist_extra)
|
||||
prefixEncodeCopyDistance(uint(distance), uint(new_params.num_direct_distance_codes), uint(new_params.distance_postfix_bits), &dist_prefix, &dist_extra)
|
||||
}
|
||||
|
||||
histogramAddDistance(&histo, uint(dist_prefix)&0x3FF)
|
||||
|
|
|
@ -32,7 +32,7 @@ package brotli
|
|||
|
||||
/* Here distance_code is an intermediate code, i.e. one of the special codes or
|
||||
the actual distance increased by BROTLI_NUM_DISTANCE_SHORT_CODES - 1. */
|
||||
func PrefixEncodeCopyDistance(distance_code uint, num_direct_codes uint, postfix_bits uint, code *uint16, extra_bits *uint32) {
|
||||
func prefixEncodeCopyDistance(distance_code uint, num_direct_codes uint, postfix_bits uint, code *uint16, extra_bits *uint32) {
|
||||
if distance_code < numDistanceShortCodes+num_direct_codes {
|
||||
*code = uint16(distance_code)
|
||||
*extra_bits = 0
|
||||
|
|
1412
prefix_dec.go
1412
prefix_dec.go
File diff suppressed because it is too large
Load Diff
64
quality.go
64
quality.go
|
@ -1,36 +1,36 @@
|
|||
package brotli
|
||||
|
||||
const FAST_ONE_PASS_COMPRESSION_QUALITY = 0
|
||||
const fastOnePassCompressionQuality = 0
|
||||
|
||||
const FAST_TWO_PASS_COMPRESSION_QUALITY = 1
|
||||
const fastTwoPassCompressionQuality = 1
|
||||
|
||||
const ZOPFLIFICATION_QUALITY = 10
|
||||
const zopflificationQuality = 10
|
||||
|
||||
const HQ_ZOPFLIFICATION_QUALITY = 11
|
||||
const hqZopflificationQuality = 11
|
||||
|
||||
const MAX_QUALITY_FOR_STATIC_ENTROPY_CODES = 2
|
||||
const maxQualityForStaticEntropyCodes = 2
|
||||
|
||||
const MIN_QUALITY_FOR_BLOCK_SPLIT = 4
|
||||
const minQualityForBlockSplit = 4
|
||||
|
||||
const MIN_QUALITY_FOR_NONZERO_DISTANCE_PARAMS = 4
|
||||
const minQualityForNonzeroDistanceParams = 4
|
||||
|
||||
const MIN_QUALITY_FOR_OPTIMIZE_HISTOGRAMS = 4
|
||||
const minQualityForOptimizeHistograms = 4
|
||||
|
||||
const MIN_QUALITY_FOR_EXTENSIVE_REFERENCE_SEARCH = 5
|
||||
const minQualityForExtensiveReferenceSearch = 5
|
||||
|
||||
const MIN_QUALITY_FOR_CONTEXT_MODELING = 5
|
||||
const minQualityForContextModeling = 5
|
||||
|
||||
const MIN_QUALITY_FOR_HQ_CONTEXT_MODELING = 7
|
||||
const minQualityForHqContextModeling = 7
|
||||
|
||||
const MIN_QUALITY_FOR_HQ_BLOCK_SPLITTING = 10
|
||||
const minQualityForHqBlockSplitting = 10
|
||||
|
||||
/* For quality below MIN_QUALITY_FOR_BLOCK_SPLIT there is no block splitting,
|
||||
so we buffer at most this much literals and commands. */
|
||||
const MAX_NUM_DELAYED_SYMBOLS = 0x2FFF
|
||||
const maxNumDelayedSymbols = 0x2FFF
|
||||
|
||||
/* Returns hash-table size for quality levels 0 and 1. */
|
||||
func MaxHashTableSize(quality int) uint {
|
||||
if quality == FAST_ONE_PASS_COMPRESSION_QUALITY {
|
||||
func maxHashTableSize(quality int) uint {
|
||||
if quality == fastOnePassCompressionQuality {
|
||||
return 1 << 15
|
||||
} else {
|
||||
return 1 << 17
|
||||
|
@ -38,23 +38,23 @@ func MaxHashTableSize(quality int) uint {
|
|||
}
|
||||
|
||||
/* The maximum length for which the zopflification uses distinct distances. */
|
||||
const MAX_ZOPFLI_LEN_QUALITY_10 = 150
|
||||
const maxZopfliLenQuality10 = 150
|
||||
|
||||
const MAX_ZOPFLI_LEN_QUALITY_11 = 325
|
||||
const maxZopfliLenQuality11 = 325
|
||||
|
||||
/* Do not thoroughly search when a long copy is found. */
|
||||
const BROTLI_LONG_COPY_QUICK_STEP = 16384
|
||||
const longCopyQuickStep = 16384
|
||||
|
||||
func MaxZopfliLen(params *encoderParams) uint {
|
||||
func maxZopfliLen(params *encoderParams) uint {
|
||||
if params.quality <= 10 {
|
||||
return MAX_ZOPFLI_LEN_QUALITY_10
|
||||
return maxZopfliLenQuality10
|
||||
} else {
|
||||
return MAX_ZOPFLI_LEN_QUALITY_11
|
||||
return maxZopfliLenQuality11
|
||||
}
|
||||
}
|
||||
|
||||
/* Number of best candidates to evaluate to expand Zopfli chain. */
|
||||
func MaxZopfliCandidates(params *encoderParams) uint {
|
||||
func maxZopfliCandidates(params *encoderParams) uint {
|
||||
if params.quality <= 10 {
|
||||
return 1
|
||||
} else {
|
||||
|
@ -62,9 +62,9 @@ func MaxZopfliCandidates(params *encoderParams) uint {
|
|||
}
|
||||
}
|
||||
|
||||
func SanitizeParams(params *encoderParams) {
|
||||
func sanitizeParams(params *encoderParams) {
|
||||
params.quality = brotli_min_int(maxQuality, brotli_max_int(minQuality, params.quality))
|
||||
if params.quality <= MAX_QUALITY_FOR_STATIC_ENTROPY_CODES {
|
||||
if params.quality <= maxQualityForStaticEntropyCodes {
|
||||
params.large_window = false
|
||||
}
|
||||
|
||||
|
@ -84,11 +84,11 @@ func SanitizeParams(params *encoderParams) {
|
|||
}
|
||||
|
||||
/* Returns optimized lg_block value. */
|
||||
func ComputeLgBlock(params *encoderParams) int {
|
||||
func computeLgBlock(params *encoderParams) int {
|
||||
var lgblock int = params.lgblock
|
||||
if params.quality == FAST_ONE_PASS_COMPRESSION_QUALITY || params.quality == FAST_TWO_PASS_COMPRESSION_QUALITY {
|
||||
if params.quality == fastOnePassCompressionQuality || params.quality == fastTwoPassCompressionQuality {
|
||||
lgblock = int(params.lgwin)
|
||||
} else if params.quality < MIN_QUALITY_FOR_BLOCK_SPLIT {
|
||||
} else if params.quality < minQualityForBlockSplit {
|
||||
lgblock = 14
|
||||
} else if lgblock == 0 {
|
||||
lgblock = 16
|
||||
|
@ -107,12 +107,12 @@ func ComputeLgBlock(params *encoderParams) int {
|
|||
added block fits there completely and we still get lgwin bits and at least
|
||||
read_block_size_bits + 1 bits because the copy tail length needs to be
|
||||
smaller than ring-buffer size. */
|
||||
func ComputeRbBits(params *encoderParams) int {
|
||||
func computeRbBits(params *encoderParams) int {
|
||||
return 1 + brotli_max_int(int(params.lgwin), params.lgblock)
|
||||
}
|
||||
|
||||
func MaxMetablockSize(params *encoderParams) uint {
|
||||
var bits int = brotli_min_int(ComputeRbBits(params), maxInputBlockBits)
|
||||
func maxMetablockSize(params *encoderParams) uint {
|
||||
var bits int = brotli_min_int(computeRbBits(params), maxInputBlockBits)
|
||||
return uint(1) << uint(bits)
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ func MaxMetablockSize(params *encoderParams) uint {
|
|||
At first 8 byte strides are taken and every second byte is put to hasher.
|
||||
After 4x more literals stride by 16 bytes, every put 4-th byte to hasher.
|
||||
Applied only to qualities 2 to 9. */
|
||||
func LiteralSpreeLengthForSparseSearch(params *encoderParams) uint {
|
||||
func literalSpreeLengthForSparseSearch(params *encoderParams) uint {
|
||||
if params.quality < 9 {
|
||||
return 64
|
||||
} else {
|
||||
|
@ -130,7 +130,7 @@ func LiteralSpreeLengthForSparseSearch(params *encoderParams) uint {
|
|||
}
|
||||
}
|
||||
|
||||
func ChooseHasher(params *encoderParams, hparams *hasherParams) {
|
||||
func chooseHasher(params *encoderParams, hparams *hasherParams) {
|
||||
if params.quality > 9 {
|
||||
hparams.type_ = 10
|
||||
} else if params.quality == 4 && params.size_hint >= 1<<20 {
|
||||
|
|
|
@ -23,7 +23,7 @@ const readBufSize = 32 * 1024
|
|||
// NewReader initializes new Reader instance.
|
||||
func NewReader(src io.Reader) *Reader {
|
||||
r := new(Reader)
|
||||
BrotliDecoderStateInit(r)
|
||||
decoderStateInit(r)
|
||||
r.src = src
|
||||
r.buf = make([]byte, readBufSize)
|
||||
return r
|
||||
|
|
|
@ -15,16 +15,16 @@ package brotli
|
|||
|
||||
/* Sliding window over the input data. */
|
||||
|
||||
/* A RingBuffer(window_bits, tail_bits) contains `1 << window_bits' bytes of
|
||||
/* A ringBuffer(window_bits, tail_bits) contains `1 << window_bits' bytes of
|
||||
data in a circular manner: writing a byte writes it to:
|
||||
`position() % (1 << window_bits)'.
|
||||
For convenience, the RingBuffer array contains another copy of the
|
||||
For convenience, the ringBuffer array contains another copy of the
|
||||
first `1 << tail_bits' bytes:
|
||||
buffer_[i] == buffer_[i + (1 << window_bits)], if i < (1 << tail_bits),
|
||||
and another copy of the last two bytes:
|
||||
buffer_[-1] == buffer_[(1 << window_bits) - 1] and
|
||||
buffer_[-2] == buffer_[(1 << window_bits) - 2]. */
|
||||
type RingBuffer struct {
|
||||
type ringBuffer struct {
|
||||
size_ uint32
|
||||
mask_ uint32
|
||||
tail_size_ uint32
|
||||
|
@ -35,15 +35,15 @@ type RingBuffer struct {
|
|||
buffer_ []byte
|
||||
}
|
||||
|
||||
func RingBufferInit(rb *RingBuffer) {
|
||||
func ringBufferInit(rb *ringBuffer) {
|
||||
rb.cur_size_ = 0
|
||||
rb.pos_ = 0
|
||||
rb.data_ = nil
|
||||
rb.buffer_ = nil
|
||||
}
|
||||
|
||||
func RingBufferSetup(params *encoderParams, rb *RingBuffer) {
|
||||
var window_bits int = ComputeRbBits(params)
|
||||
func ringBufferSetup(params *encoderParams, rb *ringBuffer) {
|
||||
var window_bits int = computeRbBits(params)
|
||||
var tail_bits int = params.lgblock
|
||||
*(*uint32)(&rb.size_) = 1 << uint(window_bits)
|
||||
*(*uint32)(&rb.mask_) = (1 << uint(window_bits)) - 1
|
||||
|
@ -51,20 +51,16 @@ func RingBufferSetup(params *encoderParams, rb *RingBuffer) {
|
|||
*(*uint32)(&rb.total_size_) = rb.size_ + rb.tail_size_
|
||||
}
|
||||
|
||||
func RingBufferFree(rb *RingBuffer) {
|
||||
rb.data_ = nil
|
||||
}
|
||||
|
||||
/* Allocates or re-allocates data_ to the given length + plus some slack
|
||||
region before and after. Fills the slack regions with zeros. */
|
||||
|
||||
var RingBufferInitBuffer_kSlackForEightByteHashingEverywhere uint = 7
|
||||
var kSlackForEightByteHashingEverywhere uint = 7
|
||||
|
||||
func RingBufferInitBuffer(buflen uint32, rb *RingBuffer) {
|
||||
var new_data []byte = make([]byte, (2 + uint(buflen) + RingBufferInitBuffer_kSlackForEightByteHashingEverywhere))
|
||||
func ringBufferInitBuffer(buflen uint32, rb *ringBuffer) {
|
||||
var new_data []byte = make([]byte, (2 + uint(buflen) + kSlackForEightByteHashingEverywhere))
|
||||
var i uint
|
||||
if rb.data_ != nil {
|
||||
copy(new_data, rb.data_[:2+rb.cur_size_+uint32(RingBufferInitBuffer_kSlackForEightByteHashingEverywhere)])
|
||||
copy(new_data, rb.data_[:2+rb.cur_size_+uint32(kSlackForEightByteHashingEverywhere)])
|
||||
rb.data_ = nil
|
||||
}
|
||||
|
||||
|
@ -73,12 +69,12 @@ func RingBufferInitBuffer(buflen uint32, rb *RingBuffer) {
|
|||
rb.buffer_ = rb.data_[2:]
|
||||
rb.data_[1] = 0
|
||||
rb.data_[0] = rb.data_[1]
|
||||
for i = 0; i < RingBufferInitBuffer_kSlackForEightByteHashingEverywhere; i++ {
|
||||
for i = 0; i < kSlackForEightByteHashingEverywhere; i++ {
|
||||
rb.buffer_[rb.cur_size_+uint32(i)] = 0
|
||||
}
|
||||
}
|
||||
|
||||
func RingBufferWriteTail(bytes []byte, n uint, rb *RingBuffer) {
|
||||
func ringBufferWriteTail(bytes []byte, n uint, rb *ringBuffer) {
|
||||
var masked_pos uint = uint(rb.pos_ & rb.mask_)
|
||||
if uint32(masked_pos) < rb.tail_size_ {
|
||||
/* Just fill the tail buffer with the beginning data. */
|
||||
|
@ -88,7 +84,7 @@ func RingBufferWriteTail(bytes []byte, n uint, rb *RingBuffer) {
|
|||
}
|
||||
|
||||
/* Push bytes into the ring buffer. */
|
||||
func RingBufferWrite(bytes []byte, n uint, rb *RingBuffer) {
|
||||
func ringBufferWrite(bytes []byte, n uint, rb *ringBuffer) {
|
||||
if rb.pos_ == 0 && uint32(n) < rb.tail_size_ {
|
||||
/* Special case for the first write: to process the first block, we don't
|
||||
need to allocate the whole ring-buffer and we don't need the tail
|
||||
|
@ -98,14 +94,14 @@ func RingBufferWrite(bytes []byte, n uint, rb *RingBuffer) {
|
|||
will need to reallocate to the full size anyway. */
|
||||
rb.pos_ = uint32(n)
|
||||
|
||||
RingBufferInitBuffer(rb.pos_, rb)
|
||||
ringBufferInitBuffer(rb.pos_, rb)
|
||||
copy(rb.buffer_, bytes[:n])
|
||||
return
|
||||
}
|
||||
|
||||
if rb.cur_size_ < rb.total_size_ {
|
||||
/* Lazily allocate the full buffer. */
|
||||
RingBufferInitBuffer(rb.total_size_, rb)
|
||||
ringBufferInitBuffer(rb.total_size_, rb)
|
||||
|
||||
/* Initialize the last two bytes to zero, so that we don't have to worry
|
||||
later when we copy the last two bytes to the first two positions. */
|
||||
|
@ -118,7 +114,7 @@ func RingBufferWrite(bytes []byte, n uint, rb *RingBuffer) {
|
|||
|
||||
/* The length of the writes is limited so that we do not need to worry
|
||||
about a write */
|
||||
RingBufferWriteTail(bytes, n, rb)
|
||||
ringBufferWriteTail(bytes, n, rb)
|
||||
|
||||
if uint32(masked_pos+n) <= rb.size_ {
|
||||
/* A single write fits. */
|
||||
|
|
148
state.go
148
state.go
|
@ -2,11 +2,6 @@ package brotli
|
|||
|
||||
import "io"
|
||||
|
||||
/* Copyright 2015 Google Inc. All Rights Reserved.
|
||||
|
||||
Distributed under MIT license.
|
||||
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
||||
*/
|
||||
/* Copyright 2015 Google Inc. All Rights Reserved.
|
||||
|
||||
Distributed under MIT license.
|
||||
|
@ -15,80 +10,80 @@ import "io"
|
|||
|
||||
/* Brotli state for partial streaming decoding. */
|
||||
const (
|
||||
BROTLI_STATE_UNINITED = iota
|
||||
BROTLI_STATE_LARGE_WINDOW_BITS
|
||||
BROTLI_STATE_INITIALIZE
|
||||
BROTLI_STATE_METABLOCK_BEGIN
|
||||
BROTLI_STATE_METABLOCK_HEADER
|
||||
BROTLI_STATE_METABLOCK_HEADER_2
|
||||
BROTLI_STATE_CONTEXT_MODES
|
||||
BROTLI_STATE_COMMAND_BEGIN
|
||||
BROTLI_STATE_COMMAND_INNER
|
||||
BROTLI_STATE_COMMAND_POST_DECODE_LITERALS
|
||||
BROTLI_STATE_COMMAND_POST_WRAP_COPY
|
||||
BROTLI_STATE_UNCOMPRESSED
|
||||
BROTLI_STATE_METADATA
|
||||
BROTLI_STATE_COMMAND_INNER_WRITE
|
||||
BROTLI_STATE_METABLOCK_DONE
|
||||
BROTLI_STATE_COMMAND_POST_WRITE_1
|
||||
BROTLI_STATE_COMMAND_POST_WRITE_2
|
||||
BROTLI_STATE_HUFFMAN_CODE_0
|
||||
BROTLI_STATE_HUFFMAN_CODE_1
|
||||
BROTLI_STATE_HUFFMAN_CODE_2
|
||||
BROTLI_STATE_HUFFMAN_CODE_3
|
||||
BROTLI_STATE_CONTEXT_MAP_1
|
||||
BROTLI_STATE_CONTEXT_MAP_2
|
||||
BROTLI_STATE_TREE_GROUP
|
||||
BROTLI_STATE_DONE
|
||||
stateUninited = iota
|
||||
stateLargeWindowBits
|
||||
stateInitialize
|
||||
stateMetablockBegin
|
||||
stateMetablockHeader
|
||||
stateMetablockHeader2
|
||||
stateContextModes
|
||||
stateCommandBegin
|
||||
stateCommandInner
|
||||
stateCommandPostDecodeLiterals
|
||||
stateCommandPostWrapCopy
|
||||
stateUncompressed
|
||||
stateMetadata
|
||||
stateCommandInnerWrite
|
||||
stateMetablockDone
|
||||
stateCommandPostWrite1
|
||||
stateCommandPostWrite2
|
||||
stateHuffmanCode0
|
||||
stateHuffmanCode1
|
||||
stateHuffmanCode2
|
||||
stateHuffmanCode3
|
||||
stateContextMap1
|
||||
stateContextMap2
|
||||
stateTreeGroup
|
||||
stateDone
|
||||
)
|
||||
|
||||
const (
|
||||
BROTLI_STATE_METABLOCK_HEADER_NONE = iota
|
||||
BROTLI_STATE_METABLOCK_HEADER_EMPTY
|
||||
BROTLI_STATE_METABLOCK_HEADER_NIBBLES
|
||||
BROTLI_STATE_METABLOCK_HEADER_SIZE
|
||||
BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED
|
||||
BROTLI_STATE_METABLOCK_HEADER_RESERVED
|
||||
BROTLI_STATE_METABLOCK_HEADER_BYTES
|
||||
BROTLI_STATE_METABLOCK_HEADER_METADATA
|
||||
stateMetablockHeaderNone = iota
|
||||
stateMetablockHeaderEmpty
|
||||
stateMetablockHeaderNibbles
|
||||
stateMetablockHeaderSize
|
||||
stateMetablockHeaderUncompressed
|
||||
stateMetablockHeaderReserved
|
||||
stateMetablockHeaderBytes
|
||||
stateMetablockHeaderMetadata
|
||||
)
|
||||
|
||||
const (
|
||||
BROTLI_STATE_UNCOMPRESSED_NONE = iota
|
||||
BROTLI_STATE_UNCOMPRESSED_WRITE
|
||||
stateUncompressedNone = iota
|
||||
stateUncompressedWrite
|
||||
)
|
||||
|
||||
const (
|
||||
BROTLI_STATE_TREE_GROUP_NONE = iota
|
||||
BROTLI_STATE_TREE_GROUP_LOOP
|
||||
stateTreeGroupNone = iota
|
||||
stateTreeGroupLoop
|
||||
)
|
||||
|
||||
const (
|
||||
BROTLI_STATE_CONTEXT_MAP_NONE = iota
|
||||
BROTLI_STATE_CONTEXT_MAP_READ_PREFIX
|
||||
BROTLI_STATE_CONTEXT_MAP_HUFFMAN
|
||||
BROTLI_STATE_CONTEXT_MAP_DECODE
|
||||
BROTLI_STATE_CONTEXT_MAP_TRANSFORM
|
||||
stateContextMapNone = iota
|
||||
stateContextMapReadPrefix
|
||||
stateContextMapHuffman
|
||||
stateContextMapDecode
|
||||
stateContextMapTransform
|
||||
)
|
||||
|
||||
const (
|
||||
BROTLI_STATE_HUFFMAN_NONE = iota
|
||||
BROTLI_STATE_HUFFMAN_SIMPLE_SIZE
|
||||
BROTLI_STATE_HUFFMAN_SIMPLE_READ
|
||||
BROTLI_STATE_HUFFMAN_SIMPLE_BUILD
|
||||
BROTLI_STATE_HUFFMAN_COMPLEX
|
||||
BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS
|
||||
stateHuffmanNone = iota
|
||||
stateHuffmanSimpleSize
|
||||
stateHuffmanSimpleRead
|
||||
stateHuffmanSimpleBuild
|
||||
stateHuffmanComplex
|
||||
stateHuffmanLengthSymbols
|
||||
)
|
||||
|
||||
const (
|
||||
BROTLI_STATE_DECODE_UINT8_NONE = iota
|
||||
BROTLI_STATE_DECODE_UINT8_SHORT
|
||||
BROTLI_STATE_DECODE_UINT8_LONG
|
||||
stateDecodeUint8None = iota
|
||||
stateDecodeUint8Short
|
||||
stateDecodeUint8Long
|
||||
)
|
||||
|
||||
const (
|
||||
BROTLI_STATE_READ_BLOCK_LENGTH_NONE = iota
|
||||
BROTLI_STATE_READ_BLOCK_LENGTH_SUFFIX
|
||||
stateReadBlockLengthNone = iota
|
||||
stateReadBlockLengthSuffix
|
||||
)
|
||||
|
||||
type Reader struct {
|
||||
|
@ -148,7 +143,7 @@ type Reader struct {
|
|||
repeat uint32
|
||||
space uint32
|
||||
table [32]huffmanCode
|
||||
symbol_lists SymbolList
|
||||
symbol_lists symbolList
|
||||
symbols_lists_array [huffmanMaxCodeLength + 1 + numCommandSymbols]uint16
|
||||
next_symbol [32]int
|
||||
code_length_code_lengths [codeLengthCodes]byte
|
||||
|
@ -179,23 +174,23 @@ type Reader struct {
|
|||
context_map []byte
|
||||
context_modes []byte
|
||||
dictionary *dictionary
|
||||
transforms *BrotliTransforms
|
||||
transforms *transforms
|
||||
trivial_literal_contexts [8]uint32
|
||||
}
|
||||
|
||||
func BrotliDecoderStateInit(s *Reader) bool {
|
||||
func decoderStateInit(s *Reader) bool {
|
||||
s.error_code = 0 /* BROTLI_DECODER_NO_ERROR */
|
||||
|
||||
initBitReader(&s.br)
|
||||
s.state = BROTLI_STATE_UNINITED
|
||||
s.state = stateUninited
|
||||
s.large_window = false
|
||||
s.substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NONE
|
||||
s.substate_tree_group = BROTLI_STATE_TREE_GROUP_NONE
|
||||
s.substate_context_map = BROTLI_STATE_CONTEXT_MAP_NONE
|
||||
s.substate_uncompressed = BROTLI_STATE_UNCOMPRESSED_NONE
|
||||
s.substate_huffman = BROTLI_STATE_HUFFMAN_NONE
|
||||
s.substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_NONE
|
||||
s.substate_read_block_length = BROTLI_STATE_READ_BLOCK_LENGTH_NONE
|
||||
s.substate_metablock_header = stateMetablockHeaderNone
|
||||
s.substate_tree_group = stateTreeGroupNone
|
||||
s.substate_context_map = stateContextMapNone
|
||||
s.substate_uncompressed = stateUncompressedNone
|
||||
s.substate_huffman = stateHuffmanNone
|
||||
s.substate_decode_uint8 = stateDecodeUint8None
|
||||
s.substate_read_block_length = stateReadBlockLengthNone
|
||||
|
||||
s.buffer_length = 0
|
||||
s.loop_counter = 0
|
||||
|
@ -245,12 +240,12 @@ func BrotliDecoderStateInit(s *Reader) bool {
|
|||
s.symbol_lists.offset = huffmanMaxCodeLength + 1
|
||||
|
||||
s.dictionary = getDictionary()
|
||||
s.transforms = BrotliGetTransforms()
|
||||
s.transforms = getTransforms()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func BrotliDecoderStateMetablockBegin(s *Reader) {
|
||||
func decoderStateMetablockBegin(s *Reader) {
|
||||
s.meta_block_remaining_len = 0
|
||||
s.block_length[0] = 1 << 24
|
||||
s.block_length[1] = 1 << 24
|
||||
|
@ -280,7 +275,7 @@ func BrotliDecoderStateMetablockBegin(s *Reader) {
|
|||
s.distance_hgroup.htrees = nil
|
||||
}
|
||||
|
||||
func BrotliDecoderStateCleanupAfterMetablock(s *Reader) {
|
||||
func decoderStateCleanupAfterMetablock(s *Reader) {
|
||||
s.context_modes = nil
|
||||
s.context_map = nil
|
||||
s.dist_context_map = nil
|
||||
|
@ -289,14 +284,7 @@ func BrotliDecoderStateCleanupAfterMetablock(s *Reader) {
|
|||
s.distance_hgroup.htrees = nil
|
||||
}
|
||||
|
||||
func BrotliDecoderStateCleanup(s *Reader) {
|
||||
BrotliDecoderStateCleanupAfterMetablock(s)
|
||||
|
||||
s.ringbuffer = nil
|
||||
s.block_type_trees = nil
|
||||
}
|
||||
|
||||
func BrotliDecoderHuffmanTreeGroupInit(s *Reader, group *huffmanTreeGroup, alphabet_size uint32, max_symbol uint32, ntrees uint32) bool {
|
||||
func decoderHuffmanTreeGroupInit(s *Reader, group *huffmanTreeGroup, alphabet_size uint32, max_symbol uint32, ntrees uint32) bool {
|
||||
var max_table_size uint = uint(kMaxHuffmanTableSize[(alphabet_size+31)>>5])
|
||||
group.alphabet_size = uint16(alphabet_size)
|
||||
group.max_symbol = uint16(max_symbol)
|
||||
|
|
206
static_dict.go
206
static_dict.go
|
@ -9,7 +9,7 @@ import "encoding/binary"
|
|||
*/
|
||||
|
||||
/* Class to model the static dictionary. */
|
||||
const BROTLI_MAX_STATIC_DICTIONARY_MATCH_LEN = 37
|
||||
const maxStaticDictionaryMatchLen = 37
|
||||
|
||||
var kInvalidMatch uint32 = 0xFFFFFFF
|
||||
|
||||
|
@ -18,7 +18,7 @@ var kInvalidMatch uint32 = 0xFFFFFFF
|
|||
Distributed under MIT license.
|
||||
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
||||
*/
|
||||
func Hash(data []byte) uint32 {
|
||||
func hash(data []byte) uint32 {
|
||||
var h uint32 = binary.LittleEndian.Uint32(data) * kDictHashMul32
|
||||
|
||||
/* The higher bits contain more mixture from the multiplication,
|
||||
|
@ -26,17 +26,17 @@ func Hash(data []byte) uint32 {
|
|||
return h >> uint(32-kDictNumBits)
|
||||
}
|
||||
|
||||
func AddMatch(distance uint, len uint, len_code uint, matches []uint32) {
|
||||
func addMatch(distance uint, len uint, len_code uint, matches []uint32) {
|
||||
var match uint32 = uint32((distance << 5) + len_code)
|
||||
matches[len] = brotli_min_uint32_t(matches[len], match)
|
||||
}
|
||||
|
||||
func DictMatchLength(dict *dictionary, data []byte, id uint, len uint, maxlen uint) uint {
|
||||
func dictMatchLength(dict *dictionary, data []byte, id uint, len uint, maxlen uint) uint {
|
||||
var offset uint = uint(dict.offsets_by_length[len]) + len*id
|
||||
return findMatchLengthWithLimit(dict.data[offset:], data, brotli_min_size_t(uint(len), maxlen))
|
||||
}
|
||||
|
||||
func IsMatch(d *dictionary, w DictWord, data []byte, max_length uint) bool {
|
||||
func isMatch(d *dictionary, w dictWord, data []byte, max_length uint) bool {
|
||||
if uint(w.len) > max_length {
|
||||
return false
|
||||
} else {
|
||||
|
@ -70,13 +70,13 @@ func IsMatch(d *dictionary, w DictWord, data []byte, max_length uint) bool {
|
|||
}
|
||||
}
|
||||
|
||||
func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte, min_length uint, max_length uint, matches []uint32) bool {
|
||||
func findAllStaticDictionaryMatches(dict *encoderDictionary, data []byte, min_length uint, max_length uint, matches []uint32) bool {
|
||||
var has_found_match bool = false
|
||||
{
|
||||
var offset uint = uint(dict.buckets[Hash(data)])
|
||||
var offset uint = uint(dict.buckets[hash(data)])
|
||||
var end bool = offset == 0
|
||||
for !end {
|
||||
var w DictWord
|
||||
var w dictWord
|
||||
w = dict.dict_words[offset]
|
||||
offset++
|
||||
var l uint = uint(w.len) & 0x1F
|
||||
|
@ -85,7 +85,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
end = !(w.len&0x80 == 0)
|
||||
w.len = byte(l)
|
||||
if w.transform == 0 {
|
||||
var matchlen uint = DictMatchLength(dict.words, data, id, l, max_length)
|
||||
var matchlen uint = dictMatchLength(dict.words, data, id, l, max_length)
|
||||
var s []byte
|
||||
var minlen uint
|
||||
var maxlen uint
|
||||
|
@ -93,16 +93,16 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
|
||||
/* Transform "" + BROTLI_TRANSFORM_IDENTITY + "" */
|
||||
if matchlen == l {
|
||||
AddMatch(id, l, l, matches)
|
||||
addMatch(id, l, l, matches)
|
||||
has_found_match = true
|
||||
}
|
||||
|
||||
/* Transforms "" + BROTLI_TRANSFORM_OMIT_LAST_1 + "" and
|
||||
"" + BROTLI_TRANSFORM_OMIT_LAST_1 + "ing " */
|
||||
if matchlen >= l-1 {
|
||||
AddMatch(id+12*n, l-1, l, matches)
|
||||
addMatch(id+12*n, l-1, l, matches)
|
||||
if l+2 < max_length && data[l-1] == 'i' && data[l] == 'n' && data[l+1] == 'g' && data[l+2] == ' ' {
|
||||
AddMatch(id+49*n, l+3, l, matches)
|
||||
addMatch(id+49*n, l+3, l, matches)
|
||||
}
|
||||
|
||||
has_found_match = true
|
||||
|
@ -118,7 +118,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
for len = minlen; len <= maxlen; len++ {
|
||||
var cut uint = l - len
|
||||
var transform_id uint = (cut << 2) + uint((dict.cutoffTransforms>>(cut*6))&0x3F)
|
||||
AddMatch(id+transform_id*n, uint(len), l, matches)
|
||||
addMatch(id+transform_id*n, uint(len), l, matches)
|
||||
has_found_match = true
|
||||
}
|
||||
|
||||
|
@ -130,182 +130,182 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
|
||||
/* Transforms "" + BROTLI_TRANSFORM_IDENTITY + <suffix> */
|
||||
if s[0] == ' ' {
|
||||
AddMatch(id+n, l+1, l, matches)
|
||||
addMatch(id+n, l+1, l, matches)
|
||||
if s[1] == 'a' {
|
||||
if s[2] == ' ' {
|
||||
AddMatch(id+28*n, l+3, l, matches)
|
||||
addMatch(id+28*n, l+3, l, matches)
|
||||
} else if s[2] == 's' {
|
||||
if s[3] == ' ' {
|
||||
AddMatch(id+46*n, l+4, l, matches)
|
||||
addMatch(id+46*n, l+4, l, matches)
|
||||
}
|
||||
} else if s[2] == 't' {
|
||||
if s[3] == ' ' {
|
||||
AddMatch(id+60*n, l+4, l, matches)
|
||||
addMatch(id+60*n, l+4, l, matches)
|
||||
}
|
||||
} else if s[2] == 'n' {
|
||||
if s[3] == 'd' && s[4] == ' ' {
|
||||
AddMatch(id+10*n, l+5, l, matches)
|
||||
addMatch(id+10*n, l+5, l, matches)
|
||||
}
|
||||
}
|
||||
} else if s[1] == 'b' {
|
||||
if s[2] == 'y' && s[3] == ' ' {
|
||||
AddMatch(id+38*n, l+4, l, matches)
|
||||
addMatch(id+38*n, l+4, l, matches)
|
||||
}
|
||||
} else if s[1] == 'i' {
|
||||
if s[2] == 'n' {
|
||||
if s[3] == ' ' {
|
||||
AddMatch(id+16*n, l+4, l, matches)
|
||||
addMatch(id+16*n, l+4, l, matches)
|
||||
}
|
||||
} else if s[2] == 's' {
|
||||
if s[3] == ' ' {
|
||||
AddMatch(id+47*n, l+4, l, matches)
|
||||
addMatch(id+47*n, l+4, l, matches)
|
||||
}
|
||||
}
|
||||
} else if s[1] == 'f' {
|
||||
if s[2] == 'o' {
|
||||
if s[3] == 'r' && s[4] == ' ' {
|
||||
AddMatch(id+25*n, l+5, l, matches)
|
||||
addMatch(id+25*n, l+5, l, matches)
|
||||
}
|
||||
} else if s[2] == 'r' {
|
||||
if s[3] == 'o' && s[4] == 'm' && s[5] == ' ' {
|
||||
AddMatch(id+37*n, l+6, l, matches)
|
||||
addMatch(id+37*n, l+6, l, matches)
|
||||
}
|
||||
}
|
||||
} else if s[1] == 'o' {
|
||||
if s[2] == 'f' {
|
||||
if s[3] == ' ' {
|
||||
AddMatch(id+8*n, l+4, l, matches)
|
||||
addMatch(id+8*n, l+4, l, matches)
|
||||
}
|
||||
} else if s[2] == 'n' {
|
||||
if s[3] == ' ' {
|
||||
AddMatch(id+45*n, l+4, l, matches)
|
||||
addMatch(id+45*n, l+4, l, matches)
|
||||
}
|
||||
}
|
||||
} else if s[1] == 'n' {
|
||||
if s[2] == 'o' && s[3] == 't' && s[4] == ' ' {
|
||||
AddMatch(id+80*n, l+5, l, matches)
|
||||
addMatch(id+80*n, l+5, l, matches)
|
||||
}
|
||||
} else if s[1] == 't' {
|
||||
if s[2] == 'h' {
|
||||
if s[3] == 'e' {
|
||||
if s[4] == ' ' {
|
||||
AddMatch(id+5*n, l+5, l, matches)
|
||||
addMatch(id+5*n, l+5, l, matches)
|
||||
}
|
||||
} else if s[3] == 'a' {
|
||||
if s[4] == 't' && s[5] == ' ' {
|
||||
AddMatch(id+29*n, l+6, l, matches)
|
||||
addMatch(id+29*n, l+6, l, matches)
|
||||
}
|
||||
}
|
||||
} else if s[2] == 'o' {
|
||||
if s[3] == ' ' {
|
||||
AddMatch(id+17*n, l+4, l, matches)
|
||||
addMatch(id+17*n, l+4, l, matches)
|
||||
}
|
||||
}
|
||||
} else if s[1] == 'w' {
|
||||
if s[2] == 'i' && s[3] == 't' && s[4] == 'h' && s[5] == ' ' {
|
||||
AddMatch(id+35*n, l+6, l, matches)
|
||||
addMatch(id+35*n, l+6, l, matches)
|
||||
}
|
||||
}
|
||||
} else if s[0] == '"' {
|
||||
AddMatch(id+19*n, l+1, l, matches)
|
||||
addMatch(id+19*n, l+1, l, matches)
|
||||
if s[1] == '>' {
|
||||
AddMatch(id+21*n, l+2, l, matches)
|
||||
addMatch(id+21*n, l+2, l, matches)
|
||||
}
|
||||
} else if s[0] == '.' {
|
||||
AddMatch(id+20*n, l+1, l, matches)
|
||||
addMatch(id+20*n, l+1, l, matches)
|
||||
if s[1] == ' ' {
|
||||
AddMatch(id+31*n, l+2, l, matches)
|
||||
addMatch(id+31*n, l+2, l, matches)
|
||||
if s[2] == 'T' && s[3] == 'h' {
|
||||
if s[4] == 'e' {
|
||||
if s[5] == ' ' {
|
||||
AddMatch(id+43*n, l+6, l, matches)
|
||||
addMatch(id+43*n, l+6, l, matches)
|
||||
}
|
||||
} else if s[4] == 'i' {
|
||||
if s[5] == 's' && s[6] == ' ' {
|
||||
AddMatch(id+75*n, l+7, l, matches)
|
||||
addMatch(id+75*n, l+7, l, matches)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if s[0] == ',' {
|
||||
AddMatch(id+76*n, l+1, l, matches)
|
||||
addMatch(id+76*n, l+1, l, matches)
|
||||
if s[1] == ' ' {
|
||||
AddMatch(id+14*n, l+2, l, matches)
|
||||
addMatch(id+14*n, l+2, l, matches)
|
||||
}
|
||||
} else if s[0] == '\n' {
|
||||
AddMatch(id+22*n, l+1, l, matches)
|
||||
addMatch(id+22*n, l+1, l, matches)
|
||||
if s[1] == '\t' {
|
||||
AddMatch(id+50*n, l+2, l, matches)
|
||||
addMatch(id+50*n, l+2, l, matches)
|
||||
}
|
||||
} else if s[0] == ']' {
|
||||
AddMatch(id+24*n, l+1, l, matches)
|
||||
addMatch(id+24*n, l+1, l, matches)
|
||||
} else if s[0] == '\'' {
|
||||
AddMatch(id+36*n, l+1, l, matches)
|
||||
addMatch(id+36*n, l+1, l, matches)
|
||||
} else if s[0] == ':' {
|
||||
AddMatch(id+51*n, l+1, l, matches)
|
||||
addMatch(id+51*n, l+1, l, matches)
|
||||
} else if s[0] == '(' {
|
||||
AddMatch(id+57*n, l+1, l, matches)
|
||||
addMatch(id+57*n, l+1, l, matches)
|
||||
} else if s[0] == '=' {
|
||||
if s[1] == '"' {
|
||||
AddMatch(id+70*n, l+2, l, matches)
|
||||
addMatch(id+70*n, l+2, l, matches)
|
||||
} else if s[1] == '\'' {
|
||||
AddMatch(id+86*n, l+2, l, matches)
|
||||
addMatch(id+86*n, l+2, l, matches)
|
||||
}
|
||||
} else if s[0] == 'a' {
|
||||
if s[1] == 'l' && s[2] == ' ' {
|
||||
AddMatch(id+84*n, l+3, l, matches)
|
||||
addMatch(id+84*n, l+3, l, matches)
|
||||
}
|
||||
} else if s[0] == 'e' {
|
||||
if s[1] == 'd' {
|
||||
if s[2] == ' ' {
|
||||
AddMatch(id+53*n, l+3, l, matches)
|
||||
addMatch(id+53*n, l+3, l, matches)
|
||||
}
|
||||
} else if s[1] == 'r' {
|
||||
if s[2] == ' ' {
|
||||
AddMatch(id+82*n, l+3, l, matches)
|
||||
addMatch(id+82*n, l+3, l, matches)
|
||||
}
|
||||
} else if s[1] == 's' {
|
||||
if s[2] == 't' && s[3] == ' ' {
|
||||
AddMatch(id+95*n, l+4, l, matches)
|
||||
addMatch(id+95*n, l+4, l, matches)
|
||||
}
|
||||
}
|
||||
} else if s[0] == 'f' {
|
||||
if s[1] == 'u' && s[2] == 'l' && s[3] == ' ' {
|
||||
AddMatch(id+90*n, l+4, l, matches)
|
||||
addMatch(id+90*n, l+4, l, matches)
|
||||
}
|
||||
} else if s[0] == 'i' {
|
||||
if s[1] == 'v' {
|
||||
if s[2] == 'e' && s[3] == ' ' {
|
||||
AddMatch(id+92*n, l+4, l, matches)
|
||||
addMatch(id+92*n, l+4, l, matches)
|
||||
}
|
||||
} else if s[1] == 'z' {
|
||||
if s[2] == 'e' && s[3] == ' ' {
|
||||
AddMatch(id+100*n, l+4, l, matches)
|
||||
addMatch(id+100*n, l+4, l, matches)
|
||||
}
|
||||
}
|
||||
} else if s[0] == 'l' {
|
||||
if s[1] == 'e' {
|
||||
if s[2] == 's' && s[3] == 's' && s[4] == ' ' {
|
||||
AddMatch(id+93*n, l+5, l, matches)
|
||||
addMatch(id+93*n, l+5, l, matches)
|
||||
}
|
||||
} else if s[1] == 'y' {
|
||||
if s[2] == ' ' {
|
||||
AddMatch(id+61*n, l+3, l, matches)
|
||||
addMatch(id+61*n, l+3, l, matches)
|
||||
}
|
||||
}
|
||||
} else if s[0] == 'o' {
|
||||
if s[1] == 'u' && s[2] == 's' && s[3] == ' ' {
|
||||
AddMatch(id+106*n, l+4, l, matches)
|
||||
addMatch(id+106*n, l+4, l, matches)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var is_all_caps bool = (w.transform != BROTLI_TRANSFORM_UPPERCASE_FIRST)
|
||||
var is_all_caps bool = (w.transform != transformUppercaseFirst)
|
||||
/* Set is_all_caps=0 for BROTLI_TRANSFORM_UPPERCASE_FIRST and
|
||||
is_all_caps=1 otherwise (BROTLI_TRANSFORM_UPPERCASE_ALL)
|
||||
transform. */
|
||||
|
||||
var s []byte
|
||||
if !IsMatch(dict.words, w, data, max_length) {
|
||||
if !isMatch(dict.words, w, data, max_length) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -316,7 +316,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 9
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l, l, matches)
|
||||
|
||||
has_found_match = true
|
||||
if l+1 >= max_length {
|
||||
|
@ -333,7 +333,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 4
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+1, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+1, l, matches)
|
||||
} else if s[0] == '"' {
|
||||
var tmp int
|
||||
if is_all_caps {
|
||||
|
@ -341,7 +341,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 66
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+1, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+1, l, matches)
|
||||
if s[1] == '>' {
|
||||
var tmp int
|
||||
if is_all_caps {
|
||||
|
@ -349,7 +349,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 69
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+2, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+2, l, matches)
|
||||
}
|
||||
} else if s[0] == '.' {
|
||||
var tmp int
|
||||
|
@ -358,7 +358,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 79
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+1, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+1, l, matches)
|
||||
if s[1] == ' ' {
|
||||
var tmp int
|
||||
if is_all_caps {
|
||||
|
@ -366,7 +366,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 88
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+2, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+2, l, matches)
|
||||
}
|
||||
} else if s[0] == ',' {
|
||||
var tmp int
|
||||
|
@ -375,7 +375,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 99
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+1, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+1, l, matches)
|
||||
if s[1] == ' ' {
|
||||
var tmp int
|
||||
if is_all_caps {
|
||||
|
@ -383,7 +383,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 58
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+2, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+2, l, matches)
|
||||
}
|
||||
} else if s[0] == '\'' {
|
||||
var tmp int
|
||||
|
@ -392,7 +392,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 74
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+1, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+1, l, matches)
|
||||
} else if s[0] == '(' {
|
||||
var tmp int
|
||||
if is_all_caps {
|
||||
|
@ -400,7 +400,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 78
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+1, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+1, l, matches)
|
||||
} else if s[0] == '=' {
|
||||
if s[1] == '"' {
|
||||
var tmp int
|
||||
|
@ -409,7 +409,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 104
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+2, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+2, l, matches)
|
||||
} else if s[1] == '\'' {
|
||||
var tmp int
|
||||
if is_all_caps {
|
||||
|
@ -417,7 +417,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 108
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+2, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+2, l, matches)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -427,10 +427,10 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
/* Transforms with prefixes " " and "." */
|
||||
if max_length >= 5 && (data[0] == ' ' || data[0] == '.') {
|
||||
var is_space bool = (data[0] == ' ')
|
||||
var offset uint = uint(dict.buckets[Hash(data[1:])])
|
||||
var offset uint = uint(dict.buckets[hash(data[1:])])
|
||||
var end bool = offset == 0
|
||||
for !end {
|
||||
var w DictWord
|
||||
var w dictWord
|
||||
w = dict.dict_words[offset]
|
||||
offset++
|
||||
var l uint = uint(w.len) & 0x1F
|
||||
|
@ -440,7 +440,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
w.len = byte(l)
|
||||
if w.transform == 0 {
|
||||
var s []byte
|
||||
if !IsMatch(dict.words, w, data[1:], max_length-1) {
|
||||
if !isMatch(dict.words, w, data[1:], max_length-1) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -452,7 +452,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 32
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+1, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+1, l, matches)
|
||||
|
||||
has_found_match = true
|
||||
if l+2 >= max_length {
|
||||
|
@ -471,7 +471,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 77
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+2, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+2, l, matches)
|
||||
} else if s[0] == '(' {
|
||||
var tmp int
|
||||
if is_space {
|
||||
|
@ -479,34 +479,34 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 67
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+2, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+2, l, matches)
|
||||
} else if is_space {
|
||||
if s[0] == ',' {
|
||||
AddMatch(id+103*n, l+2, l, matches)
|
||||
addMatch(id+103*n, l+2, l, matches)
|
||||
if s[1] == ' ' {
|
||||
AddMatch(id+33*n, l+3, l, matches)
|
||||
addMatch(id+33*n, l+3, l, matches)
|
||||
}
|
||||
} else if s[0] == '.' {
|
||||
AddMatch(id+71*n, l+2, l, matches)
|
||||
addMatch(id+71*n, l+2, l, matches)
|
||||
if s[1] == ' ' {
|
||||
AddMatch(id+52*n, l+3, l, matches)
|
||||
addMatch(id+52*n, l+3, l, matches)
|
||||
}
|
||||
} else if s[0] == '=' {
|
||||
if s[1] == '"' {
|
||||
AddMatch(id+81*n, l+3, l, matches)
|
||||
addMatch(id+81*n, l+3, l, matches)
|
||||
} else if s[1] == '\'' {
|
||||
AddMatch(id+98*n, l+3, l, matches)
|
||||
addMatch(id+98*n, l+3, l, matches)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if is_space {
|
||||
var is_all_caps bool = (w.transform != BROTLI_TRANSFORM_UPPERCASE_FIRST)
|
||||
var is_all_caps bool = (w.transform != transformUppercaseFirst)
|
||||
/* Set is_all_caps=0 for BROTLI_TRANSFORM_UPPERCASE_FIRST and
|
||||
is_all_caps=1 otherwise (BROTLI_TRANSFORM_UPPERCASE_ALL)
|
||||
transform. */
|
||||
|
||||
var s []byte
|
||||
if !IsMatch(dict.words, w, data[1:], max_length-1) {
|
||||
if !isMatch(dict.words, w, data[1:], max_length-1) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -517,7 +517,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 30
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+1, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+1, l, matches)
|
||||
|
||||
has_found_match = true
|
||||
if l+2 >= max_length {
|
||||
|
@ -534,10 +534,10 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 15
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+2, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+2, l, matches)
|
||||
} else if s[0] == ',' {
|
||||
if !is_all_caps {
|
||||
AddMatch(id+109*n, l+2, l, matches)
|
||||
addMatch(id+109*n, l+2, l, matches)
|
||||
}
|
||||
|
||||
if s[1] == ' ' {
|
||||
|
@ -547,7 +547,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 65
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+3, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+3, l, matches)
|
||||
}
|
||||
} else if s[0] == '.' {
|
||||
var tmp int
|
||||
|
@ -556,7 +556,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 96
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+2, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+2, l, matches)
|
||||
if s[1] == ' ' {
|
||||
var tmp int
|
||||
if is_all_caps {
|
||||
|
@ -564,7 +564,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 91
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+3, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+3, l, matches)
|
||||
}
|
||||
} else if s[0] == '=' {
|
||||
if s[1] == '"' {
|
||||
|
@ -574,7 +574,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 118
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+3, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+3, l, matches)
|
||||
} else if s[1] == '\'' {
|
||||
var tmp int
|
||||
if is_all_caps {
|
||||
|
@ -582,7 +582,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else {
|
||||
tmp = 120
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+3, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+3, l, matches)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -592,10 +592,10 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
if max_length >= 6 {
|
||||
/* Transforms with prefixes "e ", "s ", ", " and "\xC2\xA0" */
|
||||
if (data[1] == ' ' && (data[0] == 'e' || data[0] == 's' || data[0] == ',')) || (data[0] == 0xC2 && data[1] == 0xA0) {
|
||||
var offset uint = uint(dict.buckets[Hash(data[2:])])
|
||||
var offset uint = uint(dict.buckets[hash(data[2:])])
|
||||
var end bool = offset == 0
|
||||
for !end {
|
||||
var w DictWord
|
||||
var w dictWord
|
||||
w = dict.dict_words[offset]
|
||||
offset++
|
||||
var l uint = uint(w.len) & 0x1F
|
||||
|
@ -603,9 +603,9 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
var id uint = uint(w.idx)
|
||||
end = !(w.len&0x80 == 0)
|
||||
w.len = byte(l)
|
||||
if w.transform == 0 && IsMatch(dict.words, w, data[2:], max_length-2) {
|
||||
if w.transform == 0 && isMatch(dict.words, w, data[2:], max_length-2) {
|
||||
if data[0] == 0xC2 {
|
||||
AddMatch(id+102*n, l+2, l, matches)
|
||||
addMatch(id+102*n, l+2, l, matches)
|
||||
has_found_match = true
|
||||
} else if l+2 < max_length && data[l+2] == ' ' {
|
||||
var t uint = 13
|
||||
|
@ -614,7 +614,7 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
} else if data[0] == 's' {
|
||||
t = 7
|
||||
}
|
||||
AddMatch(id+t*n, l+3, l, matches)
|
||||
addMatch(id+t*n, l+3, l, matches)
|
||||
has_found_match = true
|
||||
}
|
||||
}
|
||||
|
@ -625,10 +625,10 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
if max_length >= 9 {
|
||||
/* Transforms with prefixes " the " and ".com/" */
|
||||
if (data[0] == ' ' && data[1] == 't' && data[2] == 'h' && data[3] == 'e' && data[4] == ' ') || (data[0] == '.' && data[1] == 'c' && data[2] == 'o' && data[3] == 'm' && data[4] == '/') {
|
||||
var offset uint = uint(dict.buckets[Hash(data[5:])])
|
||||
var offset uint = uint(dict.buckets[hash(data[5:])])
|
||||
var end bool = offset == 0
|
||||
for !end {
|
||||
var w DictWord
|
||||
var w dictWord
|
||||
w = dict.dict_words[offset]
|
||||
offset++
|
||||
var l uint = uint(w.len) & 0x1F
|
||||
|
@ -636,22 +636,22 @@ func BrotliFindAllStaticDictionaryMatches(dict *encoderDictionary, data []byte,
|
|||
var id uint = uint(w.idx)
|
||||
end = !(w.len&0x80 == 0)
|
||||
w.len = byte(l)
|
||||
if w.transform == 0 && IsMatch(dict.words, w, data[5:], max_length-5) {
|
||||
if w.transform == 0 && isMatch(dict.words, w, data[5:], max_length-5) {
|
||||
var tmp int
|
||||
if data[0] == ' ' {
|
||||
tmp = 41
|
||||
} else {
|
||||
tmp = 72
|
||||
}
|
||||
AddMatch(id+uint(tmp)*n, l+5, l, matches)
|
||||
addMatch(id+uint(tmp)*n, l+5, l, matches)
|
||||
has_found_match = true
|
||||
if l+5 < max_length {
|
||||
var s []byte = data[l+5:]
|
||||
if data[0] == ' ' {
|
||||
if l+8 < max_length && s[0] == ' ' && s[1] == 'o' && s[2] == 'f' && s[3] == ' ' {
|
||||
AddMatch(id+62*n, l+9, l, matches)
|
||||
addMatch(id+62*n, l+9, l, matches)
|
||||
if l+12 < max_length && s[4] == 't' && s[5] == 'h' && s[6] == 'e' && s[7] == ' ' {
|
||||
AddMatch(id+73*n, l+13, l, matches)
|
||||
addMatch(id+73*n, l+13, l, matches)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
63414
static_dict_lut.go
63414
static_dict_lut.go
File diff suppressed because it is too large
Load Diff
|
@ -7,15 +7,15 @@ package brotli
|
|||
*/
|
||||
|
||||
/* Utilities for building Huffman decoding tables. */
|
||||
type SymbolList struct {
|
||||
type symbolList struct {
|
||||
storage []uint16
|
||||
offset int
|
||||
}
|
||||
|
||||
func SymbolListGet(sl SymbolList, i int) uint16 {
|
||||
func symbolListGet(sl symbolList, i int) uint16 {
|
||||
return sl.storage[i+sl.offset]
|
||||
}
|
||||
|
||||
func SymbolListPut(sl SymbolList, i int, val uint16) {
|
||||
func symbolListPut(sl symbolList, i int, val uint16) {
|
||||
sl.storage[i+sl.offset] = val
|
||||
}
|
||||
|
|
354
transform.go
354
transform.go
|
@ -7,64 +7,64 @@ package brotli
|
|||
aforementioned functions will be available only to brotli internals.
|
||||
*/
|
||||
const (
|
||||
BROTLI_TRANSFORM_IDENTITY = 0
|
||||
BROTLI_TRANSFORM_OMIT_LAST_1 = 1
|
||||
BROTLI_TRANSFORM_OMIT_LAST_2 = 2
|
||||
BROTLI_TRANSFORM_OMIT_LAST_3 = 3
|
||||
BROTLI_TRANSFORM_OMIT_LAST_4 = 4
|
||||
BROTLI_TRANSFORM_OMIT_LAST_5 = 5
|
||||
BROTLI_TRANSFORM_OMIT_LAST_6 = 6
|
||||
BROTLI_TRANSFORM_OMIT_LAST_7 = 7
|
||||
BROTLI_TRANSFORM_OMIT_LAST_8 = 8
|
||||
BROTLI_TRANSFORM_OMIT_LAST_9 = 9
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST = 10
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL = 11
|
||||
BROTLI_TRANSFORM_OMIT_FIRST_1 = 12
|
||||
BROTLI_TRANSFORM_OMIT_FIRST_2 = 13
|
||||
BROTLI_TRANSFORM_OMIT_FIRST_3 = 14
|
||||
BROTLI_TRANSFORM_OMIT_FIRST_4 = 15
|
||||
BROTLI_TRANSFORM_OMIT_FIRST_5 = 16
|
||||
BROTLI_TRANSFORM_OMIT_FIRST_6 = 17
|
||||
BROTLI_TRANSFORM_OMIT_FIRST_7 = 18
|
||||
BROTLI_TRANSFORM_OMIT_FIRST_8 = 19
|
||||
BROTLI_TRANSFORM_OMIT_FIRST_9 = 20
|
||||
BROTLI_TRANSFORM_SHIFT_FIRST = 21
|
||||
BROTLI_TRANSFORM_SHIFT_ALL = 22 + iota - 22
|
||||
BROTLI_NUM_TRANSFORM_TYPES
|
||||
transformIdentity = 0
|
||||
transformOmitLast1 = 1
|
||||
transformOmitLast2 = 2
|
||||
transformOmitLast3 = 3
|
||||
transformOmitLast4 = 4
|
||||
transformOmitLast5 = 5
|
||||
transformOmitLast6 = 6
|
||||
transformOmitLast7 = 7
|
||||
transformOmitLast8 = 8
|
||||
transformOmitLast9 = 9
|
||||
transformUppercaseFirst = 10
|
||||
transformUppercaseAll = 11
|
||||
transformOmitFirst1 = 12
|
||||
transformOmitFirst2 = 13
|
||||
transformOmitFirst3 = 14
|
||||
transformOmitFirst4 = 15
|
||||
transformOmitFirst5 = 16
|
||||
transformOmitFirst6 = 17
|
||||
transformOmitFirst7 = 18
|
||||
transformOmitFirst8 = 19
|
||||
transformOmitFirst9 = 20
|
||||
transformShiftFirst = 21
|
||||
transformShiftAll = 22 + iota - 22
|
||||
numTransformTypes
|
||||
)
|
||||
|
||||
const BROTLI_TRANSFORMS_MAX_CUT_OFF = BROTLI_TRANSFORM_OMIT_LAST_9
|
||||
const transformsMaxCutOff = transformOmitLast9
|
||||
|
||||
type BrotliTransforms struct {
|
||||
type transforms struct {
|
||||
prefix_suffix_size uint16
|
||||
prefix_suffix []byte
|
||||
prefix_suffix_map []uint16
|
||||
num_transforms uint32
|
||||
transforms []byte
|
||||
params []byte
|
||||
cutOffTransforms [BROTLI_TRANSFORMS_MAX_CUT_OFF + 1]int16
|
||||
cutOffTransforms [transformsMaxCutOff + 1]int16
|
||||
}
|
||||
|
||||
/* T is BrotliTransforms*; result is uint8_t. */
|
||||
func BROTLI_TRANSFORM_PREFIX_ID(t *BrotliTransforms, I int) byte {
|
||||
func transformPrefixId(t *transforms, I int) byte {
|
||||
return t.transforms[(I*3)+0]
|
||||
}
|
||||
|
||||
func BROTLI_TRANSFORM_TYPE(t *BrotliTransforms, I int) byte {
|
||||
func transformType(t *transforms, I int) byte {
|
||||
return t.transforms[(I*3)+1]
|
||||
}
|
||||
|
||||
func BROTLI_TRANSFORM_SUFFIX_ID(t *BrotliTransforms, I int) byte {
|
||||
func transformSuffixId(t *transforms, I int) byte {
|
||||
return t.transforms[(I*3)+2]
|
||||
}
|
||||
|
||||
/* T is BrotliTransforms*; result is const uint8_t*. */
|
||||
func BROTLI_TRANSFORM_PREFIX(t *BrotliTransforms, I int) []byte {
|
||||
return t.prefix_suffix[t.prefix_suffix_map[BROTLI_TRANSFORM_PREFIX_ID(t, I)]:]
|
||||
func transformPrefix(t *transforms, I int) []byte {
|
||||
return t.prefix_suffix[t.prefix_suffix_map[transformPrefixId(t, I)]:]
|
||||
}
|
||||
|
||||
func BROTLI_TRANSFORM_SUFFIX(t *BrotliTransforms, I int) []byte {
|
||||
return t.prefix_suffix[t.prefix_suffix_map[BROTLI_TRANSFORM_SUFFIX_ID(t, I)]:]
|
||||
func transformSuffix(t *transforms, I int) []byte {
|
||||
return t.prefix_suffix[t.prefix_suffix_map[transformSuffixId(t, I)]:]
|
||||
}
|
||||
|
||||
/* RFC 7932 transforms string data */
|
||||
|
@ -139,385 +139,385 @@ var kPrefixSuffixMap = [50]uint16{
|
|||
/* RFC 7932 transforms */
|
||||
var kTransformsData = []byte{
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
0,
|
||||
0,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
0,
|
||||
49,
|
||||
BROTLI_TRANSFORM_OMIT_FIRST_1,
|
||||
transformOmitFirst1,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
0,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
47,
|
||||
0,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
49,
|
||||
4,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
0,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
3,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
6,
|
||||
49,
|
||||
BROTLI_TRANSFORM_OMIT_FIRST_2,
|
||||
transformOmitFirst2,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_OMIT_LAST_1,
|
||||
transformOmitLast1,
|
||||
49,
|
||||
1,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
0,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
1,
|
||||
0,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
0,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
7,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
9,
|
||||
48,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
0,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
8,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
5,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
10,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
11,
|
||||
49,
|
||||
BROTLI_TRANSFORM_OMIT_LAST_3,
|
||||
transformOmitLast3,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
13,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
14,
|
||||
49,
|
||||
BROTLI_TRANSFORM_OMIT_FIRST_3,
|
||||
transformOmitFirst3,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_OMIT_LAST_2,
|
||||
transformOmitLast2,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
15,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
16,
|
||||
0,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
12,
|
||||
5,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
49,
|
||||
0,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
1,
|
||||
49,
|
||||
BROTLI_TRANSFORM_OMIT_FIRST_4,
|
||||
transformOmitFirst4,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
18,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
17,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
19,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
20,
|
||||
49,
|
||||
BROTLI_TRANSFORM_OMIT_FIRST_5,
|
||||
transformOmitFirst5,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_OMIT_FIRST_6,
|
||||
transformOmitFirst6,
|
||||
49,
|
||||
47,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_OMIT_LAST_4,
|
||||
transformOmitLast4,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
22,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL,
|
||||
transformUppercaseAll,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
23,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
24,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
25,
|
||||
49,
|
||||
BROTLI_TRANSFORM_OMIT_LAST_7,
|
||||
transformOmitLast7,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_OMIT_LAST_1,
|
||||
transformOmitLast1,
|
||||
26,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
27,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
28,
|
||||
0,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
12,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
29,
|
||||
49,
|
||||
BROTLI_TRANSFORM_OMIT_FIRST_9,
|
||||
transformOmitFirst9,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_OMIT_FIRST_7,
|
||||
transformOmitFirst7,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_OMIT_LAST_6,
|
||||
transformOmitLast6,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
21,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
1,
|
||||
49,
|
||||
BROTLI_TRANSFORM_OMIT_LAST_8,
|
||||
transformOmitLast8,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
31,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
32,
|
||||
47,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
3,
|
||||
49,
|
||||
BROTLI_TRANSFORM_OMIT_LAST_5,
|
||||
transformOmitLast5,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_OMIT_LAST_9,
|
||||
transformOmitLast9,
|
||||
49,
|
||||
0,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
1,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
8,
|
||||
5,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
21,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL,
|
||||
transformUppercaseAll,
|
||||
0,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
10,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
30,
|
||||
0,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
5,
|
||||
35,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
49,
|
||||
47,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
2,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
17,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
36,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
33,
|
||||
5,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
0,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
21,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
5,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
37,
|
||||
0,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
30,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
38,
|
||||
0,
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL,
|
||||
transformUppercaseAll,
|
||||
0,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
39,
|
||||
0,
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL,
|
||||
transformUppercaseAll,
|
||||
49,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
34,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL,
|
||||
transformUppercaseAll,
|
||||
8,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
12,
|
||||
0,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
21,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
40,
|
||||
0,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
12,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
41,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
42,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL,
|
||||
transformUppercaseAll,
|
||||
17,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
43,
|
||||
0,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
5,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL,
|
||||
transformUppercaseAll,
|
||||
10,
|
||||
0,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
34,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
33,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
44,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL,
|
||||
transformUppercaseAll,
|
||||
5,
|
||||
45,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
49,
|
||||
0,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
33,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
30,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL,
|
||||
transformUppercaseAll,
|
||||
30,
|
||||
49,
|
||||
BROTLI_TRANSFORM_IDENTITY,
|
||||
transformIdentity,
|
||||
46,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL,
|
||||
transformUppercaseAll,
|
||||
1,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
34,
|
||||
0,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
33,
|
||||
0,
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL,
|
||||
transformUppercaseAll,
|
||||
30,
|
||||
0,
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL,
|
||||
transformUppercaseAll,
|
||||
1,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL,
|
||||
transformUppercaseAll,
|
||||
33,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL,
|
||||
transformUppercaseAll,
|
||||
21,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL,
|
||||
transformUppercaseAll,
|
||||
12,
|
||||
0,
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL,
|
||||
transformUppercaseAll,
|
||||
5,
|
||||
49,
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL,
|
||||
transformUppercaseAll,
|
||||
34,
|
||||
0,
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL,
|
||||
transformUppercaseAll,
|
||||
12,
|
||||
0,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
30,
|
||||
0,
|
||||
BROTLI_TRANSFORM_UPPERCASE_ALL,
|
||||
transformUppercaseAll,
|
||||
34,
|
||||
0,
|
||||
BROTLI_TRANSFORM_UPPERCASE_FIRST,
|
||||
transformUppercaseFirst,
|
||||
34,
|
||||
}
|
||||
|
||||
var kBrotliTransforms = BrotliTransforms{
|
||||
var kBrotliTransforms = transforms{
|
||||
217,
|
||||
[]byte(kPrefixSuffix),
|
||||
kPrefixSuffixMap[:],
|
||||
121,
|
||||
kTransformsData,
|
||||
nil, /* no extra parameters */
|
||||
[BROTLI_TRANSFORMS_MAX_CUT_OFF + 1]int16{0, 12, 27, 23, 42, 63, 56, 48, 59, 64},
|
||||
[transformsMaxCutOff + 1]int16{0, 12, 27, 23, 42, 63, 56, 48, 59, 64},
|
||||
}
|
||||
|
||||
func BrotliGetTransforms() *BrotliTransforms {
|
||||
func getTransforms() *transforms {
|
||||
return &kBrotliTransforms
|
||||
}
|
||||
|
||||
func ToUpperCase(p []byte) int {
|
||||
func toUpperCase(p []byte) int {
|
||||
if p[0] < 0xC0 {
|
||||
if p[0] >= 'a' && p[0] <= 'z' {
|
||||
p[0] ^= 32
|
||||
|
@ -538,7 +538,7 @@ func ToUpperCase(p []byte) int {
|
|||
return 3
|
||||
}
|
||||
|
||||
func Shift(word []byte, word_len int, parameter uint16) int {
|
||||
func shiftTransform(word []byte, word_len int, parameter uint16) int {
|
||||
/* Limited sign extension: scalar < (1 << 24). */
|
||||
var scalar uint32 = (uint32(parameter) & 0x7FFF) + (0x1000000 - (uint32(parameter) & 0x8000))
|
||||
if word[0] < 0x80 {
|
||||
|
@ -585,11 +585,11 @@ func Shift(word []byte, word_len int, parameter uint16) int {
|
|||
return 1
|
||||
}
|
||||
|
||||
func BrotliTransformDictionaryWord(dst []byte, word []byte, len int, transforms *BrotliTransforms, transform_idx int) int {
|
||||
func transformDictionaryWord(dst []byte, word []byte, len int, trans *transforms, transform_idx int) int {
|
||||
var idx int = 0
|
||||
var prefix []byte = BROTLI_TRANSFORM_PREFIX(transforms, transform_idx)
|
||||
var type_ byte = BROTLI_TRANSFORM_TYPE(transforms, transform_idx)
|
||||
var suffix []byte = BROTLI_TRANSFORM_SUFFIX(transforms, transform_idx)
|
||||
var prefix []byte = transformPrefix(trans, transform_idx)
|
||||
var type_ byte = transformType(trans, transform_idx)
|
||||
var suffix []byte = transformSuffix(trans, transform_idx)
|
||||
{
|
||||
var prefix_len int = int(prefix[0])
|
||||
prefix = prefix[1:]
|
||||
|
@ -607,10 +607,10 @@ func BrotliTransformDictionaryWord(dst []byte, word []byte, len int, transforms
|
|||
{
|
||||
var t int = int(type_)
|
||||
var i int = 0
|
||||
if t <= BROTLI_TRANSFORM_OMIT_LAST_9 {
|
||||
if t <= transformOmitLast9 {
|
||||
len -= t
|
||||
} else if t >= BROTLI_TRANSFORM_OMIT_FIRST_1 && t <= BROTLI_TRANSFORM_OMIT_FIRST_9 {
|
||||
var skip int = t - (BROTLI_TRANSFORM_OMIT_FIRST_1 - 1)
|
||||
} else if t >= transformOmitFirst1 && t <= transformOmitFirst9 {
|
||||
var skip int = t - (transformOmitFirst1 - 1)
|
||||
word = word[skip:]
|
||||
len -= skip
|
||||
}
|
||||
|
@ -620,25 +620,25 @@ func BrotliTransformDictionaryWord(dst []byte, word []byte, len int, transforms
|
|||
idx++
|
||||
i++
|
||||
}
|
||||
if t == BROTLI_TRANSFORM_UPPERCASE_FIRST {
|
||||
ToUpperCase(dst[idx-len:])
|
||||
} else if t == BROTLI_TRANSFORM_UPPERCASE_ALL {
|
||||
if t == transformUppercaseFirst {
|
||||
toUpperCase(dst[idx-len:])
|
||||
} else if t == transformUppercaseAll {
|
||||
var uppercase []byte = dst
|
||||
uppercase = uppercase[idx-len:]
|
||||
for len > 0 {
|
||||
var step int = ToUpperCase(uppercase)
|
||||
var step int = toUpperCase(uppercase)
|
||||
uppercase = uppercase[step:]
|
||||
len -= step
|
||||
}
|
||||
} else if t == BROTLI_TRANSFORM_SHIFT_FIRST {
|
||||
var param uint16 = uint16(transforms.params[transform_idx*2] + (transforms.params[transform_idx*2+1] << 8))
|
||||
Shift(dst[idx-len:], int(len), param)
|
||||
} else if t == BROTLI_TRANSFORM_SHIFT_ALL {
|
||||
var param uint16 = uint16(transforms.params[transform_idx*2] + (transforms.params[transform_idx*2+1] << 8))
|
||||
} else if t == transformShiftFirst {
|
||||
var param uint16 = uint16(trans.params[transform_idx*2] + (trans.params[transform_idx*2+1] << 8))
|
||||
shiftTransform(dst[idx-len:], int(len), param)
|
||||
} else if t == transformShiftAll {
|
||||
var param uint16 = uint16(trans.params[transform_idx*2] + (trans.params[transform_idx*2+1] << 8))
|
||||
var shift []byte = dst
|
||||
shift = shift[idx-len:]
|
||||
for len > 0 {
|
||||
var step int = Shift(shift, int(len), param)
|
||||
var step int = shiftTransform(shift, int(len), param)
|
||||
shift = shift[step:]
|
||||
len -= step
|
||||
}
|
||||
|
|
15
types.go
15
types.go
|
@ -1,15 +0,0 @@
|
|||
package brotli
|
||||
|
||||
/* Copyright 2013 Google Inc. All Rights Reserved.
|
||||
|
||||
Distributed under MIT license.
|
||||
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Common types used in decoder and encoder API.
|
||||
*/
|
||||
const BROTLI_UINT32_MAX = (^(uint32(0)))
|
||||
|
||||
const BROTLI_SIZE_MAX = (^(uint(0)))
|
12
utf8_util.go
12
utf8_util.go
|
@ -7,19 +7,13 @@ package brotli
|
|||
*/
|
||||
|
||||
/* Heuristics for deciding about the UTF8-ness of strings. */
|
||||
/* Copyright 2013 Google Inc. All Rights Reserved.
|
||||
|
||||
Distributed under MIT license.
|
||||
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
/* Heuristics for deciding about the UTF8-ness of strings. */
|
||||
var kMinUTF8Ratio float64 = 0.75
|
||||
|
||||
/* Returns 1 if at least min_fraction of the bytes between pos and
|
||||
pos + length in the (data, mask) ring-buffer is UTF8-encoded, otherwise
|
||||
returns 0. */
|
||||
func BrotliParseAsUTF8(symbol *int, input []byte, size uint) uint {
|
||||
func parseAsUTF8(symbol *int, input []byte, size uint) uint {
|
||||
/* ASCII */
|
||||
if input[0]&0x80 == 0 {
|
||||
*symbol = int(input[0])
|
||||
|
@ -59,14 +53,14 @@ func BrotliParseAsUTF8(symbol *int, input []byte, size uint) uint {
|
|||
}
|
||||
|
||||
/* Returns 1 if at least min_fraction of the data is UTF8-encoded.*/
|
||||
func BrotliIsMostlyUTF8(data []byte, pos uint, mask uint, length uint, min_fraction float64) bool {
|
||||
func isMostlyUTF8(data []byte, pos uint, mask uint, length uint, min_fraction float64) bool {
|
||||
var size_utf8 uint = 0
|
||||
var i uint = 0
|
||||
for i < length {
|
||||
var symbol int
|
||||
var current_data []byte
|
||||
current_data = data[(pos+i)&mask:]
|
||||
var bytes_read uint = BrotliParseAsUTF8(&symbol, current_data, length-i)
|
||||
var bytes_read uint = parseAsUTF8(&symbol, current_data, length-i)
|
||||
i += bytes_read
|
||||
if symbol < 0x110000 {
|
||||
size_utf8 += bytes_read
|
||||
|
|
23
version.go
23
version.go
|
@ -1,23 +0,0 @@
|
|||
package brotli
|
||||
|
||||
/* Copyright 2016 Google Inc. All Rights Reserved.
|
||||
|
||||
Distributed under MIT license.
|
||||
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
/* Version definition. */
|
||||
|
||||
/* This macro should only be used when library is compiled together with client.
|
||||
If library is dynamically linked, use BrotliDecoderVersion and
|
||||
BrotliEncoderVersion methods. */
|
||||
|
||||
/* Semantic version, calculated as (MAJOR << 24) | (MINOR << 12) | PATCH */
|
||||
const BROTLI_VERSION = 0x1000007
|
||||
|
||||
/* This macro is used by build system to produce Libtool-friendly soname. See
|
||||
https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
|
||||
*/
|
||||
|
||||
/* ABI version, calculated as (CURRENT << 24) | (REVISION << 12) | AGE */
|
||||
const BROTLI_ABI_VERSION = 0x1007000
|
|
@ -60,7 +60,7 @@ package brotli
|
|||
|
||||
For n bits, we take the last 5 bits, OR that with high bits in BYTE-0,
|
||||
and locate the rest in BYTE+1, BYTE+2, etc. */
|
||||
func BrotliWriteBits(n_bits uint, bits uint64, pos *uint, array []byte) {
|
||||
func writeBits(n_bits uint, bits uint64, pos *uint, array []byte) {
|
||||
var array_pos []byte = array[*pos>>3:]
|
||||
var bits_reserved_in_first_byte uint = (*pos & 7)
|
||||
/* implicit & 0xFF is assumed for uint8_t arithmetics */
|
||||
|
@ -79,15 +79,15 @@ func BrotliWriteBits(n_bits uint, bits uint64, pos *uint, array []byte) {
|
|||
*pos += n_bits
|
||||
}
|
||||
|
||||
func BrotliWriteSingleBit(bit bool, pos *uint, array []byte) {
|
||||
func writeSingleBit(bit bool, pos *uint, array []byte) {
|
||||
if bit {
|
||||
BrotliWriteBits(1, 1, pos, array)
|
||||
writeBits(1, 1, pos, array)
|
||||
} else {
|
||||
BrotliWriteBits(1, 0, pos, array)
|
||||
writeBits(1, 0, pos, array)
|
||||
}
|
||||
}
|
||||
|
||||
func BrotliWriteBitsPrepareStorage(pos uint, array []byte) {
|
||||
func writeBitsPrepareStorage(pos uint, array []byte) {
|
||||
assert(pos&7 == 0)
|
||||
array[pos>>3] = 0
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue