diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:17 +0300 |
commit | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch) | |
tree | dd4bd3ca0f36b817e96812825ffaf10d645803f2 /contrib/libs/brotli/enc | |
parent | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff) | |
download | ydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/brotli/enc')
-rw-r--r-- | contrib/libs/brotli/enc/backward_references.h | 18 | ||||
-rw-r--r-- | contrib/libs/brotli/enc/bit_cost.h | 60 | ||||
-rw-r--r-- | contrib/libs/brotli/enc/block_splitter.h | 24 | ||||
-rw-r--r-- | contrib/libs/brotli/enc/brotli_bit_stream.h | 30 | ||||
-rw-r--r-- | contrib/libs/brotli/enc/cluster.h | 32 | ||||
-rw-r--r-- | contrib/libs/brotli/enc/command.h | 80 | ||||
-rw-r--r-- | contrib/libs/brotli/enc/dictionary_hash.h | 16 | ||||
-rw-r--r-- | contrib/libs/brotli/enc/entropy_encode.h | 28 | ||||
-rw-r--r-- | contrib/libs/brotli/enc/fast_log.h | 224 | ||||
-rw-r--r-- | contrib/libs/brotli/enc/find_match_length.h | 78 | ||||
-rw-r--r-- | contrib/libs/brotli/enc/hash.h | 124 | ||||
-rw-r--r-- | contrib/libs/brotli/enc/histogram.h | 24 | ||||
-rw-r--r-- | contrib/libs/brotli/enc/literal_cost.h | 16 | ||||
-rw-r--r-- | contrib/libs/brotli/enc/metablock.h | 34 | ||||
-rw-r--r-- | contrib/libs/brotli/enc/prefix.h | 26 | ||||
-rw-r--r-- | contrib/libs/brotli/enc/ringbuffer.h | 34 | ||||
-rw-r--r-- | contrib/libs/brotli/enc/static_dict.h | 18 | ||||
-rw-r--r-- | contrib/libs/brotli/enc/static_dict_lut.h | 26 | ||||
-rw-r--r-- | contrib/libs/brotli/enc/write_bits.h | 46 | ||||
-rw-r--r-- | contrib/libs/brotli/enc/ya.make | 30 |
20 files changed, 484 insertions, 484 deletions
diff --git a/contrib/libs/brotli/enc/backward_references.h b/contrib/libs/brotli/enc/backward_references.h index 7b3c04a8ff..3a4146647c 100644 --- a/contrib/libs/brotli/enc/backward_references.h +++ b/contrib/libs/brotli/enc/backward_references.h @@ -1,26 +1,26 @@ /* Copyright 2013 Google Inc. All Rights Reserved. - + Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ /* Function to find backward reference copies. */ -#ifndef BROTLI_ENC_BACKWARD_REFERENCES_H_ -#define BROTLI_ENC_BACKWARD_REFERENCES_H_ - +#ifndef BROTLI_ENC_BACKWARD_REFERENCES_H_ +#define BROTLI_ENC_BACKWARD_REFERENCES_H_ + #include "../common/constants.h" #include "../common/dictionary.h" #include "../common/platform.h" #include <brotli/types.h> #include "./command.h" -#include "./hash.h" +#include "./hash.h" #include "./quality.h" - + #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif - + /* "commands" points to the next output command to write to, "*num_commands" is initially the total amount of commands output by previous CreateBackwardReferences calls, and must be incremented by the amount written @@ -30,9 +30,9 @@ BROTLI_INTERNAL void BrotliCreateBackwardReferences( size_t ringbuffer_mask, const BrotliEncoderParams* params, HasherHandle hasher, int* dist_cache, size_t* last_insert_len, Command* commands, size_t* num_commands, size_t* num_literals); - + #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif - + #endif /* BROTLI_ENC_BACKWARD_REFERENCES_H_ */ diff --git a/contrib/libs/brotli/enc/bit_cost.h b/contrib/libs/brotli/enc/bit_cost.h index 30324d38c7..6586469e62 100644 --- a/contrib/libs/brotli/enc/bit_cost.h +++ b/contrib/libs/brotli/enc/bit_cost.h @@ -1,63 +1,63 @@ /* Copyright 2013 Google Inc. All Rights Reserved. - + Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ /* Functions to estimate the bit cost of Huffman trees. */ -#ifndef BROTLI_ENC_BIT_COST_H_ -#define BROTLI_ENC_BIT_COST_H_ - +#ifndef BROTLI_ENC_BIT_COST_H_ +#define BROTLI_ENC_BIT_COST_H_ + #include "../common/platform.h" #include <brotli/types.h> -#include "./fast_log.h" +#include "./fast_log.h" #include "./histogram.h" - + #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif - + static BROTLI_INLINE double ShannonEntropy( const uint32_t* population, size_t size, size_t* total) { size_t sum = 0; - double retval = 0; + double retval = 0; const uint32_t* population_end = population + size; size_t p; - if (size & 1) { - goto odd_number_of_elements_left; - } - while (population < population_end) { - p = *population++; - sum += p; + if (size & 1) { + goto odd_number_of_elements_left; + } + while (population < population_end) { + p = *population++; + sum += p; retval -= (double)p * FastLog2(p); - odd_number_of_elements_left: - p = *population++; - sum += p; + odd_number_of_elements_left: + p = *population++; + sum += p; retval -= (double)p * FastLog2(p); - } + } if (sum) retval += (double)sum * FastLog2(sum); - *total = sum; - return retval; -} - + *total = sum; + return retval; +} + static BROTLI_INLINE double BitsEntropy( const uint32_t* population, size_t size) { size_t sum; - double retval = ShannonEntropy(population, size, &sum); - if (retval < sum) { + double retval = ShannonEntropy(population, size, &sum); + if (retval < sum) { /* At least one bit per literal is needed. */ retval = (double)sum; - } - return retval; -} - + } + return retval; +} + BROTLI_INTERNAL double BrotliPopulationCostLiteral(const HistogramLiteral*); BROTLI_INTERNAL double BrotliPopulationCostCommand(const HistogramCommand*); BROTLI_INTERNAL double BrotliPopulationCostDistance(const HistogramDistance*); - + #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif - + #endif /* BROTLI_ENC_BIT_COST_H_ */ diff --git a/contrib/libs/brotli/enc/block_splitter.h b/contrib/libs/brotli/enc/block_splitter.h index 2fd1cb417a..a5e006c4b3 100644 --- a/contrib/libs/brotli/enc/block_splitter.h +++ b/contrib/libs/brotli/enc/block_splitter.h @@ -1,38 +1,38 @@ /* Copyright 2013 Google Inc. All Rights Reserved. - + Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ /* Block split point selection utilities. */ -#ifndef BROTLI_ENC_BLOCK_SPLITTER_H_ -#define BROTLI_ENC_BLOCK_SPLITTER_H_ - +#ifndef BROTLI_ENC_BLOCK_SPLITTER_H_ +#define BROTLI_ENC_BLOCK_SPLITTER_H_ + #include "../common/platform.h" #include <brotli/types.h> -#include "./command.h" +#include "./command.h" #include "./memory.h" #include "./quality.h" - + #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif - + typedef struct BlockSplit { size_t num_types; /* Amount of distinct types */ size_t num_blocks; /* Amount of values in types and length */ uint8_t* types; uint32_t* lengths; - + size_t types_alloc_size; size_t lengths_alloc_size; } BlockSplit; - + BROTLI_INTERNAL void BrotliInitBlockSplit(BlockSplit* self); BROTLI_INTERNAL void BrotliDestroyBlockSplit(MemoryManager* m, BlockSplit* self); - + BROTLI_INTERNAL void BrotliSplitBlock(MemoryManager* m, const Command* cmds, const size_t num_commands, @@ -43,9 +43,9 @@ BROTLI_INTERNAL void BrotliSplitBlock(MemoryManager* m, BlockSplit* literal_split, BlockSplit* insert_and_copy_split, BlockSplit* dist_split); - + #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif - + #endif /* BROTLI_ENC_BLOCK_SPLITTER_H_ */ diff --git a/contrib/libs/brotli/enc/brotli_bit_stream.h b/contrib/libs/brotli/enc/brotli_bit_stream.h index 42663c6704..2ed703bf79 100644 --- a/contrib/libs/brotli/enc/brotli_bit_stream.h +++ b/contrib/libs/brotli/enc/brotli_bit_stream.h @@ -1,5 +1,5 @@ /* Copyright 2014 Google Inc. All Rights Reserved. - + Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ @@ -13,32 +13,32 @@ is called "storage" and the index to the bit is called storage_ix in function arguments. */ -#ifndef BROTLI_ENC_BROTLI_BIT_STREAM_H_ -#define BROTLI_ENC_BROTLI_BIT_STREAM_H_ - +#ifndef BROTLI_ENC_BROTLI_BIT_STREAM_H_ +#define BROTLI_ENC_BROTLI_BIT_STREAM_H_ + #include "../common/context.h" #include "../common/platform.h" #include <brotli/types.h> #include "./command.h" #include "./entropy_encode.h" #include "./memory.h" -#include "./metablock.h" - +#include "./metablock.h" + #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif - + /* All Store functions here will use a storage_ix, which is always the bit position for the current storage. */ - + BROTLI_INTERNAL void BrotliStoreHuffmanTree(const uint8_t* depths, size_t num, HuffmanTree* tree, size_t* storage_ix, uint8_t* storage); - + BROTLI_INTERNAL void BrotliBuildAndStoreHuffmanTreeFast( MemoryManager* m, const uint32_t* histogram, const size_t histogram_total, const size_t max_bits, uint8_t* depth, uint16_t* bits, size_t* storage_ix, uint8_t* storage); - + /* REQUIRES: length > 0 */ /* REQUIRES: length <= (1 << 24) */ BROTLI_INTERNAL void BrotliStoreMetaBlock(MemoryManager* m, @@ -47,7 +47,7 @@ BROTLI_INTERNAL void BrotliStoreMetaBlock(MemoryManager* m, const BrotliEncoderParams* params, ContextType literal_context_mode, const Command* commands, size_t n_commands, const MetaBlockSplit* mb, size_t* storage_ix, uint8_t* storage); - + /* Stores the meta-block without doing any block splitting, just collects one histogram per block category and uses that for entropy coding. REQUIRES: length > 0 @@ -57,7 +57,7 @@ BROTLI_INTERNAL void BrotliStoreMetaBlockTrivial(MemoryManager* m, BROTLI_BOOL is_last, const BrotliEncoderParams* params, const Command* commands, size_t n_commands, size_t* storage_ix, uint8_t* storage); - + /* Same as above, but uses static prefix codes for histograms with a only a few symbols, and uses static code length prefix codes for all other histograms. REQUIRES: length > 0 @@ -67,7 +67,7 @@ BROTLI_INTERNAL void BrotliStoreMetaBlockFast(MemoryManager* m, BROTLI_BOOL is_last, const BrotliEncoderParams* params, const Command* commands, size_t n_commands, size_t* storage_ix, uint8_t* storage); - + /* This is for storing uncompressed blocks (simple raw storage of bytes-as-bytes). REQUIRES: length > 0 @@ -76,9 +76,9 @@ BROTLI_INTERNAL void BrotliStoreUncompressedMetaBlock( BROTLI_BOOL is_final_block, const uint8_t* BROTLI_RESTRICT input, size_t position, size_t mask, size_t len, size_t* BROTLI_RESTRICT storage_ix, uint8_t* BROTLI_RESTRICT storage); - + #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif - + #endif /* BROTLI_ENC_BROTLI_BIT_STREAM_H_ */ diff --git a/contrib/libs/brotli/enc/cluster.h b/contrib/libs/brotli/enc/cluster.h index daf573dc65..bb26124d24 100644 --- a/contrib/libs/brotli/enc/cluster.h +++ b/contrib/libs/brotli/enc/cluster.h @@ -1,48 +1,48 @@ /* Copyright 2013 Google Inc. All Rights Reserved. - + Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ /* Functions for clustering similar histograms together. */ -#ifndef BROTLI_ENC_CLUSTER_H_ -#define BROTLI_ENC_CLUSTER_H_ - +#ifndef BROTLI_ENC_CLUSTER_H_ +#define BROTLI_ENC_CLUSTER_H_ + #include "../common/platform.h" #include <brotli/types.h> -#include "./histogram.h" +#include "./histogram.h" #include "./memory.h" - + #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif - + typedef struct HistogramPair { uint32_t idx1; uint32_t idx2; - double cost_combo; - double cost_diff; + double cost_combo; + double cost_diff; } HistogramPair; - + #define CODE(X) /* Declaration */; - + #define FN(X) X ## Literal #include "./cluster_inc.h" /* NOLINT(build/include) */ #undef FN - + #define FN(X) X ## Command #include "./cluster_inc.h" /* NOLINT(build/include) */ #undef FN - + #define FN(X) X ## Distance #include "./cluster_inc.h" /* NOLINT(build/include) */ #undef FN - + #undef CODE - + #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif - + #endif /* BROTLI_ENC_CLUSTER_H_ */ diff --git a/contrib/libs/brotli/enc/command.h b/contrib/libs/brotli/enc/command.h index 181510cd67..1aac85689b 100644 --- a/contrib/libs/brotli/enc/command.h +++ b/contrib/libs/brotli/enc/command.h @@ -1,25 +1,25 @@ /* Copyright 2013 Google Inc. All Rights Reserved. - + Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ /* This class models a sequence of literals and a backward reference copy. */ -#ifndef BROTLI_ENC_COMMAND_H_ -#define BROTLI_ENC_COMMAND_H_ - +#ifndef BROTLI_ENC_COMMAND_H_ +#define BROTLI_ENC_COMMAND_H_ + #include "../common/constants.h" #include "../common/platform.h" #include <brotli/types.h> -#include "./fast_log.h" +#include "./fast_log.h" #include "./params.h" -#include "./prefix.h" - +#include "./prefix.h" + #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif - + static uint32_t kInsBase[] = { 0, 1, 2, 3, 4, 5, 6, 8, 10, 14, 18, 26, 34, 50, 66, 98, 130, 194, 322, 578, 1090, 2114, 6210, 22594 }; static uint32_t kInsExtra[] = { 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, @@ -28,44 +28,44 @@ static uint32_t kCopyBase[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 18, 22, 30, 38, 54, 70, 102, 134, 198, 326, 582, 1094, 2118 }; static uint32_t kCopyExtra[] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10, 24 }; - + static BROTLI_INLINE uint16_t GetInsertLengthCode(size_t insertlen) { - if (insertlen < 6) { + if (insertlen < 6) { return (uint16_t)insertlen; - } else if (insertlen < 130) { + } else if (insertlen < 130) { uint32_t nbits = Log2FloorNonZero(insertlen - 2) - 1u; return (uint16_t)((nbits << 1) + ((insertlen - 2) >> nbits) + 2); - } else if (insertlen < 2114) { + } else if (insertlen < 2114) { return (uint16_t)(Log2FloorNonZero(insertlen - 66) + 10); - } else if (insertlen < 6210) { + } else if (insertlen < 6210) { return 21u; - } else if (insertlen < 22594) { + } else if (insertlen < 22594) { return 22u; - } else { + } else { return 23u; - } -} - + } +} + static BROTLI_INLINE uint16_t GetCopyLengthCode(size_t copylen) { - if (copylen < 10) { + if (copylen < 10) { return (uint16_t)(copylen - 2); - } else if (copylen < 134) { + } else if (copylen < 134) { uint32_t nbits = Log2FloorNonZero(copylen - 6) - 1u; return (uint16_t)((nbits << 1) + ((copylen - 6) >> nbits) + 4); - } else if (copylen < 2118) { + } else if (copylen < 2118) { return (uint16_t)(Log2FloorNonZero(copylen - 70) + 12); - } else { + } else { return 23u; - } -} - + } +} + static BROTLI_INLINE uint16_t CombineLengthCodes( uint16_t inscode, uint16_t copycode, BROTLI_BOOL use_last_distance) { uint16_t bits64 = (uint16_t)((copycode & 0x7u) | ((inscode & 0x7u) << 3u)); if (use_last_distance && inscode < 8u && copycode < 16u) { return (copycode < 8u) ? bits64 : (bits64 | 64u); - } else { + } else { /* Specification: 5 Encoding of ... (last table) */ /* offset = 2 * index, where index is in range [0..8] */ uint32_t offset = 2u * ((copycode >> 3u) + 3u * (inscode >> 3u)); @@ -77,29 +77,29 @@ static BROTLI_INLINE uint16_t CombineLengthCodes( Magic constant is shifted 6 bits left, to avoid final multiplication. */ offset = (offset << 5u) + 0x40u + ((0x520D40u >> offset) & 0xC0u); return (uint16_t)(offset | bits64); - } -} - + } +} + static BROTLI_INLINE void GetLengthCode(size_t insertlen, size_t copylen, BROTLI_BOOL use_last_distance, uint16_t* code) { uint16_t inscode = GetInsertLengthCode(insertlen); uint16_t copycode = GetCopyLengthCode(copylen); *code = CombineLengthCodes(inscode, copycode, use_last_distance); -} - +} + static BROTLI_INLINE uint32_t GetInsertBase(uint16_t inscode) { return kInsBase[inscode]; } - + static BROTLI_INLINE uint32_t GetInsertExtra(uint16_t inscode) { return kInsExtra[inscode]; } - + static BROTLI_INLINE uint32_t GetCopyBase(uint16_t copycode) { return kCopyBase[copycode]; } - + static BROTLI_INLINE uint32_t GetCopyExtra(uint16_t copycode) { return kCopyExtra[copycode]; } @@ -161,28 +161,28 @@ static BROTLI_INLINE uint32_t CommandRestoreDistanceCode( uint32_t offset = ((2U + (hcode & 1U)) << nbits) - 4U; return ((offset + extra) << dist->distance_postfix_bits) + lcode + dist->num_direct_distance_codes + BROTLI_NUM_DISTANCE_SHORT_CODES; - } + } } - + static BROTLI_INLINE uint32_t CommandDistanceContext(const Command* self) { uint32_t r = self->cmd_prefix_ >> 6; uint32_t c = self->cmd_prefix_ & 7; if ((r == 0 || r == 2 || r == 4 || r == 7) && (c <= 2)) { return c; - } + } return 3; } - + static BROTLI_INLINE uint32_t CommandCopyLen(const Command* self) { return self->copy_len_ & 0x1FFFFFF; } - + static BROTLI_INLINE uint32_t CommandCopyLenCode(const Command* self) { uint32_t modifier = self->copy_len_ >> 25; int32_t delta = (int8_t)((uint8_t)(modifier | ((modifier & 0x40) << 1))); return (uint32_t)((int32_t)(self->copy_len_ & 0x1FFFFFF) + delta); } - + #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif diff --git a/contrib/libs/brotli/enc/dictionary_hash.h b/contrib/libs/brotli/enc/dictionary_hash.h index a7fafbe065..b3bb9599f4 100644 --- a/contrib/libs/brotli/enc/dictionary_hash.h +++ b/contrib/libs/brotli/enc/dictionary_hash.h @@ -1,24 +1,24 @@ /* Copyright 2015 Google Inc. All Rights Reserved. - + Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ /* Hash table on the 4-byte prefixes of static dictionary words. */ -#ifndef BROTLI_ENC_DICTIONARY_HASH_H_ -#define BROTLI_ENC_DICTIONARY_HASH_H_ - +#ifndef BROTLI_ENC_DICTIONARY_HASH_H_ +#define BROTLI_ENC_DICTIONARY_HASH_H_ + #include <brotli/types.h> - + #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif - + extern const uint16_t kStaticDictionaryHash[32768]; - + #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif - + #endif /* BROTLI_ENC_DICTIONARY_HASH_H_ */ diff --git a/contrib/libs/brotli/enc/entropy_encode.h b/contrib/libs/brotli/enc/entropy_encode.h index b1f02d5a35..f23d9c379d 100644 --- a/contrib/libs/brotli/enc/entropy_encode.h +++ b/contrib/libs/brotli/enc/entropy_encode.h @@ -1,57 +1,57 @@ /* Copyright 2010 Google Inc. All Rights Reserved. - + Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ /* Entropy encoding (Huffman) utilities. */ -#ifndef BROTLI_ENC_ENTROPY_ENCODE_H_ -#define BROTLI_ENC_ENTROPY_ENCODE_H_ - +#ifndef BROTLI_ENC_ENTROPY_ENCODE_H_ +#define BROTLI_ENC_ENTROPY_ENCODE_H_ + #include "../common/platform.h" #include <brotli/types.h> - + #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif - + /* A node of a Huffman tree. */ typedef struct HuffmanTree { uint32_t total_count_; int16_t index_left_; int16_t index_right_or_value_; } HuffmanTree; - + static BROTLI_INLINE void InitHuffmanTree(HuffmanTree* self, uint32_t count, int16_t left, int16_t right) { self->total_count_ = count; self->index_left_ = left; self->index_right_or_value_ = right; } - + /* Returns 1 is assignment of depths succeeded, otherwise 0. */ BROTLI_INTERNAL BROTLI_BOOL BrotliSetDepth( int p, HuffmanTree* pool, uint8_t* depth, int max_depth); - + /* This function will create a Huffman tree. - + The (data,length) contains the population counts. The tree_limit is the maximum bit depth of the Huffman codes. - + The depth contains the tree, i.e., how many bits are used for the symbol. - + The actual Huffman tree is constructed in the tree[] array, which has to be at least 2 * length + 1 long. - + See http://en.wikipedia.org/wiki/Huffman_coding */ BROTLI_INTERNAL void BrotliCreateHuffmanTree(const uint32_t* data, const size_t length, const int tree_limit, HuffmanTree* tree, uint8_t* depth); - + /* Change the population counts in a way that the consequent Huffman tree compression, especially its RLE-part will be more likely to compress this data more efficiently. diff --git a/contrib/libs/brotli/enc/fast_log.h b/contrib/libs/brotli/enc/fast_log.h index 7b5d067de6..cade1235ad 100644 --- a/contrib/libs/brotli/enc/fast_log.h +++ b/contrib/libs/brotli/enc/fast_log.h @@ -1,147 +1,147 @@ /* Copyright 2013 Google Inc. All Rights Reserved. - + Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ /* Utilities for fast computation of logarithms. */ -#ifndef BROTLI_ENC_FAST_LOG_H_ -#define BROTLI_ENC_FAST_LOG_H_ - -#include <math.h> - +#ifndef BROTLI_ENC_FAST_LOG_H_ +#define BROTLI_ENC_FAST_LOG_H_ + +#include <math.h> + #include "../common/platform.h" #include <brotli/types.h> - + #if defined(__cplusplus) || defined(c_plusplus) extern "C" { -#endif - +#endif + static BROTLI_INLINE uint32_t Log2FloorNonZero(size_t n) { /* TODO: generalize and move to platform.h */ #if BROTLI_GNUC_HAS_BUILTIN(__builtin_clz, 3, 4, 0) || \ BROTLI_INTEL_VERSION_CHECK(16, 0, 0) return 31u ^ (uint32_t)__builtin_clz((uint32_t)n); -#else +#else uint32_t result = 0; - while (n >>= 1) result++; - return result; -#endif -} - + while (n >>= 1) result++; + return result; +#endif +} + /* A lookup table for small values of log2(int) to be used in entropy computation. - + ", ".join(["%.16ff" % x for x in [0.0]+[log2(x) for x in range(1, 256)]]) */ -static const float kLog2Table[] = { - 0.0000000000000000f, 0.0000000000000000f, 1.0000000000000000f, - 1.5849625007211563f, 2.0000000000000000f, 2.3219280948873622f, - 2.5849625007211561f, 2.8073549220576042f, 3.0000000000000000f, - 3.1699250014423126f, 3.3219280948873626f, 3.4594316186372978f, - 3.5849625007211565f, 3.7004397181410922f, 3.8073549220576037f, - 3.9068905956085187f, 4.0000000000000000f, 4.0874628412503400f, - 4.1699250014423122f, 4.2479275134435852f, 4.3219280948873626f, - 4.3923174227787607f, 4.4594316186372973f, 4.5235619560570131f, - 4.5849625007211570f, 4.6438561897747244f, 4.7004397181410926f, - 4.7548875021634691f, 4.8073549220576037f, 4.8579809951275728f, - 4.9068905956085187f, 4.9541963103868758f, 5.0000000000000000f, - 5.0443941193584534f, 5.0874628412503400f, 5.1292830169449664f, - 5.1699250014423122f, 5.2094533656289501f, 5.2479275134435852f, - 5.2854022188622487f, 5.3219280948873626f, 5.3575520046180838f, - 5.3923174227787607f, 5.4262647547020979f, 5.4594316186372973f, - 5.4918530963296748f, 5.5235619560570131f, 5.5545888516776376f, - 5.5849625007211570f, 5.6147098441152083f, 5.6438561897747244f, - 5.6724253419714961f, 5.7004397181410926f, 5.7279204545631996f, - 5.7548875021634691f, 5.7813597135246599f, 5.8073549220576046f, - 5.8328900141647422f, 5.8579809951275719f, 5.8826430493618416f, - 5.9068905956085187f, 5.9307373375628867f, 5.9541963103868758f, - 5.9772799234999168f, 6.0000000000000000f, 6.0223678130284544f, - 6.0443941193584534f, 6.0660891904577721f, 6.0874628412503400f, - 6.1085244567781700f, 6.1292830169449672f, 6.1497471195046822f, - 6.1699250014423122f, 6.1898245588800176f, 6.2094533656289510f, - 6.2288186904958804f, 6.2479275134435861f, 6.2667865406949019f, - 6.2854022188622487f, 6.3037807481771031f, 6.3219280948873617f, - 6.3398500028846252f, 6.3575520046180847f, 6.3750394313469254f, - 6.3923174227787598f, 6.4093909361377026f, 6.4262647547020979f, - 6.4429434958487288f, 6.4594316186372982f, 6.4757334309663976f, - 6.4918530963296748f, 6.5077946401986964f, 6.5235619560570131f, - 6.5391588111080319f, 6.5545888516776376f, 6.5698556083309478f, - 6.5849625007211561f, 6.5999128421871278f, 6.6147098441152092f, - 6.6293566200796095f, 6.6438561897747253f, 6.6582114827517955f, - 6.6724253419714952f, 6.6865005271832185f, 6.7004397181410917f, - 6.7142455176661224f, 6.7279204545631988f, 6.7414669864011465f, - 6.7548875021634691f, 6.7681843247769260f, 6.7813597135246599f, - 6.7944158663501062f, 6.8073549220576037f, 6.8201789624151887f, - 6.8328900141647422f, 6.8454900509443757f, 6.8579809951275719f, - 6.8703647195834048f, 6.8826430493618416f, 6.8948177633079437f, - 6.9068905956085187f, 6.9188632372745955f, 6.9307373375628867f, - 6.9425145053392399f, 6.9541963103868758f, 6.9657842846620879f, - 6.9772799234999168f, 6.9886846867721664f, 7.0000000000000000f, - 7.0112272554232540f, 7.0223678130284544f, 7.0334230015374501f, - 7.0443941193584534f, 7.0552824355011898f, 7.0660891904577721f, - 7.0768155970508317f, 7.0874628412503400f, 7.0980320829605272f, - 7.1085244567781700f, 7.1189410727235076f, 7.1292830169449664f, - 7.1395513523987937f, 7.1497471195046822f, 7.1598713367783891f, - 7.1699250014423130f, 7.1799090900149345f, 7.1898245588800176f, - 7.1996723448363644f, 7.2094533656289492f, 7.2191685204621621f, - 7.2288186904958804f, 7.2384047393250794f, 7.2479275134435861f, - 7.2573878426926521f, 7.2667865406949019f, 7.2761244052742384f, - 7.2854022188622487f, 7.2946207488916270f, 7.3037807481771031f, - 7.3128829552843557f, 7.3219280948873617f, 7.3309168781146177f, - 7.3398500028846243f, 7.3487281542310781f, 7.3575520046180847f, - 7.3663222142458151f, 7.3750394313469254f, 7.3837042924740528f, - 7.3923174227787607f, 7.4008794362821844f, 7.4093909361377026f, - 7.4178525148858991f, 7.4262647547020979f, 7.4346282276367255f, - 7.4429434958487288f, 7.4512111118323299f, 7.4594316186372973f, - 7.4676055500829976f, 7.4757334309663976f, 7.4838157772642564f, - 7.4918530963296748f, 7.4998458870832057f, 7.5077946401986964f, - 7.5156998382840436f, 7.5235619560570131f, 7.5313814605163119f, - 7.5391588111080319f, 7.5468944598876373f, 7.5545888516776376f, - 7.5622424242210728f, 7.5698556083309478f, 7.5774288280357487f, - 7.5849625007211561f, 7.5924570372680806f, 7.5999128421871278f, - 7.6073303137496113f, 7.6147098441152075f, 7.6220518194563764f, - 7.6293566200796095f, 7.6366246205436488f, 7.6438561897747244f, - 7.6510516911789290f, 7.6582114827517955f, 7.6653359171851765f, - 7.6724253419714952f, 7.6794800995054464f, 7.6865005271832185f, - 7.6934869574993252f, 7.7004397181410926f, 7.7073591320808825f, - 7.7142455176661224f, 7.7210991887071856f, 7.7279204545631996f, - 7.7347096202258392f, 7.7414669864011465f, 7.7481928495894596f, - 7.7548875021634691f, 7.7615512324444795f, 7.7681843247769260f, - 7.7747870596011737f, 7.7813597135246608f, 7.7879025593914317f, - 7.7944158663501062f, 7.8008998999203047f, 7.8073549220576037f, - 7.8137811912170374f, 7.8201789624151887f, 7.8265484872909159f, - 7.8328900141647422f, 7.8392037880969445f, 7.8454900509443757f, - 7.8517490414160571f, 7.8579809951275719f, 7.8641861446542798f, - 7.8703647195834048f, 7.8765169465650002f, 7.8826430493618425f, - 7.8887432488982601f, 7.8948177633079446f, 7.9008668079807496f, - 7.9068905956085187f, 7.9128893362299619f, 7.9188632372745955f, - 7.9248125036057813f, 7.9307373375628867f, 7.9366379390025719f, - 7.9425145053392399f, 7.9483672315846778f, 7.9541963103868758f, - 7.9600019320680806f, 7.9657842846620870f, 7.9715435539507720f, - 7.9772799234999168f, 7.9829935746943104f, 7.9886846867721664f, - 7.9943534368588578f -}; - +static const float kLog2Table[] = { + 0.0000000000000000f, 0.0000000000000000f, 1.0000000000000000f, + 1.5849625007211563f, 2.0000000000000000f, 2.3219280948873622f, + 2.5849625007211561f, 2.8073549220576042f, 3.0000000000000000f, + 3.1699250014423126f, 3.3219280948873626f, 3.4594316186372978f, + 3.5849625007211565f, 3.7004397181410922f, 3.8073549220576037f, + 3.9068905956085187f, 4.0000000000000000f, 4.0874628412503400f, + 4.1699250014423122f, 4.2479275134435852f, 4.3219280948873626f, + 4.3923174227787607f, 4.4594316186372973f, 4.5235619560570131f, + 4.5849625007211570f, 4.6438561897747244f, 4.7004397181410926f, + 4.7548875021634691f, 4.8073549220576037f, 4.8579809951275728f, + 4.9068905956085187f, 4.9541963103868758f, 5.0000000000000000f, + 5.0443941193584534f, 5.0874628412503400f, 5.1292830169449664f, + 5.1699250014423122f, 5.2094533656289501f, 5.2479275134435852f, + 5.2854022188622487f, 5.3219280948873626f, 5.3575520046180838f, + 5.3923174227787607f, 5.4262647547020979f, 5.4594316186372973f, + 5.4918530963296748f, 5.5235619560570131f, 5.5545888516776376f, + 5.5849625007211570f, 5.6147098441152083f, 5.6438561897747244f, + 5.6724253419714961f, 5.7004397181410926f, 5.7279204545631996f, + 5.7548875021634691f, 5.7813597135246599f, 5.8073549220576046f, + 5.8328900141647422f, 5.8579809951275719f, 5.8826430493618416f, + 5.9068905956085187f, 5.9307373375628867f, 5.9541963103868758f, + 5.9772799234999168f, 6.0000000000000000f, 6.0223678130284544f, + 6.0443941193584534f, 6.0660891904577721f, 6.0874628412503400f, + 6.1085244567781700f, 6.1292830169449672f, 6.1497471195046822f, + 6.1699250014423122f, 6.1898245588800176f, 6.2094533656289510f, + 6.2288186904958804f, 6.2479275134435861f, 6.2667865406949019f, + 6.2854022188622487f, 6.3037807481771031f, 6.3219280948873617f, + 6.3398500028846252f, 6.3575520046180847f, 6.3750394313469254f, + 6.3923174227787598f, 6.4093909361377026f, 6.4262647547020979f, + 6.4429434958487288f, 6.4594316186372982f, 6.4757334309663976f, + 6.4918530963296748f, 6.5077946401986964f, 6.5235619560570131f, + 6.5391588111080319f, 6.5545888516776376f, 6.5698556083309478f, + 6.5849625007211561f, 6.5999128421871278f, 6.6147098441152092f, + 6.6293566200796095f, 6.6438561897747253f, 6.6582114827517955f, + 6.6724253419714952f, 6.6865005271832185f, 6.7004397181410917f, + 6.7142455176661224f, 6.7279204545631988f, 6.7414669864011465f, + 6.7548875021634691f, 6.7681843247769260f, 6.7813597135246599f, + 6.7944158663501062f, 6.8073549220576037f, 6.8201789624151887f, + 6.8328900141647422f, 6.8454900509443757f, 6.8579809951275719f, + 6.8703647195834048f, 6.8826430493618416f, 6.8948177633079437f, + 6.9068905956085187f, 6.9188632372745955f, 6.9307373375628867f, + 6.9425145053392399f, 6.9541963103868758f, 6.9657842846620879f, + 6.9772799234999168f, 6.9886846867721664f, 7.0000000000000000f, + 7.0112272554232540f, 7.0223678130284544f, 7.0334230015374501f, + 7.0443941193584534f, 7.0552824355011898f, 7.0660891904577721f, + 7.0768155970508317f, 7.0874628412503400f, 7.0980320829605272f, + 7.1085244567781700f, 7.1189410727235076f, 7.1292830169449664f, + 7.1395513523987937f, 7.1497471195046822f, 7.1598713367783891f, + 7.1699250014423130f, 7.1799090900149345f, 7.1898245588800176f, + 7.1996723448363644f, 7.2094533656289492f, 7.2191685204621621f, + 7.2288186904958804f, 7.2384047393250794f, 7.2479275134435861f, + 7.2573878426926521f, 7.2667865406949019f, 7.2761244052742384f, + 7.2854022188622487f, 7.2946207488916270f, 7.3037807481771031f, + 7.3128829552843557f, 7.3219280948873617f, 7.3309168781146177f, + 7.3398500028846243f, 7.3487281542310781f, 7.3575520046180847f, + 7.3663222142458151f, 7.3750394313469254f, 7.3837042924740528f, + 7.3923174227787607f, 7.4008794362821844f, 7.4093909361377026f, + 7.4178525148858991f, 7.4262647547020979f, 7.4346282276367255f, + 7.4429434958487288f, 7.4512111118323299f, 7.4594316186372973f, + 7.4676055500829976f, 7.4757334309663976f, 7.4838157772642564f, + 7.4918530963296748f, 7.4998458870832057f, 7.5077946401986964f, + 7.5156998382840436f, 7.5235619560570131f, 7.5313814605163119f, + 7.5391588111080319f, 7.5468944598876373f, 7.5545888516776376f, + 7.5622424242210728f, 7.5698556083309478f, 7.5774288280357487f, + 7.5849625007211561f, 7.5924570372680806f, 7.5999128421871278f, + 7.6073303137496113f, 7.6147098441152075f, 7.6220518194563764f, + 7.6293566200796095f, 7.6366246205436488f, 7.6438561897747244f, + 7.6510516911789290f, 7.6582114827517955f, 7.6653359171851765f, + 7.6724253419714952f, 7.6794800995054464f, 7.6865005271832185f, + 7.6934869574993252f, 7.7004397181410926f, 7.7073591320808825f, + 7.7142455176661224f, 7.7210991887071856f, 7.7279204545631996f, + 7.7347096202258392f, 7.7414669864011465f, 7.7481928495894596f, + 7.7548875021634691f, 7.7615512324444795f, 7.7681843247769260f, + 7.7747870596011737f, 7.7813597135246608f, 7.7879025593914317f, + 7.7944158663501062f, 7.8008998999203047f, 7.8073549220576037f, + 7.8137811912170374f, 7.8201789624151887f, 7.8265484872909159f, + 7.8328900141647422f, 7.8392037880969445f, 7.8454900509443757f, + 7.8517490414160571f, 7.8579809951275719f, 7.8641861446542798f, + 7.8703647195834048f, 7.8765169465650002f, 7.8826430493618425f, + 7.8887432488982601f, 7.8948177633079446f, 7.9008668079807496f, + 7.9068905956085187f, 7.9128893362299619f, 7.9188632372745955f, + 7.9248125036057813f, 7.9307373375628867f, 7.9366379390025719f, + 7.9425145053392399f, 7.9483672315846778f, 7.9541963103868758f, + 7.9600019320680806f, 7.9657842846620870f, 7.9715435539507720f, + 7.9772799234999168f, 7.9829935746943104f, 7.9886846867721664f, + 7.9943534368588578f +}; + #define LOG_2_INV 1.4426950408889634 /* Faster logarithm for small integers, with the property of log2(0) == 0. */ static BROTLI_INLINE double FastLog2(size_t v) { if (v < sizeof(kLog2Table) / sizeof(kLog2Table[0])) { - return kLog2Table[v]; - } + return kLog2Table[v]; + } #if (defined(_MSC_VER) && _MSC_VER <= 1700) || \ (defined(__ANDROID_API__) && __ANDROID_API__ < 18) /* Visual Studio 2012 and Android API levels < 18 do not have the log2() * function defined, so we use log() and a multiplication instead. */ return log((double)v) * LOG_2_INV; -#else +#else return log2((double)v); -#endif -} - +#endif +} + #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif - + #endif /* BROTLI_ENC_FAST_LOG_H_ */ diff --git a/contrib/libs/brotli/enc/find_match_length.h b/contrib/libs/brotli/enc/find_match_length.h index 5dd2bbb52e..bc428cffda 100644 --- a/contrib/libs/brotli/enc/find_match_length.h +++ b/contrib/libs/brotli/enc/find_match_length.h @@ -1,24 +1,24 @@ /* Copyright 2010 Google Inc. All Rights Reserved. - + Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ /* Function to find maximal matching prefixes of strings. */ -#ifndef BROTLI_ENC_FIND_MATCH_LENGTH_H_ -#define BROTLI_ENC_FIND_MATCH_LENGTH_H_ - +#ifndef BROTLI_ENC_FIND_MATCH_LENGTH_H_ +#define BROTLI_ENC_FIND_MATCH_LENGTH_H_ + #include "../common/platform.h" #include <brotli/types.h> - + #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif - + /* Separate implementation for little-endian 64-bit targets, for speed. */ #if defined(__GNUC__) && defined(_LP64) && defined(BROTLI_LITTLE_ENDIAN) - + static BROTLI_INLINE size_t FindMatchLengthWithLimit(const uint8_t* s1, const uint8_t* s2, size_t limit) { @@ -27,54 +27,54 @@ static BROTLI_INLINE size_t FindMatchLengthWithLimit(const uint8_t* s1, while (BROTLI_PREDICT_TRUE(--limit2)) { if (BROTLI_PREDICT_FALSE(BROTLI_UNALIGNED_LOAD64LE(s2) == BROTLI_UNALIGNED_LOAD64LE(s1 + matched))) { - s2 += 8; - matched += 8; - } else { + s2 += 8; + matched += 8; + } else { uint64_t x = BROTLI_UNALIGNED_LOAD64LE(s2) ^ BROTLI_UNALIGNED_LOAD64LE(s1 + matched); size_t matching_bits = (size_t)__builtin_ctzll(x); - matched += matching_bits >> 3; - return matched; - } - } + matched += matching_bits >> 3; + return matched; + } + } limit = (limit & 7) + 1; /* + 1 is for pre-decrement in while */ - while (--limit) { + while (--limit) { if (BROTLI_PREDICT_TRUE(s1[matched] == *s2)) { - ++s2; - ++matched; - } else { - return matched; - } - } - return matched; -} -#else + ++s2; + ++matched; + } else { + return matched; + } + } + return matched; +} +#else static BROTLI_INLINE size_t FindMatchLengthWithLimit(const uint8_t* s1, const uint8_t* s2, size_t limit) { size_t matched = 0; - const uint8_t* s2_limit = s2 + limit; - const uint8_t* s2_ptr = s2; + const uint8_t* s2_limit = s2 + limit; + const uint8_t* s2_ptr = s2; /* Find out how long the match is. We loop over the data 32 bits at a time until we find a 32-bit block that doesn't match; then we find the first non-matching bit and use that to calculate the total length of the match. */ - while (s2_ptr <= s2_limit - 4 && + while (s2_ptr <= s2_limit - 4 && BrotliUnalignedRead32(s2_ptr) == BrotliUnalignedRead32(s1 + matched)) { - s2_ptr += 4; - matched += 4; - } - while ((s2_ptr < s2_limit) && (s1[matched] == *s2_ptr)) { - ++s2_ptr; - ++matched; - } - return matched; -} -#endif - + s2_ptr += 4; + matched += 4; + } + while ((s2_ptr < s2_limit) && (s1[matched] == *s2_ptr)) { + ++s2_ptr; + ++matched; + } + return matched; +} +#endif + #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif - + #endif /* BROTLI_ENC_FIND_MATCH_LENGTH_H_ */ diff --git a/contrib/libs/brotli/enc/hash.h b/contrib/libs/brotli/enc/hash.h index c4945fb101..8c5a7bb5ad 100644 --- a/contrib/libs/brotli/enc/hash.h +++ b/contrib/libs/brotli/enc/hash.h @@ -1,5 +1,5 @@ /* Copyright 2010 Google Inc. All Rights Reserved. - + Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ @@ -7,26 +7,26 @@ /* A (forgetful) hash table to the data seen by the compressor, to help create backward references to previous data. */ -#ifndef BROTLI_ENC_HASH_H_ -#define BROTLI_ENC_HASH_H_ - +#ifndef BROTLI_ENC_HASH_H_ +#define BROTLI_ENC_HASH_H_ + #include <string.h> /* memcmp, memset */ - + #include "../common/constants.h" #include "../common/dictionary.h" #include "../common/platform.h" #include <brotli/types.h> #include "./encoder_dict.h" -#include "./fast_log.h" -#include "./find_match_length.h" +#include "./fast_log.h" +#include "./find_match_length.h" #include "./memory.h" #include "./quality.h" -#include "./static_dict.h" - +#include "./static_dict.h" + #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif - + /* Pointer to hasher data. * * Excluding initialization and destruction, hasher can be passed as @@ -40,10 +40,10 @@ extern "C" { * Using "define" instead of "typedef", because on MSVC __restrict does not work * on typedef pointer types. */ #define HasherHandle uint8_t* - + typedef struct { BrotliHasherParams params; - + /* False if hasher needs to be "prepared" before use. */ BROTLI_BOOL is_prepared_; @@ -80,14 +80,14 @@ static const uint32_t kHashMul32 = 0x1E35A7BD; static const uint64_t kHashMul64 = BROTLI_MAKE_UINT64_T(0x1E35A7BD, 0x1E35A7BD); static const uint64_t kHashMul64Long = BROTLI_MAKE_UINT64_T(0x1FE35A7Bu, 0xD3579BD3u); - + static BROTLI_INLINE uint32_t Hash14(const uint8_t* data) { uint32_t h = BROTLI_UNALIGNED_LOAD32LE(data) * kHashMul32; /* The higher bits contain more mixture from the multiplication, so we take our results from there. */ return h >> (32 - 14); -} - +} + static BROTLI_INLINE void PrepareDistanceCache( int* BROTLI_RESTRICT distance_cache, const int num_distances) { if (num_distances > 4) { @@ -108,8 +108,8 @@ static BROTLI_INLINE void PrepareDistanceCache( distance_cache[15] = next_last_distance + 3; } } -} - +} + #define BROTLI_LITERAL_BYTE_SCORE 135 #define BROTLI_DISTANCE_BIT_PENALTY 30 /* Score must be positive after applying maximal penalty. */ @@ -135,19 +135,19 @@ static BROTLI_INLINE score_t BackwardReferenceScore( size_t copy_length, size_t backward_reference_offset) { return BROTLI_SCORE_BASE + BROTLI_LITERAL_BYTE_SCORE * (score_t)copy_length - BROTLI_DISTANCE_BIT_PENALTY * Log2FloorNonZero(backward_reference_offset); -} - +} + static BROTLI_INLINE score_t BackwardReferenceScoreUsingLastDistance( size_t copy_length) { return BROTLI_LITERAL_BYTE_SCORE * (score_t)copy_length + BROTLI_SCORE_BASE + 15; } - + static BROTLI_INLINE score_t BackwardReferencePenaltyUsingLastDistance( size_t distance_short_code) { return (score_t)39 + ((0x1CA10 >> (distance_short_code & 0xE)) & 0xE); } - + static BROTLI_INLINE BROTLI_BOOL TestStaticDictionaryItem( const BrotliEncoderDictionary* dictionary, size_t item, const uint8_t* data, size_t max_length, size_t max_backward, @@ -164,33 +164,33 @@ static BROTLI_INLINE BROTLI_BOOL TestStaticDictionaryItem( if (len > max_length) { return BROTLI_FALSE; } - + matchlen = FindMatchLengthWithLimit(data, &dictionary->words->data[offset], len); if (matchlen + dictionary->cutoffTransformsCount <= len || matchlen == 0) { return BROTLI_FALSE; - } + } { size_t cut = len - matchlen; size_t transform_id = (cut << 2) + (size_t)((dictionary->cutoffTransforms >> (cut * 6)) & 0x3F); backward = max_backward + 1 + word_idx + (transform_id << dictionary->words->size_bits_by_length[len]); - } + } if (backward > max_distance) { return BROTLI_FALSE; - } + } score = BackwardReferenceScore(matchlen, backward); if (score < out->score) { return BROTLI_FALSE; - } + } out->len = matchlen; out->len_code_delta = (int)len - (int)matchlen; out->distance = backward; out->score = score; return BROTLI_TRUE; } - + static BROTLI_INLINE void SearchInStaticDictionary( const BrotliEncoderDictionary* dictionary, HasherHandle handle, const uint8_t* data, size_t max_length, @@ -201,7 +201,7 @@ static BROTLI_INLINE void SearchInStaticDictionary( HasherCommon* self = GetHasherCommon(handle); if (self->dict_num_matches < (self->dict_num_lookups >> 7)) { return; - } + } key = Hash14(data) << 1; for (i = 0; i < (shallow ? 1u : 2u); ++i, ++key) { size_t item = dictionary->hash_table[key]; @@ -212,42 +212,42 @@ static BROTLI_INLINE void SearchInStaticDictionary( max_length, max_backward, max_distance, out); if (item_matches) { self->dict_num_matches++; - } - } - } + } + } + } } - + typedef struct BackwardMatch { uint32_t distance; uint32_t length_and_code; } BackwardMatch; - + static BROTLI_INLINE void InitBackwardMatch(BackwardMatch* self, size_t dist, size_t len) { self->distance = (uint32_t)dist; self->length_and_code = (uint32_t)(len << 5); } - + static BROTLI_INLINE void InitDictionaryBackwardMatch(BackwardMatch* self, size_t dist, size_t len, size_t len_code) { self->distance = (uint32_t)dist; self->length_and_code = (uint32_t)((len << 5) | (len == len_code ? 0 : len_code)); } - + static BROTLI_INLINE size_t BackwardMatchLength(const BackwardMatch* self) { return self->length_and_code >> 5; } - + static BROTLI_INLINE size_t BackwardMatchLengthCode(const BackwardMatch* self) { size_t code = self->length_and_code & 31; return code ? code : BackwardMatchLength(self); } - + #define EXPAND_CAT(a, b) CAT(a, b) #define CAT(a, b) a ## b #define FN(X) EXPAND_CAT(X, HASHER()) - + #define HASHER() H10 #define BUCKET_BITS 17 #define MAX_TREE_SEARCH_DEPTH 64 @@ -259,11 +259,11 @@ static BROTLI_INLINE size_t BackwardMatchLengthCode(const BackwardMatch* self) { #undef HASHER /* MAX_NUM_MATCHES == 64 + MAX_TREE_SEARCH_DEPTH */ #define MAX_NUM_MATCHES_H10 128 - + /* For BUCKET_SWEEP == 1, enabling the dictionary lookup makes compression a little faster (0.5% - 1%) and it compresses 0.15% better on small text and HTML inputs. */ - + #define HASHER() H2 #define BUCKET_BITS 16 #define BUCKET_SWEEP 1 @@ -273,7 +273,7 @@ static BROTLI_INLINE size_t BackwardMatchLengthCode(const BackwardMatch* self) { #undef BUCKET_SWEEP #undef USE_DICTIONARY #undef HASHER - + #define HASHER() H3 #define BUCKET_SWEEP 2 #define USE_DICTIONARY 0 @@ -282,7 +282,7 @@ static BROTLI_INLINE size_t BackwardMatchLengthCode(const BackwardMatch* self) { #undef BUCKET_SWEEP #undef BUCKET_BITS #undef HASHER - + #define HASHER() H4 #define BUCKET_BITS 17 #define BUCKET_SWEEP 4 @@ -293,17 +293,17 @@ static BROTLI_INLINE size_t BackwardMatchLengthCode(const BackwardMatch* self) { #undef BUCKET_SWEEP #undef BUCKET_BITS #undef HASHER - + #define HASHER() H5 #include "./hash_longest_match_inc.h" /* NOLINT(build/include) */ #undef HASHER - + #define HASHER() H6 #include "./hash_longest_match64_inc.h" /* NOLINT(build/include) */ #undef HASHER - + #define BUCKET_BITS 15 - + #define NUM_LAST_DISTANCES_TO_CHECK 4 #define NUM_BANKS 1 #define BANK_BITS 16 @@ -311,7 +311,7 @@ static BROTLI_INLINE size_t BackwardMatchLengthCode(const BackwardMatch* self) { #include "./hash_forgetful_chain_inc.h" /* NOLINT(build/include) */ #undef HASHER #undef NUM_LAST_DISTANCES_TO_CHECK - + #define NUM_LAST_DISTANCES_TO_CHECK 10 #define HASHER() H41 #include "./hash_forgetful_chain_inc.h" /* NOLINT(build/include) */ @@ -319,7 +319,7 @@ static BROTLI_INLINE size_t BackwardMatchLengthCode(const BackwardMatch* self) { #undef NUM_LAST_DISTANCES_TO_CHECK #undef NUM_BANKS #undef BANK_BITS - + #define NUM_LAST_DISTANCES_TO_CHECK 16 #define NUM_BANKS 512 #define BANK_BITS 9 @@ -329,9 +329,9 @@ static BROTLI_INLINE size_t BackwardMatchLengthCode(const BackwardMatch* self) { #undef NUM_LAST_DISTANCES_TO_CHECK #undef NUM_BANKS #undef BANK_BITS - + #undef BUCKET_BITS - + #define HASHER() H54 #define BUCKET_BITS 20 #define BUCKET_SWEEP 4 @@ -343,7 +343,7 @@ static BROTLI_INLINE size_t BackwardMatchLengthCode(const BackwardMatch* self) { #undef BUCKET_SWEEP #undef BUCKET_BITS #undef HASHER - + /* fast large window hashers */ #define HASHER() HROLLING_FAST @@ -420,10 +420,10 @@ static BROTLI_INLINE size_t HasherSize(const BrotliEncoderParams* params, #undef SIZE_ default: break; - } + } return result; } - + static BROTLI_INLINE void HasherSetup(MemoryManager* m, HasherHandle* handle, BrotliEncoderParams* params, const uint8_t* data, size_t position, size_t input_size, BROTLI_BOOL is_last) { @@ -448,10 +448,10 @@ static BROTLI_INLINE void HasherSetup(MemoryManager* m, HasherHandle* handle, #undef INITIALIZE_ default: break; - } + } HasherReset(*handle); - } - + } + self = *handle; common = GetHasherCommon(self); if (!common->is_prepared_) { @@ -462,16 +462,16 @@ static BROTLI_INLINE void HasherSetup(MemoryManager* m, HasherHandle* handle, break; FOR_ALL_HASHERS(PREPARE_) #undef PREPARE_ - default: break; - } + default: break; + } if (position == 0) { common->dict_num_lookups = 0; common->dict_num_matches = 0; } common->is_prepared_ = BROTLI_TRUE; - } + } } - + static BROTLI_INLINE void InitOrStitchToPreviousBlock( MemoryManager* m, HasherHandle* handle, const uint8_t* data, size_t mask, BrotliEncoderParams* params, size_t position, size_t input_size, @@ -490,9 +490,9 @@ static BROTLI_INLINE void InitOrStitchToPreviousBlock( default: break; } } - + #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif - + #endif /* BROTLI_ENC_HASH_H_ */ diff --git a/contrib/libs/brotli/enc/histogram.h b/contrib/libs/brotli/enc/histogram.h index a522ca7aa7..42af3c3f9d 100644 --- a/contrib/libs/brotli/enc/histogram.h +++ b/contrib/libs/brotli/enc/histogram.h @@ -1,14 +1,14 @@ /* Copyright 2013 Google Inc. All Rights Reserved. - + Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ /* Models the histograms of literals, commands and distance codes. */ -#ifndef BROTLI_ENC_HISTOGRAM_H_ -#define BROTLI_ENC_HISTOGRAM_H_ - +#ifndef BROTLI_ENC_HISTOGRAM_H_ +#define BROTLI_ENC_HISTOGRAM_H_ + #include <string.h> /* memset */ #include "../common/constants.h" @@ -16,12 +16,12 @@ #include "../common/platform.h" #include <brotli/types.h> #include "./block_splitter.h" -#include "./command.h" - +#include "./command.h" + #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif - + /* The distance symbols effectively used by "Large Window Brotli" (32-bit). */ #define BROTLI_NUM_HISTOGRAM_DISTANCE_SYMBOLS 544 @@ -32,21 +32,21 @@ extern "C" { #undef DataType #undef DATA_SIZE #undef FN - + #define FN(X) X ## Command #define DataType uint16_t #define DATA_SIZE BROTLI_NUM_COMMAND_SYMBOLS #include "./histogram_inc.h" /* NOLINT(build/include) */ #undef DATA_SIZE #undef FN - + #define FN(X) X ## Distance #define DATA_SIZE BROTLI_NUM_HISTOGRAM_DISTANCE_SYMBOLS #include "./histogram_inc.h" /* NOLINT(build/include) */ #undef DataType #undef DATA_SIZE #undef FN - + BROTLI_INTERNAL void BrotliBuildHistogramsWithContext( const Command* cmds, const size_t num_commands, const BlockSplit* literal_split, const BlockSplit* insert_and_copy_split, @@ -55,9 +55,9 @@ BROTLI_INTERNAL void BrotliBuildHistogramsWithContext( const ContextType* context_modes, HistogramLiteral* literal_histograms, HistogramCommand* insert_and_copy_histograms, HistogramDistance* copy_dist_histograms); - + #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif - + #endif /* BROTLI_ENC_HISTOGRAM_H_ */ diff --git a/contrib/libs/brotli/enc/literal_cost.h b/contrib/libs/brotli/enc/literal_cost.h index 412c155890..8f53f39d3f 100644 --- a/contrib/libs/brotli/enc/literal_cost.h +++ b/contrib/libs/brotli/enc/literal_cost.h @@ -1,5 +1,5 @@ /* Copyright 2013 Google Inc. All Rights Reserved. - + Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ @@ -7,24 +7,24 @@ /* Literal cost model to allow backward reference replacement to be efficient. */ -#ifndef BROTLI_ENC_LITERAL_COST_H_ -#define BROTLI_ENC_LITERAL_COST_H_ - +#ifndef BROTLI_ENC_LITERAL_COST_H_ +#define BROTLI_ENC_LITERAL_COST_H_ + #include "../common/platform.h" #include <brotli/types.h> - + #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif - + /* Estimates how many bits the literals in the interval [pos, pos + len) in the ring-buffer (data, mask) will take entropy coded and writes these estimates to the cost[0..len) array. */ BROTLI_INTERNAL void BrotliEstimateBitCostsForLiterals( size_t pos, size_t len, size_t mask, const uint8_t* data, float* cost); - + #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif - + #endif /* BROTLI_ENC_LITERAL_COST_H_ */ diff --git a/contrib/libs/brotli/enc/metablock.h b/contrib/libs/brotli/enc/metablock.h index add40a056c..334a79a443 100644 --- a/contrib/libs/brotli/enc/metablock.h +++ b/contrib/libs/brotli/enc/metablock.h @@ -1,5 +1,5 @@ /* Copyright 2015 Google Inc. All Rights Reserved. - + Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ @@ -7,26 +7,26 @@ /* Algorithms for distributing the literals and commands of a metablock between block types and contexts. */ -#ifndef BROTLI_ENC_METABLOCK_H_ -#define BROTLI_ENC_METABLOCK_H_ - +#ifndef BROTLI_ENC_METABLOCK_H_ +#define BROTLI_ENC_METABLOCK_H_ + #include "../common/context.h" #include "../common/platform.h" #include <brotli/types.h> #include "./block_splitter.h" -#include "./command.h" -#include "./histogram.h" +#include "./command.h" +#include "./histogram.h" #include "./memory.h" #include "./quality.h" - + #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif - + typedef struct MetaBlockSplit { - BlockSplit literal_split; - BlockSplit command_split; - BlockSplit distance_split; + BlockSplit literal_split; + BlockSplit command_split; + BlockSplit distance_split; uint32_t* literal_context_map; size_t literal_context_map_size; uint32_t* distance_context_map; @@ -38,7 +38,7 @@ typedef struct MetaBlockSplit { HistogramDistance* distance_histograms; size_t distance_histograms_size; } MetaBlockSplit; - + static BROTLI_INLINE void InitMetaBlockSplit(MetaBlockSplit* mb) { BrotliInitBlockSplit(&mb->literal_split); BrotliInitBlockSplit(&mb->command_split); @@ -54,7 +54,7 @@ static BROTLI_INLINE void InitMetaBlockSplit(MetaBlockSplit* mb) { mb->distance_histograms = 0; mb->distance_histograms_size = 0; } - + static BROTLI_INLINE void DestroyMetaBlockSplit( MemoryManager* m, MetaBlockSplit* mb) { BrotliDestroyBlockSplit(m, &mb->literal_split); @@ -66,7 +66,7 @@ static BROTLI_INLINE void DestroyMetaBlockSplit( BROTLI_FREE(m, mb->command_histograms); BROTLI_FREE(m, mb->distance_histograms); } - + /* Uses the slow shortest-path block splitter and does context clustering. The distance parameters are dynamically selected based on the commands which get recomputed under the new distance parameters. The new distance @@ -82,7 +82,7 @@ BROTLI_INTERNAL void BrotliBuildMetaBlock(MemoryManager* m, size_t num_commands, ContextType literal_context_mode, MetaBlockSplit* mb); - + /* Uses a fast greedy block splitter that tries to merge current block with the last or the second last block and uses a static context clustering which is the same for all block types. */ @@ -91,10 +91,10 @@ BROTLI_INTERNAL void BrotliBuildMetaBlockGreedy( uint8_t prev_byte, uint8_t prev_byte2, ContextLut literal_context_lut, size_t num_contexts, const uint32_t* static_context_map, const Command* commands, size_t n_commands, MetaBlockSplit* mb); - + BROTLI_INTERNAL void BrotliOptimizeHistograms(uint32_t num_distance_codes, MetaBlockSplit* mb); - + BROTLI_INTERNAL void BrotliInitDistanceParams(BrotliEncoderParams* params, uint32_t npostfix, uint32_t ndirect); diff --git a/contrib/libs/brotli/enc/prefix.h b/contrib/libs/brotli/enc/prefix.h index 56b89fa466..fd359a478d 100644 --- a/contrib/libs/brotli/enc/prefix.h +++ b/contrib/libs/brotli/enc/prefix.h @@ -1,5 +1,5 @@ /* Copyright 2013 Google Inc. All Rights Reserved. - + Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ @@ -7,18 +7,18 @@ /* Functions for encoding of integers into prefix codes the amount of extra bits, and the actual values of the extra bits. */ -#ifndef BROTLI_ENC_PREFIX_H_ -#define BROTLI_ENC_PREFIX_H_ - +#ifndef BROTLI_ENC_PREFIX_H_ +#define BROTLI_ENC_PREFIX_H_ + #include "../common/constants.h" #include "../common/platform.h" #include <brotli/types.h> -#include "./fast_log.h" - +#include "./fast_log.h" + #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif - + /* 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. */ static BROTLI_INLINE void PrefixEncodeCopyDistance(size_t distance_code, @@ -28,8 +28,8 @@ static BROTLI_INLINE void PrefixEncodeCopyDistance(size_t distance_code, uint32_t* extra_bits) { if (distance_code < BROTLI_NUM_DISTANCE_SHORT_CODES + num_direct_codes) { *code = (uint16_t)distance_code; - *extra_bits = 0; - return; + *extra_bits = 0; + return; } else { size_t dist = ((size_t)1 << (postfix_bits + 2u)) + (distance_code - BROTLI_NUM_DISTANCE_SHORT_CODES - num_direct_codes); @@ -43,11 +43,11 @@ static BROTLI_INLINE void PrefixEncodeCopyDistance(size_t distance_code, (BROTLI_NUM_DISTANCE_SHORT_CODES + num_direct_codes + ((2 * (nbits - 1) + prefix) << postfix_bits) + postfix)); *extra_bits = (uint32_t)((dist - offset) >> postfix_bits); - } -} - + } +} + #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif - + #endif /* BROTLI_ENC_PREFIX_H_ */ diff --git a/contrib/libs/brotli/enc/ringbuffer.h b/contrib/libs/brotli/enc/ringbuffer.h index 1ee7688e54..86079a89d3 100644 --- a/contrib/libs/brotli/enc/ringbuffer.h +++ b/contrib/libs/brotli/enc/ringbuffer.h @@ -1,25 +1,25 @@ /* Copyright 2013 Google Inc. All Rights Reserved. - + Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ /* Sliding window over the input data. */ -#ifndef BROTLI_ENC_RINGBUFFER_H_ -#define BROTLI_ENC_RINGBUFFER_H_ - +#ifndef BROTLI_ENC_RINGBUFFER_H_ +#define BROTLI_ENC_RINGBUFFER_H_ + #include <string.h> /* memcpy */ - + #include "../common/platform.h" #include <brotli/types.h> #include "./memory.h" #include "./quality.h" - + #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif - + /* 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)'. @@ -80,16 +80,16 @@ static BROTLI_INLINE void RingBufferInitBuffer( memcpy(new_data, rb->data_, 2 + rb->cur_size_ + kSlackForEightByteHashingEverywhere); BROTLI_FREE(m, rb->data_); - } + } rb->data_ = new_data; rb->cur_size_ = buflen; rb->buffer_ = rb->data_ + 2; rb->buffer_[-2] = rb->buffer_[-1] = 0; for (i = 0; i < kSlackForEightByteHashingEverywhere; ++i) { rb->buffer_[rb->cur_size_ + i] = 0; - } + } } - + static BROTLI_INLINE void RingBufferWriteTail( const uint8_t* bytes, size_t n, RingBuffer* rb) { const size_t masked_pos = rb->pos_ & rb->mask_; @@ -98,9 +98,9 @@ static BROTLI_INLINE void RingBufferWriteTail( const size_t p = rb->size_ + masked_pos; memcpy(&rb->buffer_[p], bytes, BROTLI_MIN(size_t, n, rb->tail_size_ - masked_pos)); - } + } } - + /* Push bytes into the ring buffer. */ static BROTLI_INLINE void RingBufferWrite( MemoryManager* m, const uint8_t* bytes, size_t n, RingBuffer* rb) { @@ -116,7 +116,7 @@ static BROTLI_INLINE void RingBufferWrite( if (BROTLI_IS_OOM(m)) return; memcpy(rb->buffer_, bytes, n); return; - } + } if (rb->cur_size_ < rb->total_size_) { /* Lazily allocate the full buffer. */ RingBufferInitBuffer(m, rb->total_size_, rb); @@ -142,8 +142,8 @@ static BROTLI_INLINE void RingBufferWrite( /* Copy into the beginning of the buffer */ memcpy(&rb->buffer_[0], bytes + (rb->size_ - masked_pos), n - (rb->size_ - masked_pos)); - } - } + } + } { BROTLI_BOOL not_first_lap = (rb->pos_ & (1u << 31)) != 0; uint32_t rb_pos_mask = (1u << 31) - 1; @@ -156,9 +156,9 @@ static BROTLI_INLINE void RingBufferWrite( } } } - + #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif - + #endif /* BROTLI_ENC_RINGBUFFER_H_ */ diff --git a/contrib/libs/brotli/enc/static_dict.h b/contrib/libs/brotli/enc/static_dict.h index a5e06f43c5..6b5d4eb0c9 100644 --- a/contrib/libs/brotli/enc/static_dict.h +++ b/contrib/libs/brotli/enc/static_dict.h @@ -1,26 +1,26 @@ /* Copyright 2013 Google Inc. All Rights Reserved. - + Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ /* Class to model the static dictionary. */ -#ifndef BROTLI_ENC_STATIC_DICT_H_ -#define BROTLI_ENC_STATIC_DICT_H_ - +#ifndef BROTLI_ENC_STATIC_DICT_H_ +#define BROTLI_ENC_STATIC_DICT_H_ + #include "../common/dictionary.h" #include "../common/platform.h" #include <brotli/types.h> #include "./encoder_dict.h" - + #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif - + #define BROTLI_MAX_STATIC_DICTIONARY_MATCH_LEN 37 static const uint32_t kInvalidMatch = 0xFFFFFFF; - + /* Matches data against static dictionary words, and for each length l, for which a match is found, updates matches[l] to be the minimum possible (distance << 5) + len_code. @@ -32,9 +32,9 @@ BROTLI_INTERNAL BROTLI_BOOL BrotliFindAllStaticDictionaryMatches( const BrotliEncoderDictionary* dictionary, const uint8_t* data, size_t min_length, size_t max_length, uint32_t* matches); - + #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif - + #endif /* BROTLI_ENC_STATIC_DICT_H_ */ diff --git a/contrib/libs/brotli/enc/static_dict_lut.h b/contrib/libs/brotli/enc/static_dict_lut.h index aba9af4508..e299cda6d8 100644 --- a/contrib/libs/brotli/enc/static_dict_lut.h +++ b/contrib/libs/brotli/enc/static_dict_lut.h @@ -1,30 +1,30 @@ /* Copyright 2015 Google Inc. All Rights Reserved. - + Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ - + /* Lookup table for static dictionary and transforms. */ - + #ifndef BROTLI_ENC_STATIC_DICT_LUT_H_ #define BROTLI_ENC_STATIC_DICT_LUT_H_ - + #include <brotli/types.h> - + #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif typedef struct DictWord { /* Highest bit is used to indicate end of bucket. */ - uint8_t len; - uint8_t transform; - uint16_t idx; + uint8_t len; + uint8_t transform; + uint16_t idx; } DictWord; - + static const int kDictNumBits = 15; static const uint32_t kDictHashMul32 = 0x1E35A7BD; - + static const uint16_t kStaticDictionaryBuckets[32768] = { 1,0,0,0,0,0,0,0,0,3,6,0,0,0,0,0,20,0,0,0,21,0,22,0,0,0,0,0,0,0,0,23,0,0,25,0,29, 0,53,0,0,0,0,0,0,55,0,0,0,0,0,0,61,76,0,0,0,94,0,0,0,0,0,0,96,0,97,0,98,0,0,0,0, @@ -5855,10 +5855,10 @@ static const DictWord kStaticDictionaryWords[31705] = { 458},{12,0,756},{132,10,420},{134,0,1504},{6,0,757},{133,11,383},{6,0,1266},{135 ,0,1735},{5,0,598},{7,0,791},{8,0,108},{9,0,123},{7,10,1570},{140,10,542},{142, 11,410},{9,11,660},{138,11,347} -}; - +}; + #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif - + #endif /* BROTLI_ENC_STATIC_DICT_LUT_H_ */ diff --git a/contrib/libs/brotli/enc/write_bits.h b/contrib/libs/brotli/enc/write_bits.h index 6f6080b5c0..36515a6893 100644 --- a/contrib/libs/brotli/enc/write_bits.h +++ b/contrib/libs/brotli/enc/write_bits.h @@ -1,23 +1,23 @@ /* Copyright 2010 Google Inc. All Rights Reserved. - + Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ /* Write bits into a byte array. */ -#ifndef BROTLI_ENC_WRITE_BITS_H_ -#define BROTLI_ENC_WRITE_BITS_H_ - +#ifndef BROTLI_ENC_WRITE_BITS_H_ +#define BROTLI_ENC_WRITE_BITS_H_ + #include "../common/platform.h" #include <brotli/types.h> - + #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif - + /*#define BIT_WRITER_DEBUG */ - + /* This function writes bits into bytes in increasing addresses, and within a byte least-significant-bit first. @@ -50,36 +50,36 @@ static BROTLI_INLINE void BrotliWriteBits(size_t n_bits, (int)*pos)); BROTLI_DCHECK((bits >> n_bits) == 0); BROTLI_DCHECK(n_bits <= 56); - v |= bits << (*pos & 7); + v |= bits << (*pos & 7); BROTLI_UNALIGNED_STORE64LE(p, v); /* Set some bits. */ - *pos += n_bits; -#else + *pos += n_bits; +#else /* implicit & 0xFF is assumed for uint8_t arithmetics */ uint8_t* array_pos = &array[*pos >> 3]; const size_t bits_reserved_in_first_byte = (*pos & 7); size_t bits_left_to_write; - bits <<= bits_reserved_in_first_byte; + bits <<= bits_reserved_in_first_byte; *array_pos++ |= (uint8_t)bits; for (bits_left_to_write = n_bits + bits_reserved_in_first_byte; bits_left_to_write >= 9; - bits_left_to_write -= 8) { - bits >>= 8; + bits_left_to_write -= 8) { + bits >>= 8; *array_pos++ = (uint8_t)bits; - } - *array_pos = 0; - *pos += n_bits; -#endif -} - + } + *array_pos = 0; + *pos += n_bits; +#endif +} + static BROTLI_INLINE void BrotliWriteBitsPrepareStorage( size_t pos, uint8_t* array) { BROTLI_LOG(("WriteBitsPrepareStorage %10d\n", (int)pos)); BROTLI_DCHECK((pos & 7) == 0); - array[pos >> 3] = 0; -} - + array[pos >> 3] = 0; +} + #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif - + #endif /* BROTLI_ENC_WRITE_BITS_H_ */ diff --git a/contrib/libs/brotli/enc/ya.make b/contrib/libs/brotli/enc/ya.make index 6d415989e7..67da82ec4d 100644 --- a/contrib/libs/brotli/enc/ya.make +++ b/contrib/libs/brotli/enc/ya.make @@ -1,6 +1,6 @@ -LIBRARY() - -LICENSE(MIT) +LIBRARY() + +LICENSE(MIT) LICENSE_TEXTS(.yandex_meta/licenses.list.txt) @@ -9,19 +9,19 @@ OWNER( g:contrib g:cpp-contrib ) - -NO_UTIL() -NO_COMPILER_WARNINGS() - +NO_UTIL() + +NO_COMPILER_WARNINGS() + ADDINCL(GLOBAL contrib/libs/brotli/include) -PEERDIR( +PEERDIR( contrib/libs/brotli/common - contrib/libs/brotli/dec -) - -SRCS( + contrib/libs/brotli/dec +) + +SRCS( backward_references.c backward_references_hq.c bit_cost.c @@ -40,8 +40,8 @@ SRCS( metablock.c static_dict.c utf8_util.c -) - +) + CFLAGS(-DBROTLI_BUILD_PORTABLE) -END() +END() |