From ec493b128aded68a3a30d52133b0d52b40afa3e1 Mon Sep 17 00:00:00 2001 From: Cal Pratt Date: Mon, 27 Jan 2025 16:17:34 -0500 Subject: [PATCH] Some small fixes --- src/core/common.hpp | 21 ++++++++++-- src/indexed_bzip2/bzip2.hpp | 32 +++++++++---------- src/rapidgzip/CompressedVector.hpp | 2 -- src/rapidgzip/GzipChunkFetcher.hpp | 3 +- src/rapidgzip/ParallelGzipReader.hpp | 1 - src/rapidgzip/gzip/InflateWrapper.hpp | 4 +-- src/tests/rapidgzip/testCLI.cpp | 13 -------- src/tests/rapidgzip/testHuffmanCoding.cpp | 6 ++-- .../rapidgzip/testParallelGzipReader.cpp | 2 +- 9 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/core/common.hpp b/src/core/common.hpp index 8f25602b..a6f8c2db 100644 --- a/src/core/common.hpp +++ b/src/core/common.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -26,8 +27,6 @@ #include #endif -namespace rapidgzip -{ /* Platform dependent stuff */ #ifdef _MSC_VER @@ -46,6 +45,8 @@ namespace rapidgzip #define S_IFIFO _S_IFIFO #define S_IFMT _S_IFMT + namespace rapidgzip + { template [[nodiscard]] bool testFileType( FileMode fileMode, @@ -53,6 +54,7 @@ namespace rapidgzip { return ( fileMode & S_IFMT ) == fileType; } + } // namespace rapidgzip; #define S_ISFIFO( m ) testFileType( m, S_IFIFO ) @@ -71,6 +73,21 @@ namespace rapidgzip #define forceinline __attribute__(( always_inline )) inline #endif +namespace rapidgzip +{ + +std::ostream& +operator<<( std::ostream& out, + const std::set& values ) +{ + out << "{ "; + for ( const auto& value : values ) { + out << value << ", "; + } + out << "}"; + return out; +} + template( hh ); } - const auto error = huffmanCodings[j].initializeFromLengths( VectorView( lengths.data(), symCount ) ); + const auto error = huffmanCodings[j].initializeFromLengths( rapidgzip::VectorView( lengths.data(), symCount ) ); if ( error != rapidgzip::Error::NONE ) { throw std::domain_error( toString( error ) ); } @@ -655,7 +655,7 @@ Block::readBlockData() bwdata.byteCount.fill( 0 ); std::iota( mtfSymbol.begin(), mtfSymbol.end(), 0 ); - const auto t0 = now(); + const auto t0 = rapidgzip::now(); /** @note The loops inside this for-loop are all too short to be profiled. * The overhead becomes disastrously large! It takes 190s to decode instead of 20s. */ // Loop through compressed symbols. This is the first "tight inner loop" @@ -754,11 +754,11 @@ Block::readBlockData() throw std::domain_error( std::move( msg ).str() ); } - statistics.durations.createHuffmanTable += duration( t0 ); + statistics.durations.createHuffmanTable += rapidgzip::duration( t0 ); - const auto tPrepareStart = now(); + const auto tPrepareStart = rapidgzip::now(); bwdata.prepare(); - statistics.durations.burrowsWheelerPreparation += duration( tPrepareStart ); + statistics.durations.burrowsWheelerPreparation += rapidgzip::duration( tPrepareStart ); encodedSizeInBits = bitReader().tell() - encodedOffsetInBits; } diff --git a/src/rapidgzip/CompressedVector.hpp b/src/rapidgzip/CompressedVector.hpp index 03a20027..59307efd 100644 --- a/src/rapidgzip/CompressedVector.hpp +++ b/src/rapidgzip/CompressedVector.hpp @@ -179,8 +179,6 @@ class CompressedVector using InflateWrapper = rapidgzip::ZlibInflateWrapper; #endif - using FileType = rapidgzip::FileType; - const auto decompressWithWrapper = [this] ( FileType fileType ) { return std::make_shared( diff --git a/src/rapidgzip/GzipChunkFetcher.hpp b/src/rapidgzip/GzipChunkFetcher.hpp index 137e451f..4af172ef 100644 --- a/src/rapidgzip/GzipChunkFetcher.hpp +++ b/src/rapidgzip/GzipChunkFetcher.hpp @@ -39,7 +39,6 @@ class GzipChunkFetcher final : using ChunkData = T_ChunkData; using ChunkConfiguration = typename ChunkData::Configuration; using BaseType = BlockFetcher; - using BitReader = rapidgzip::BitReader; using SharedWindow = WindowMap::SharedWindow; using SharedDecompressedWindow = std::shared_ptr >; using WindowView = VectorView; @@ -651,7 +650,7 @@ class GzipChunkFetcher final : * to directly call @ref decodeBlock with that offset. */ chunkData = BaseType::get( blockOffset, blockIndex, getPartitionOffsetFromOffset ); } - catch ( const rapidgzip::BitReader::EndOfFileReached& exception ) + catch ( const BitReader64::EndOfFileReached& exception ) { std::cerr << "Unexpected end of file when getting block at " << formatBits( blockOffset ) << " (block index: " << blockIndex << ") on demand\n"; diff --git a/src/rapidgzip/ParallelGzipReader.hpp b/src/rapidgzip/ParallelGzipReader.hpp index 5ea8d9e9..3df9bc24 100644 --- a/src/rapidgzip/ParallelGzipReader.hpp +++ b/src/rapidgzip/ParallelGzipReader.hpp @@ -83,7 +83,6 @@ class ParallelGzipReader final : */ using ChunkFetcher = rapidgzip::GzipChunkFetcher; using BlockFinder = typename ChunkFetcher::BlockFinder; - using BitReader = rapidgzip::BitReader; using WriteFunctor = std::function&, size_t, size_t )>; using Window = WindowMap::Window; diff --git a/src/rapidgzip/gzip/InflateWrapper.hpp b/src/rapidgzip/gzip/InflateWrapper.hpp index 1818abd1..4b5e36ce 100644 --- a/src/rapidgzip/gzip/InflateWrapper.hpp +++ b/src/rapidgzip/gzip/InflateWrapper.hpp @@ -35,13 +35,11 @@ inflateWithWrapper( const Container& toDecompress, } #endif - rapidgzip::BitReader bitReader( + BitReader64 bitReader( std::make_unique( toDecompress.data(), toDecompress.size() ) ); InflateWrapper inflateWrapper( std::move( bitReader ) ); - using FileType = rapidgzip::FileType; - switch ( fileType ) { case FileType::DEFLATE: diff --git a/src/tests/rapidgzip/testCLI.cpp b/src/tests/rapidgzip/testCLI.cpp index b0260705..925aca19 100644 --- a/src/tests/rapidgzip/testCLI.cpp +++ b/src/tests/rapidgzip/testCLI.cpp @@ -3,19 +3,6 @@ #include #include #include - -std::ostream& -operator<<( std::ostream& out, - const std::set& values ) -{ - out << "{ "; - for ( const auto& value : values ) { - out << value << ", "; - } - out << "}"; - return out; -} - #include #define WITHOUT_MAIN #include diff --git a/src/tests/rapidgzip/testHuffmanCoding.cpp b/src/tests/rapidgzip/testHuffmanCoding.cpp index edac1178..dbf53d03 100644 --- a/src/tests/rapidgzip/testHuffmanCoding.cpp +++ b/src/tests/rapidgzip/testHuffmanCoding.cpp @@ -30,7 +30,7 @@ decodeHuffmanAndCompare( const std::vector& code { BufferedFileReader::AlignedBuffer encodedChars( encoded.size() ); std::transform( encoded.begin(), encoded.end(), encodedChars.begin(), [] ( const auto c ) { return c; } ); - rapidgzip::BitReader bitReader( std::make_unique( std::move( encodedChars ) ) ); + BitReader64 bitReader( std::make_unique( std::move( encodedChars ) ) ); HuffmanCoding coding; const auto errorCode = coding.initializeFromLengths( codeLengths ); @@ -58,7 +58,7 @@ void testHuffmanCodingInvalidDetection() { const std::vector encoded = { 0b0110'1110 }; - rapidgzip::BitReader bitReader( std::make_unique( encoded ) ); + BitReader64 bitReader( std::make_unique( encoded ) ); HuffmanCoding coding; const std::vector codeLengthsHalfBit = { 1 }; @@ -74,7 +74,7 @@ void testHuffmanCodingReuse( bool testOneSymbolCoding = true ) { const std::vector encoded = { 0b0110'1101 }; - rapidgzip::BitReader bitReader( std::make_unique( encoded ) ); + BitReader64 bitReader( std::make_unique( encoded ) ); const std::vector codeLengths2Bit = { 2, 2, 2, 2 }; HuffmanCoding coding; diff --git a/src/tests/rapidgzip/testParallelGzipReader.cpp b/src/tests/rapidgzip/testParallelGzipReader.cpp index a54ba6bd..b9315800 100644 --- a/src/tests/rapidgzip/testParallelGzipReader.cpp +++ b/src/tests/rapidgzip/testParallelGzipReader.cpp @@ -993,7 +993,7 @@ void printClassSizes() { std::cout << "== Rapidgzip class sizes ==\n"; - std::cout << " BitReader : " << sizeof( rapidgzip::BitReader ) << "\n"; // 88 + std::cout << " BitReader : " << sizeof( BitReader64 ) << "\n"; // 88 std::cout << " WindowMap : " << sizeof( WindowMap ) << "\n"; // 88 std::cout << " deflate::DecodedDataView : " << sizeof( deflate::DecodedDataView ) << "\n"; // 64 std::cout << " deflate::DecodedData : " << sizeof( deflate::DecodedData ) << "\n"; // 96