Split read/write functions into small and big variants.

This commit is contained in:
Bartosz Taudul 2018-03-17 13:57:32 +01:00
parent 79418d0c57
commit 41d8ca0814
2 changed files with 57 additions and 37 deletions

View File

@ -29,11 +29,30 @@ public:
tracy_force_inline void Read( void* ptr, size_t size )
{
if( size <= BufSize - m_offset )
{
ReadSmall( ptr, size );
}
else
{
ReadBig( ptr, size );
}
}
private:
FileRead( FILE* f )
: m_stream( LZ4_createStreamDecode() )
, m_file( f )
, m_offset( BufSize )
, m_active( 1 )
{}
tracy_force_inline void ReadSmall( void* ptr, size_t size )
{
memcpy( ptr, m_buf[m_active] + m_offset, size );
m_offset += size;
}
else
void ReadBig( void* ptr, size_t size )
{
auto dst = (char*)ptr;
while( size > 0 )
@ -55,15 +74,6 @@ public:
size -= sz;
}
}
}
private:
FileRead( FILE* f )
: m_stream( LZ4_createStreamDecode() )
, m_file( f )
, m_offset( BufSize )
, m_active( 1 )
{}
enum { BufSize = 64 * 1024 };
enum { LZ4Size = LZ4_COMPRESSBOUND( BufSize ) };

View File

@ -33,11 +33,30 @@ public:
tracy_force_inline void Write( const void* ptr, size_t size )
{
if( m_offset + size <= BufSize )
{
WriteSmall( ptr, size );
}
else
{
WriteBig( ptr, size );
}
}
private:
FileWrite( FILE* f )
: m_stream( LZ4_createStream() )
, m_file( f )
, m_offset( 0 )
, m_active( 0 )
{}
tracy_force_inline void WriteSmall( const void* ptr, size_t size )
{
memcpy( m_buf[m_active] + m_offset, ptr, size );
m_offset += size;
}
else
void WriteBig( const void* ptr, size_t size )
{
auto src = (const char*)ptr;
while( size > 0 )
@ -54,15 +73,6 @@ public:
}
}
}
}
private:
FileWrite( FILE* f )
: m_stream( LZ4_createStream() )
, m_file( f )
, m_offset( 0 )
, m_active( 0 )
{}
void WriteLz4Block()
{