Store custom strings as const char*, not std::string.

It would seem that std::string is not moved, but copied, thus
invalidating the pointer.
This commit is contained in:
Bartosz Taudul 2017-09-27 02:36:14 +02:00
parent 537542f682
commit c2926f2a0d
2 changed files with 10 additions and 5 deletions

View File

@ -385,15 +385,19 @@ void View::AddCustomString( uint64_t ptr, std::string&& str )
{
auto pit = m_pendingCustomStrings.find( ptr );
assert( pit != m_pendingCustomStrings.end() );
auto sit = m_customStrings.find( str );
auto sit = m_customStrings.find( str.c_str() );
if( sit == m_customStrings.end() )
{
pit->second->text = str.c_str();
m_customStrings.emplace( std::move( str ) );
const auto sz = str.size();
auto ptr = new char[sz+1];
memcpy( ptr, str.c_str(), sz );
ptr[sz] = '\0';
pit->second->text = ptr;
m_customStrings.emplace( ptr );
}
else
{
pit->second->text = sit->c_str();
pit->second->text = *sit;
}
m_pendingCustomStrings.erase( pit );
}

View File

@ -12,6 +12,7 @@
#include "../common/tracy_lz4.hpp"
#include "../common/TracySocket.hpp"
#include "../common/TracyQueue.hpp"
#include "TracyCharUtil.hpp"
#include "TracyEvent.hpp"
#include "TracySlab.hpp"
#include "TracyVector.hpp"
@ -96,7 +97,7 @@ private:
Vector<ThreadData> m_threads;
std::unordered_map<uint64_t, std::string> m_strings;
std::unordered_map<uint64_t, std::string> m_threadNames;
std::unordered_set<std::string> m_customStrings;
std::unordered_set<const char*, charutil::Hasher, charutil::Comparator> m_customStrings;
std::unordered_map<uint64_t, QueueSourceLocation> m_sourceLocation;
uint64_t m_zonesCnt;