diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 16dfc16b..24097c5e 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -538,7 +538,7 @@ void View::DispatchProcess( const QueueItem& ev, const char*& ptr ) switch( ev.hdr.type ) { case QueueType::CustomStringData: - AddCustomString( ev.stringTransfer.ptr, std::string( ptr, ptr+sz ) ); + AddCustomString( ev.stringTransfer.ptr, ptr, sz ); break; case QueueType::StringData: AddString( ev.stringTransfer.ptr, std::string( ptr, ptr+sz ) ); @@ -916,26 +916,33 @@ void View::AddThreadString( uint64_t id, std::string&& str ) m_threadNames.emplace( id, std::move( str ) ); } -void View::AddCustomString( uint64_t ptr, const std::string& str ) +void View::AddCustomString( uint64_t ptr, const char* str, size_t sz ) { auto pit = m_pendingCustomStrings.find( ptr ); assert( pit != m_pendingCustomStrings.end() ); - const auto sl = StoreString( str ); + const auto sl = StoreString( str, sz ); m_lock.lock(); GetTextData( *pit->second )->userText = sl.ptr; m_lock.unlock(); m_pendingCustomStrings.erase( pit ); } -View::StringLocation View::StoreString( const std::string& str ) +View::StringLocation View::StoreString( const char* str, size_t sz ) { StringLocation ret; - auto sit = m_stringMap.find( str.c_str() ); + + // TODO: Remove this temporary buffer. Requires custom map implementation. + enum { BufSize = 16*1024 }; + char buf[BufSize]; + assert( sz < BufSize ); + memcpy( buf, str, sz ); + buf[sz] = '\0'; + + auto sit = m_stringMap.find( buf ); if( sit == m_stringMap.end() ) { - const auto sz = str.size(); auto ptr = m_slab.Alloc( sz+1 ); - memcpy( ptr, str.c_str(), sz ); + memcpy( ptr, str, sz ); ptr[sz] = '\0'; ret.ptr = ptr; ret.idx = m_stringData.size(); diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 4062a11a..94e348bf 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -150,12 +150,12 @@ private: void AddString( uint64_t ptr, std::string&& str ); void AddThreadString( uint64_t id, std::string&& str ); - void AddCustomString( uint64_t ptr, const std::string& str ); + void AddCustomString( uint64_t ptr, const char* str, size_t sz ); void AddSourceLocation( const QueueSourceLocation& srcloc ); void AddSourceLocationPayload( uint64_t ptr, const char* data, size_t sz ); void AddMessageData( uint64_t ptr, const char* str, size_t sz ); - StringLocation StoreString( const std::string& str ); + StringLocation StoreString( const char* str, size_t sz ); uint32_t ShrinkSourceLocation( uint64_t srcloc );