From ecc9369da23b774e894efc3343179a4e17305a5c Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 20 Feb 2020 23:39:40 +0100 Subject: [PATCH] Return zone extra during allocation. --- server/TracyWorker.cpp | 16 +++++++++++----- server/TracyWorker.hpp | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index ba768022..f285dcc4 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -5287,8 +5287,7 @@ void Worker::ReadTimelinePre063( FileRead& f, Vector>& _vec zone->extra = 0; if( extra.callstack.Val() != 0 || extra.name.Active() || extra.text.Active() ) { - AllocZoneExtra( *zone ); - memcpy( &GetZoneExtraMutable( *zone ), &extra, sizeof( ZoneExtra ) ); + memcpy( &AllocZoneExtra( *zone ), &extra, sizeof( ZoneExtra ) ); } refTime += zone->_end_child1; zone->SetStart( refTime - m_data.baseTime ); @@ -5979,18 +5978,25 @@ const Worker::CpuThreadTopology* Worker::GetThreadTopology( uint32_t cpuThread ) return &it->second; } -void Worker::AllocZoneExtra( ZoneEvent& ev ) +ZoneExtra& Worker::AllocZoneExtra( ZoneEvent& ev ) { assert( ev.extra == 0 ); ev.extra = uint32_t( m_data.zoneExtra.size() ); auto& extra = m_data.zoneExtra.push_next(); memset( &extra, 0, sizeof( extra ) ); + return extra; } ZoneExtra& Worker::RequestZoneExtra( ZoneEvent& ev ) { - if( !HasZoneExtra( ev ) ) AllocZoneExtra( ev ); - return GetZoneExtraMutable( ev ); + if( !HasZoneExtra( ev ) ) + { + return AllocZoneExtra( ev ); + } + else + { + return GetZoneExtraMutable( ev ); + } } } diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 66f45066..fb0f53f3 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -630,7 +630,7 @@ private: #endif tracy_force_inline ZoneExtra& GetZoneExtraMutable( const ZoneEvent& ev ) { return m_data.zoneExtra[ev.extra]; } - tracy_force_inline void AllocZoneExtra( ZoneEvent& ev ); + tracy_force_inline ZoneExtra& AllocZoneExtra( ZoneEvent& ev ); tracy_force_inline ZoneExtra& RequestZoneExtra( ZoneEvent& ev ); int64_t ReadTimeline( FileRead& f, Vector>& vec, uint32_t size, int64_t refTime, int32_t& childIdx );