Preserve string length in string map.

This commit is contained in:
Bartosz Taudul 2019-02-12 20:23:14 +01:00
parent 17e1894034
commit 08642d034b
2 changed files with 5 additions and 4 deletions

View File

@ -2114,7 +2114,8 @@ StringLocation Worker::StoreString( char* str, size_t sz )
StringLocation ret;
const char backup = str[sz];
str[sz] = '\0';
auto sit = m_data.stringMap.find( str );
charutil::StringKey key = { str, sz };
auto sit = m_data.stringMap.find( key );
if( sit == m_data.stringMap.end() )
{
auto ptr = m_slab.Alloc<char>( sz+1 );
@ -2122,12 +2123,12 @@ StringLocation Worker::StoreString( char* str, size_t sz )
ptr[sz] = '\0';
ret.ptr = ptr;
ret.idx = m_data.stringData.size();
m_data.stringMap.emplace( ptr, m_data.stringData.size() );
m_data.stringMap.emplace( charutil::StringKey { ptr, sz }, m_data.stringData.size() );
m_data.stringData.push_back( ptr );
}
else
{
ret.ptr = sit->first;
ret.ptr = sit->first.ptr;
ret.idx = sit->second;
}
str[sz] = backup;

View File

@ -118,7 +118,7 @@ private:
flat_hash_map<uint64_t, const char*, nohash<uint64_t>> strings;
Vector<const char*> stringData;
flat_hash_map<const char*, uint32_t, charutil::HasherPOT, charutil::Comparator> stringMap;
flat_hash_map<charutil::StringKey, uint32_t, charutil::StringKey::HasherPOT, charutil::StringKey::Comparator> stringMap;
flat_hash_map<uint64_t, const char*, nohash<uint64_t>> threadNames;
flat_hash_map<uint64_t, SourceLocation, nohash<uint64_t>> sourceLocation;