2018-08-04 14:25:11 +00:00
|
|
|
#ifndef __TRACYSTRINGDISCOVERY_HPP__
|
|
|
|
#define __TRACYSTRINGDISCOVERY_HPP__
|
|
|
|
|
|
|
|
#include "../common/TracyForceInline.hpp"
|
2020-01-28 20:49:36 +00:00
|
|
|
#include "tracy_robin_hood.h"
|
2018-08-04 14:25:11 +00:00
|
|
|
#include "TracyCharUtil.hpp"
|
2022-04-26 19:23:22 +00:00
|
|
|
#include "TracyEvent.hpp"
|
2018-08-04 14:25:11 +00:00
|
|
|
#include "TracyVector.hpp"
|
|
|
|
|
|
|
|
namespace tracy
|
|
|
|
{
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class StringDiscovery
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
tracy_force_inline Vector<T>& Data() { return m_data; }
|
|
|
|
tracy_force_inline const Vector<T>& Data() const { return m_data; }
|
|
|
|
|
|
|
|
tracy_force_inline bool IsPending() const { return !m_pending.empty(); }
|
|
|
|
|
|
|
|
// Merge( destination, postponed )
|
2018-08-04 15:10:45 +00:00
|
|
|
template<typename U>
|
|
|
|
tracy_force_inline void StringDiscovered( uint64_t name, const StringLocation& sl, U& stringMap, std::function<void(T,T)> Merge )
|
2018-08-04 14:25:11 +00:00
|
|
|
{
|
|
|
|
auto pit = m_pending.find( name );
|
|
|
|
assert( pit != m_pending.end() );
|
|
|
|
|
|
|
|
auto it = m_rev.find( sl.ptr );
|
2018-08-04 15:10:45 +00:00
|
|
|
if( it == m_rev.end() )
|
2018-08-04 14:25:11 +00:00
|
|
|
{
|
|
|
|
m_map.emplace( name, pit->second );
|
|
|
|
m_rev.emplace( sl.ptr, pit->second );
|
|
|
|
m_data.push_back( pit->second );
|
2018-08-04 15:10:45 +00:00
|
|
|
stringMap.emplace( name, sl.ptr );
|
2018-08-04 14:25:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto item = it->second;
|
|
|
|
m_map.emplace( name, item );
|
|
|
|
Merge( item, pit->second );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pending.erase( pit );
|
|
|
|
}
|
|
|
|
|
|
|
|
tracy_force_inline T Retrieve( uint64_t name, std::function<T(uint64_t)> Create, std::function<void(uint64_t)> Query )
|
|
|
|
{
|
|
|
|
auto it = m_map.find( name );
|
|
|
|
if( it == m_map.end() )
|
|
|
|
{
|
|
|
|
auto pit = m_pending.find( name );
|
|
|
|
if( pit == m_pending.end() )
|
|
|
|
{
|
|
|
|
T item = Create( name );
|
|
|
|
m_pending.emplace( name, item );
|
|
|
|
Query( name );
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return pit->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Vector<T> m_data;
|
2020-01-28 20:49:36 +00:00
|
|
|
unordered_flat_map<uint64_t, T> m_pending;
|
|
|
|
unordered_flat_map<uint64_t, T> m_map;
|
|
|
|
unordered_flat_map<const char*, T, charutil::Hasher, charutil::Comparator> m_rev;
|
2018-08-04 14:25:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|