mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-22 14:44:34 +00:00
Buffer reads.
This commit is contained in:
parent
1c29367a54
commit
ddf2453cca
@ -1,6 +1,7 @@
|
||||
#ifndef __TRACYFILEREAD_HPP__
|
||||
#define __TRACYFILEREAD_HPP__
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace tracy
|
||||
@ -20,15 +21,36 @@ public:
|
||||
fclose( m_file );
|
||||
}
|
||||
|
||||
size_t Read( void* ptr, size_t size )
|
||||
void Read( void* ptr, size_t size )
|
||||
{
|
||||
return fread( ptr, 1, size, m_file );
|
||||
auto dst = (char*)ptr;
|
||||
while( size > 0 )
|
||||
{
|
||||
if( m_offset == BufSize )
|
||||
{
|
||||
fread( m_buf, 1, BufSize, m_file );
|
||||
m_offset = 0;
|
||||
}
|
||||
|
||||
const auto sz = std::min( size, BufSize - m_offset );
|
||||
memcpy( dst, m_buf + m_offset, sz );
|
||||
m_offset += sz;
|
||||
dst += sz;
|
||||
size -= sz;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
FileRead( FILE* f ) : m_file( f ) {}
|
||||
FileRead( FILE* f )
|
||||
: m_file( f )
|
||||
, m_offset( BufSize )
|
||||
{}
|
||||
|
||||
enum { BufSize = 64 * 1024 };
|
||||
|
||||
FILE* m_file;
|
||||
char m_buf[BufSize];
|
||||
size_t m_offset;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user