Don't call ReadTimeline() when there's nothing to read.

This commit is contained in:
Bartosz Taudul 2018-03-15 22:54:10 +01:00
parent 9dfa9c95cb
commit 81ff554c7d
3 changed files with 35 additions and 10 deletions

View File

@ -170,6 +170,11 @@ public:
void reserve( size_t cap ) void reserve( size_t cap )
{ {
if( cap == 0 || cap <= Capacity() ) return; if( cap == 0 || cap <= Capacity() ) return;
reserve_non_zero( cap );
}
void reserve_non_zero( size_t cap )
{
cap--; cap--;
cap |= cap >> 1; cap |= cap >> 1;
cap |= cap >> 2; cap |= cap >> 2;

View File

@ -1549,11 +1549,29 @@ void Worker::ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec )
{ {
uint64_t sz; uint64_t sz;
f.Read( &sz, sizeof( sz ) ); f.Read( &sz, sizeof( sz ) );
vec.reserve( sz ); if( sz != 0 )
{
ReadTimeline( f, vec, sz );
}
}
m_data.zonesCnt += sz; void Worker::ReadTimeline( FileRead& f, Vector<GpuEvent*>& vec )
{
uint64_t sz;
f.Read( &sz, sizeof( sz ) );
if( sz != 0 )
{
ReadTimeline( f, vec, sz );
}
}
for( uint64_t i=0; i<sz; i++ ) void Worker::ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec, uint64_t size )
{
assert( size != 0 );
vec.reserve_non_zero( size );
m_data.zonesCnt += size;
for( uint64_t i=0; i<size; i++ )
{ {
auto zone = m_slab.AllocInit<ZoneEvent>(); auto zone = m_slab.AllocInit<ZoneEvent>();
vec.push_back_no_space_check( zone ); vec.push_back_no_space_check( zone );
@ -1563,13 +1581,12 @@ void Worker::ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec )
} }
} }
void Worker::ReadTimeline( FileRead& f, Vector<GpuEvent*>& vec ) void Worker::ReadTimeline( FileRead& f, Vector<GpuEvent*>& vec, uint64_t size )
{ {
uint64_t sz; assert( size != 0 );
f.Read( &sz, sizeof( sz ) ); vec.reserve_non_zero( size );
vec.reserve( sz );
for( uint64_t i=0; i<sz; i++ ) for( uint64_t i=0; i<size; i++ )
{ {
auto zone = m_slab.AllocInit<GpuEvent>(); auto zone = m_slab.AllocInit<GpuEvent>();
vec.push_back_no_space_check( zone ); vec.push_back_no_space_check( zone );

View File

@ -171,8 +171,11 @@ private:
StringLocation StoreString( char* str, size_t sz ); StringLocation StoreString( char* str, size_t sz );
void ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec ); tracy_force_inline void ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec );
void ReadTimeline( FileRead& f, Vector<GpuEvent*>& vec ); tracy_force_inline void ReadTimeline( FileRead& f, Vector<GpuEvent*>& vec );
void ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec, uint64_t size );
void ReadTimeline( FileRead& f, Vector<GpuEvent*>& vec, uint64_t size );
void WriteTimeline( FileWrite& f, const Vector<ZoneEvent*>& vec ); void WriteTimeline( FileWrite& f, const Vector<ZoneEvent*>& vec );
void WriteTimeline( FileWrite& f, const Vector<GpuEvent*>& vec ); void WriteTimeline( FileWrite& f, const Vector<GpuEvent*>& vec );