diff --git a/server/TracyFileRead.hpp b/server/TracyFileRead.hpp index d566bc41..89b7bb9f 100644 --- a/server/TracyFileRead.hpp +++ b/server/TracyFileRead.hpp @@ -129,18 +129,13 @@ private: void ReadBig( void* ptr, size_t size ) { - char m_lz4buf[LZ4Size]; auto dst = (char*)ptr; while( size > 0 ) { if( m_offset == BufSize ) { std::swap( m_buf, m_second ); - m_offset = 0; - uint32_t sz; - fread( &sz, 1, sizeof( sz ), m_file ); - fread( m_lz4buf, 1, sz, m_file ); - m_lastBlock = LZ4_decompress_safe_continue( m_stream, m_lz4buf, m_buf, sz, BufSize ); + ReadBlock(); } const auto sz = std::min( size, BufSize - m_offset ); @@ -153,17 +148,12 @@ private: void SkipBig( size_t size ) { - char m_lz4buf[LZ4Size]; while( size > 0 ) { if( m_offset == BufSize ) { std::swap( m_buf, m_second ); - m_offset = 0; - uint32_t sz; - fread( &sz, 1, sizeof( sz ), m_file ); - fread( m_lz4buf, 1, sz, m_file ); - m_lastBlock = LZ4_decompress_safe_continue( m_stream, m_lz4buf, m_buf, sz, BufSize ); + ReadBlock(); } const auto sz = std::min( size, BufSize - m_offset ); @@ -172,6 +162,16 @@ private: } } + void ReadBlock() + { + char m_lz4buf[LZ4Size]; + m_offset = 0; + uint32_t sz; + fread( &sz, 1, sizeof( sz ), m_file ); + fread( m_lz4buf, 1, sz, m_file ); + m_lastBlock = LZ4_decompress_safe_continue( m_stream, m_lz4buf, m_buf, sz, BufSize ); + } + enum { BufSize = 64 * 1024 }; enum { LZ4Size = LZ4_COMPRESSBOUND( BufSize ) };