Skip to content

Commit

Permalink
Some small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cal-pratt committed Jan 27, 2025
1 parent 4672868 commit ec493b1
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 43 deletions.
21 changes: 19 additions & 2 deletions src/core/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <memory>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <thread>
Expand All @@ -26,8 +27,6 @@
#include <Python.h>
#endif

namespace rapidgzip
{
/* Platform dependent stuff */

#ifdef _MSC_VER
Expand All @@ -46,13 +45,16 @@ namespace rapidgzip
#define S_IFIFO _S_IFIFO
#define S_IFMT _S_IFMT

namespace rapidgzip
{
template<typename FileMode, typename FileType>
[[nodiscard]] bool
testFileType( FileMode fileMode,
FileType fileType )
{
return ( fileMode & S_IFMT ) == fileType;
}
} // namespace rapidgzip;

#define S_ISFIFO( m ) testFileType( m, S_IFIFO )

Expand All @@ -71,6 +73,21 @@ namespace rapidgzip
#define forceinline __attribute__(( always_inline )) inline
#endif

namespace rapidgzip
{

std::ostream&
operator<<( std::ostream& out,
const std::set<size_t>& values )
{
out << "{ ";
for ( const auto& value : values ) {
out << value << ", ";
}
out << "}";
return out;
}

template<typename I1,
typename I2,
typename Enable = typename std::enable_if<
Expand Down
32 changes: 16 additions & 16 deletions src/indexed_bzip2/bzip2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ struct Block // NOLINT(clang-analyzer-optin.performance.Padding)
read( const size_t nMaxBytesToDecode,
char* outputBuffer )
{
const auto t0 = now();
const auto t0 = rapidgzip::now();
const auto result = bwdata.decodeBlock( nMaxBytesToDecode, outputBuffer );
statistics.durations.decodeBlock += duration( t0 );
statistics.durations.decodeBlock += rapidgzip::duration( t0 );
return result;
}

Expand All @@ -317,16 +317,16 @@ struct Block // NOLINT(clang-analyzer-optin.performance.Padding)
void
readBlockTrees()
{
const auto tReadSymbolMaps = now();
const auto tReadSymbolMaps = rapidgzip::now();
readSymbolMaps();
const auto tReadSelectors = now();
const auto tReadSelectors = rapidgzip::now();
readSelectors();
const auto tReadTrees = now();
const auto tReadTrees = rapidgzip::now();
readTrees();

statistics.durations.readSymbolMaps += duration( tReadSymbolMaps, tReadSelectors );
statistics.durations.readSelectors += duration( tReadSelectors, tReadTrees );
statistics.durations.readTrees += duration( tReadTrees );
statistics.durations.readSymbolMaps += rapidgzip::duration( tReadSymbolMaps, tReadSelectors );
statistics.durations.readSelectors += rapidgzip::duration( tReadSelectors, tReadTrees );
statistics.durations.readTrees += rapidgzip::duration( tReadTrees );
}

void
Expand Down Expand Up @@ -436,7 +436,7 @@ struct Block // NOLINT(clang-analyzer-optin.performance.Padding)
inline void
Block::readBlockHeader()
{
const auto tReadBlockHeader = now();
const auto tReadBlockHeader = rapidgzip::now();

encodedOffsetInBits = bitReader().tell();
encodedSizeInBits = 0;
Expand All @@ -459,7 +459,7 @@ Block::readBlockHeader()
if ( magicBytes != MAGIC_BITS_BLOCK ) {
std::stringstream msg;
msg << "[BZip2 block header] invalid compressed magic 0x" << std::hex << magicBytes
<< " at offset " << formatBits( encodedOffsetInBits );
<< " at offset " << rapidgzip::formatBits( encodedOffsetInBits );
throw std::domain_error( std::move( msg ).str() );
}

Expand All @@ -476,7 +476,7 @@ Block::readBlockHeader()
}

readBlockTrees();
statistics.durations.readBlockHeader += duration( tReadBlockHeader );
statistics.durations.readBlockHeader += rapidgzip::duration( tReadBlockHeader );
}


Expand Down Expand Up @@ -634,7 +634,7 @@ Block::readTrees()
lengths[symbol] = static_cast<uint8_t>( hh );
}

const auto error = huffmanCodings[j].initializeFromLengths( VectorView<uint8_t>( lengths.data(), symCount ) );
const auto error = huffmanCodings[j].initializeFromLengths( rapidgzip::VectorView<uint8_t>( lengths.data(), symCount ) );
if ( error != rapidgzip::Error::NONE ) {
throw std::domain_error( toString( error ) );
}
Expand All @@ -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"
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions src/rapidgzip/CompressedVector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Container>(
Expand Down
3 changes: 1 addition & 2 deletions src/rapidgzip/GzipChunkFetcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class GzipChunkFetcher final :
using ChunkData = T_ChunkData;
using ChunkConfiguration = typename ChunkData::Configuration;
using BaseType = BlockFetcher<GzipBlockFinder, ChunkData, FetchingStrategy>;
using BitReader = rapidgzip::BitReader;
using SharedWindow = WindowMap::SharedWindow;
using SharedDecompressedWindow = std::shared_ptr<const FasterVector<uint8_t> >;
using WindowView = VectorView<uint8_t>;
Expand Down Expand Up @@ -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";
Expand Down
1 change: 0 additions & 1 deletion src/rapidgzip/ParallelGzipReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class ParallelGzipReader final :
*/
using ChunkFetcher = rapidgzip::GzipChunkFetcher<FetchingStrategy::FetchMultiStream, ChunkData>;
using BlockFinder = typename ChunkFetcher::BlockFinder;
using BitReader = rapidgzip::BitReader;
using WriteFunctor = std::function<void ( const std::shared_ptr<ChunkData>&, size_t, size_t )>;
using Window = WindowMap::Window;

Expand Down
4 changes: 1 addition & 3 deletions src/rapidgzip/gzip/InflateWrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ inflateWithWrapper( const Container& toDecompress,
}
#endif

rapidgzip::BitReader bitReader(
BitReader64 bitReader(
std::make_unique<BufferViewFileReader>( toDecompress.data(), toDecompress.size() ) );

InflateWrapper inflateWrapper( std::move( bitReader ) );

using FileType = rapidgzip::FileType;

switch ( fileType )
{
case FileType::DEFLATE:
Expand Down
13 changes: 0 additions & 13 deletions src/tests/rapidgzip/testCLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@
#include <set>
#include <stdexcept>
#include <string>

std::ostream&
operator<<( std::ostream& out,
const std::set<size_t>& values )
{
out << "{ ";
for ( const auto& value : values ) {
out << value << ", ";
}
out << "}";
return out;
}

#include <common.hpp>
#define WITHOUT_MAIN
#include <rapidgzip.cpp>
Expand Down
6 changes: 3 additions & 3 deletions src/tests/rapidgzip/testHuffmanCoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ decodeHuffmanAndCompare( const std::vector<uint8_t>& 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<BufferedFileReader>( std::move( encodedChars ) ) );
BitReader64 bitReader( std::make_unique<BufferedFileReader>( std::move( encodedChars ) ) );

HuffmanCoding coding;
const auto errorCode = coding.initializeFromLengths( codeLengths );
Expand Down Expand Up @@ -58,7 +58,7 @@ void
testHuffmanCodingInvalidDetection()
{
const std::vector<char> encoded = { 0b0110'1110 };
rapidgzip::BitReader bitReader( std::make_unique<BufferViewFileReader>( encoded ) );
BitReader64 bitReader( std::make_unique<BufferViewFileReader>( encoded ) );

HuffmanCoding coding;
const std::vector<uint8_t> codeLengthsHalfBit = { 1 };
Expand All @@ -74,7 +74,7 @@ void
testHuffmanCodingReuse( bool testOneSymbolCoding = true )
{
const std::vector<char> encoded = { 0b0110'1101 };
rapidgzip::BitReader bitReader( std::make_unique<BufferViewFileReader>( encoded ) );
BitReader64 bitReader( std::make_unique<BufferViewFileReader>( encoded ) );

const std::vector<uint8_t> codeLengths2Bit = { 2, 2, 2, 2 };
HuffmanCoding coding;
Expand Down
2 changes: 1 addition & 1 deletion src/tests/rapidgzip/testParallelGzipReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ec493b1

Please sign in to comment.