diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2022-04-01 20:58:27 +0300 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-04-01 21:24:45 +0100 |
commit | 086969277e74d8ba065bf8145d3aeb0dec0bfee5 (patch) | |
tree | 02b3699a66735ef806d9b46353491f18f8e4e7b4 /Userland/Libraries/LibCompress | |
parent | 0376c127f6e98e03607700d0b3f5154b7014b2f8 (diff) | |
download | serenity-086969277e74d8ba065bf8145d3aeb0dec0bfee5.zip |
Everywhere: Run clang-format
Diffstat (limited to 'Userland/Libraries/LibCompress')
-rw-r--r-- | Userland/Libraries/LibCompress/Deflate.cpp | 36 | ||||
-rw-r--r-- | Userland/Libraries/LibCompress/Deflate.h | 20 | ||||
-rw-r--r-- | Userland/Libraries/LibCompress/Gzip.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibCompress/Gzip.h | 2 |
4 files changed, 32 insertions, 32 deletions
diff --git a/Userland/Libraries/LibCompress/Deflate.cpp b/Userland/Libraries/LibCompress/Deflate.cpp index a4e0bcedbe..31a2271572 100644 --- a/Userland/Libraries/LibCompress/Deflate.cpp +++ b/Userland/Libraries/LibCompress/Deflate.cpp @@ -16,7 +16,7 @@ namespace Compress { -const CanonicalCode& CanonicalCode::fixed_literal_codes() +CanonicalCode const& CanonicalCode::fixed_literal_codes() { static CanonicalCode code; static bool initialized = false; @@ -30,7 +30,7 @@ const CanonicalCode& CanonicalCode::fixed_literal_codes() return code; } -const CanonicalCode& CanonicalCode::fixed_distance_codes() +CanonicalCode const& CanonicalCode::fixed_distance_codes() { static CanonicalCode code; static bool initialized = false; @@ -128,7 +128,7 @@ bool DeflateDecompressor::CompressedBlock::try_read_more() if (m_eof == true) return false; - const auto symbol = m_literal_codes.read_symbol(m_decompressor.m_input_stream); + auto const symbol = m_literal_codes.read_symbol(m_decompressor.m_input_stream); if (symbol >= 286) { // invalid deflate literal/length symbol m_decompressor.set_fatal_error(); @@ -147,13 +147,13 @@ bool DeflateDecompressor::CompressedBlock::try_read_more() return false; } - const auto length = m_decompressor.decode_length(symbol); - const auto distance_symbol = m_distance_codes.value().read_symbol(m_decompressor.m_input_stream); + auto const length = m_decompressor.decode_length(symbol); + auto const distance_symbol = m_distance_codes.value().read_symbol(m_decompressor.m_input_stream); if (distance_symbol >= 30) { // invalid deflate distance symbol m_decompressor.set_fatal_error(); return false; } - const auto distance = m_decompressor.decode_distance(distance_symbol); + auto const distance = m_decompressor.decode_distance(distance_symbol); for (size_t idx = 0; idx < length; ++idx) { u8 byte = 0; @@ -180,7 +180,7 @@ bool DeflateDecompressor::UncompressedBlock::try_read_more() if (m_bytes_remaining == 0) return false; - const auto nread = min(m_bytes_remaining, m_decompressor.m_output_stream.remaining_contiguous_space()); + auto const nread = min(m_bytes_remaining, m_decompressor.m_output_stream.remaining_contiguous_space()); m_bytes_remaining -= nread; m_decompressor.m_input_stream >> m_decompressor.m_output_stream.reserve_contiguous_space(nread); @@ -215,7 +215,7 @@ size_t DeflateDecompressor::read(Bytes bytes) break; m_read_final_bock = m_input_stream.read_bit(); - const auto block_type = m_input_stream.read_bits(2); + auto const block_type = m_input_stream.read_bits(2); if (m_input_stream.has_any_error()) { set_fatal_error(); @@ -363,7 +363,7 @@ Optional<ByteBuffer> DeflateDecompressor::decompress_all(ReadonlyBytes bytes) u8 buffer[4096]; while (!deflate_stream.has_any_error() && !deflate_stream.unreliable_eof()) { - const auto nread = deflate_stream.read({ buffer, sizeof(buffer) }); + auto const nread = deflate_stream.read({ buffer, sizeof(buffer) }); output_stream.write_or_error({ buffer, nread }); } @@ -428,7 +428,7 @@ void DeflateDecompressor::decode_codes(CanonicalCode& literal_code, Optional<Can set_fatal_error(); return; } - const auto code_length_code = code_length_code_result.value(); + auto const code_length_code = code_length_code_result.value(); // Next we extract the code lengths of the code that was used to encode the block. @@ -544,7 +544,7 @@ bool DeflateCompressor::write_or_error(ReadonlyBytes bytes) } // Knuth's multiplicative hash on 4 bytes -u16 DeflateCompressor::hash_sequence(const u8* bytes) +u16 DeflateCompressor::hash_sequence(u8 const* bytes) { constexpr const u32 knuth_constant = 2654435761; // shares no common factors with 2^32 return ((bytes[0] | bytes[1] << 8 | bytes[2] << 16 | bytes[3] << 24) * knuth_constant) >> (32 - hash_bits); @@ -617,7 +617,7 @@ ALWAYS_INLINE u8 DeflateCompressor::distance_to_base(u16 distance) } template<size_t Size> -void DeflateCompressor::generate_huffman_lengths(Array<u8, Size>& lengths, const Array<u16, Size>& frequencies, size_t max_bit_length, u16 frequency_cap) +void DeflateCompressor::generate_huffman_lengths(Array<u8, Size>& lengths, Array<u16, Size> const& frequencies, size_t max_bit_length, u16 frequency_cap) { VERIFY((1u << max_bit_length) >= Size); u16 heap_keys[Size]; // Used for O(n) heap construction @@ -773,7 +773,7 @@ void DeflateCompressor::lz77_compress_block() } } -size_t DeflateCompressor::huffman_block_length(const Array<u8, max_huffman_literals>& literal_bit_lengths, const Array<u8, max_huffman_distances>& distance_bit_lengths) +size_t DeflateCompressor::huffman_block_length(Array<u8, max_huffman_literals> const& literal_bit_lengths, Array<u8, max_huffman_distances> const& distance_bit_lengths) { size_t length = 0; @@ -807,7 +807,7 @@ size_t DeflateCompressor::fixed_block_length() return 3 + huffman_block_length(fixed_literal_bit_lengths, fixed_distance_bit_lengths); } -size_t DeflateCompressor::dynamic_block_length(const Array<u8, max_huffman_literals>& literal_bit_lengths, const Array<u8, max_huffman_distances>& distance_bit_lengths, const Array<u8, 19>& code_lengths_bit_lengths, const Array<u16, 19>& code_lengths_frequencies, size_t code_lengths_count) +size_t DeflateCompressor::dynamic_block_length(Array<u8, max_huffman_literals> const& literal_bit_lengths, Array<u8, max_huffman_distances> const& distance_bit_lengths, Array<u8, 19> const& code_lengths_bit_lengths, Array<u16, 19> const& code_lengths_frequencies, size_t code_lengths_count) { // block header + literal code count + distance code count + code length count auto length = 3 + 5 + 5 + 4; @@ -831,7 +831,7 @@ size_t DeflateCompressor::dynamic_block_length(const Array<u8, max_huffman_liter return length + huffman_block_length(literal_bit_lengths, distance_bit_lengths); } -void DeflateCompressor::write_huffman(const CanonicalCode& literal_code, const Optional<CanonicalCode>& distance_code) +void DeflateCompressor::write_huffman(CanonicalCode const& literal_code, Optional<CanonicalCode> const& distance_code) { auto has_distances = distance_code.has_value(); for (size_t i = 0; i < m_pending_symbol_size; i++) { @@ -852,7 +852,7 @@ void DeflateCompressor::write_huffman(const CanonicalCode& literal_code, const O } } -size_t DeflateCompressor::encode_huffman_lengths(const Array<u8, max_huffman_literals + max_huffman_distances>& lengths, size_t lengths_count, Array<code_length_symbol, max_huffman_literals + max_huffman_distances>& encoded_lengths) +size_t DeflateCompressor::encode_huffman_lengths(Array<u8, max_huffman_literals + max_huffman_distances> const& lengths, size_t lengths_count, Array<code_length_symbol, max_huffman_literals + max_huffman_distances>& encoded_lengths) { size_t encoded_count = 0; size_t i = 0; @@ -895,7 +895,7 @@ size_t DeflateCompressor::encode_huffman_lengths(const Array<u8, max_huffman_lit return encoded_count; } -size_t DeflateCompressor::encode_block_lengths(const Array<u8, max_huffman_literals>& literal_bit_lengths, const Array<u8, max_huffman_distances>& distance_bit_lengths, Array<code_length_symbol, max_huffman_literals + max_huffman_distances>& encoded_lengths, size_t& literal_code_count, size_t& distance_code_count) +size_t DeflateCompressor::encode_block_lengths(Array<u8, max_huffman_literals> const& literal_bit_lengths, Array<u8, max_huffman_distances> const& distance_bit_lengths, Array<code_length_symbol, max_huffman_literals + max_huffman_distances>& encoded_lengths, size_t& literal_code_count, size_t& distance_code_count) { literal_code_count = max_huffman_literals; distance_code_count = max_huffman_distances; @@ -920,7 +920,7 @@ size_t DeflateCompressor::encode_block_lengths(const Array<u8, max_huffman_liter return encode_huffman_lengths(all_lengths, lengths_count, encoded_lengths); } -void DeflateCompressor::write_dynamic_huffman(const CanonicalCode& literal_code, size_t literal_code_count, const Optional<CanonicalCode>& distance_code, size_t distance_code_count, const Array<u8, 19>& code_lengths_bit_lengths, size_t code_length_count, const Array<code_length_symbol, max_huffman_literals + max_huffman_distances>& encoded_lengths, size_t encoded_lengths_count) +void DeflateCompressor::write_dynamic_huffman(CanonicalCode const& literal_code, size_t literal_code_count, Optional<CanonicalCode> const& distance_code, size_t distance_code_count, Array<u8, 19> const& code_lengths_bit_lengths, size_t code_length_count, Array<code_length_symbol, max_huffman_literals + max_huffman_distances> const& encoded_lengths, size_t encoded_lengths_count) { m_output_stream.write_bits(literal_code_count - 257, 5); m_output_stream.write_bits(distance_code_count - 1, 5); diff --git a/Userland/Libraries/LibCompress/Deflate.h b/Userland/Libraries/LibCompress/Deflate.h index 9d9b51de8b..85e5a811dd 100644 --- a/Userland/Libraries/LibCompress/Deflate.h +++ b/Userland/Libraries/LibCompress/Deflate.h @@ -22,8 +22,8 @@ public: u32 read_symbol(InputBitStream&) const; void write_symbol(OutputBitStream&, u32) const; - static const CanonicalCode& fixed_literal_codes(); - static const CanonicalCode& fixed_distance_codes(); + static CanonicalCode const& fixed_literal_codes(); + static CanonicalCode const& fixed_distance_codes(); static Optional<CanonicalCode> from_bytes(ReadonlyBytes); @@ -157,7 +157,7 @@ private: Bytes pending_block() { return { m_rolling_window + block_size, block_size }; } // LZ77 Compression - static u16 hash_sequence(const u8* bytes); + static u16 hash_sequence(u8 const* bytes); size_t compare_match_candidate(size_t start, size_t candidate, size_t prev_match_length, size_t max_match_length); size_t find_back_match(size_t start, u16 hash, size_t previous_match_length, size_t max_match_length, size_t& match_position); void lz77_compress_block(); @@ -169,16 +169,16 @@ private: }; static u8 distance_to_base(u16 distance); template<size_t Size> - static void generate_huffman_lengths(Array<u8, Size>& lengths, const Array<u16, Size>& frequencies, size_t max_bit_length, u16 frequency_cap = UINT16_MAX); - size_t huffman_block_length(const Array<u8, max_huffman_literals>& literal_bit_lengths, const Array<u8, max_huffman_distances>& distance_bit_lengths); - void write_huffman(const CanonicalCode& literal_code, const Optional<CanonicalCode>& distance_code); - static size_t encode_huffman_lengths(const Array<u8, max_huffman_literals + max_huffman_distances>& lengths, size_t lengths_count, Array<code_length_symbol, max_huffman_literals + max_huffman_distances>& encoded_lengths); - size_t encode_block_lengths(const Array<u8, max_huffman_literals>& literal_bit_lengths, const Array<u8, max_huffman_distances>& distance_bit_lengths, Array<code_length_symbol, max_huffman_literals + max_huffman_distances>& encoded_lengths, size_t& literal_code_count, size_t& distance_code_count); - void write_dynamic_huffman(const CanonicalCode& literal_code, size_t literal_code_count, const Optional<CanonicalCode>& distance_code, size_t distance_code_count, const Array<u8, 19>& code_lengths_bit_lengths, size_t code_length_count, const Array<code_length_symbol, max_huffman_literals + max_huffman_distances>& encoded_lengths, size_t encoded_lengths_count); + static void generate_huffman_lengths(Array<u8, Size>& lengths, Array<u16, Size> const& frequencies, size_t max_bit_length, u16 frequency_cap = UINT16_MAX); + size_t huffman_block_length(Array<u8, max_huffman_literals> const& literal_bit_lengths, Array<u8, max_huffman_distances> const& distance_bit_lengths); + void write_huffman(CanonicalCode const& literal_code, Optional<CanonicalCode> const& distance_code); + static size_t encode_huffman_lengths(Array<u8, max_huffman_literals + max_huffman_distances> const& lengths, size_t lengths_count, Array<code_length_symbol, max_huffman_literals + max_huffman_distances>& encoded_lengths); + size_t encode_block_lengths(Array<u8, max_huffman_literals> const& literal_bit_lengths, Array<u8, max_huffman_distances> const& distance_bit_lengths, Array<code_length_symbol, max_huffman_literals + max_huffman_distances>& encoded_lengths, size_t& literal_code_count, size_t& distance_code_count); + void write_dynamic_huffman(CanonicalCode const& literal_code, size_t literal_code_count, Optional<CanonicalCode> const& distance_code, size_t distance_code_count, Array<u8, 19> const& code_lengths_bit_lengths, size_t code_length_count, Array<code_length_symbol, max_huffman_literals + max_huffman_distances> const& encoded_lengths, size_t encoded_lengths_count); size_t uncompressed_block_length(); size_t fixed_block_length(); - size_t dynamic_block_length(const Array<u8, max_huffman_literals>& literal_bit_lengths, const Array<u8, max_huffman_distances>& distance_bit_lengths, const Array<u8, 19>& code_lengths_bit_lengths, const Array<u16, 19>& code_lengths_frequencies, size_t code_lengths_count); + size_t dynamic_block_length(Array<u8, max_huffman_literals> const& literal_bit_lengths, Array<u8, max_huffman_distances> const& distance_bit_lengths, Array<u8, 19> const& code_lengths_bit_lengths, Array<u16, 19> const& code_lengths_frequencies, size_t code_lengths_count); void flush(); bool m_finished { false }; diff --git a/Userland/Libraries/LibCompress/Gzip.cpp b/Userland/Libraries/LibCompress/Gzip.cpp index f93554d272..924bb7bc9b 100644 --- a/Userland/Libraries/LibCompress/Gzip.cpp +++ b/Userland/Libraries/LibCompress/Gzip.cpp @@ -159,11 +159,11 @@ Optional<String> GzipDecompressor::describe_header(ReadonlyBytes bytes) if (bytes.size() < sizeof(BlockHeader)) return {}; - auto& header = *(reinterpret_cast<const BlockHeader*>(bytes.data())); + auto& header = *(reinterpret_cast<BlockHeader const*>(bytes.data())); if (!header.valid_magic_number() || !header.supported_by_implementation()) return {}; - LittleEndian<u32> original_size = *reinterpret_cast<const u32*>(bytes.offset(bytes.size() - sizeof(u32))); + LittleEndian<u32> original_size = *reinterpret_cast<u32 const*>(bytes.offset(bytes.size() - sizeof(u32))); return String::formatted("last modified: {}, original size {}", Core::DateTime::from_timestamp(header.modification_time).to_string(), (u32)original_size); } @@ -202,7 +202,7 @@ Optional<ByteBuffer> GzipDecompressor::decompress_all(ReadonlyBytes bytes) u8 buffer[4096]; while (!gzip_stream.has_any_error() && !gzip_stream.unreliable_eof()) { - const auto nread = gzip_stream.read({ buffer, sizeof(buffer) }); + auto const nread = gzip_stream.read({ buffer, sizeof(buffer) }); output_stream.write_or_error({ buffer, nread }); } diff --git a/Userland/Libraries/LibCompress/Gzip.h b/Userland/Libraries/LibCompress/Gzip.h index e25b6b0813..c043bcadc4 100644 --- a/Userland/Libraries/LibCompress/Gzip.h +++ b/Userland/Libraries/LibCompress/Gzip.h @@ -68,7 +68,7 @@ private: size_t m_nread { 0 }; }; - const Member& current_member() const { return m_current_member.value(); } + Member const& current_member() const { return m_current_member.value(); } Member& current_member() { return m_current_member.value(); } InputStream& m_input_stream; |