diff --git a/server/TracyStringDiscovery.hpp b/server/TracyStringDiscovery.hpp new file mode 100644 index 00000000..36e5cd84 --- /dev/null +++ b/server/TracyStringDiscovery.hpp @@ -0,0 +1,80 @@ +#ifndef __TRACYSTRINGDISCOVERY_HPP__ +#define __TRACYSTRINGDISCOVERY_HPP__ + +#include "../common/TracyForceInline.hpp" +#include "tracy_flat_hash_map.hpp" +#include "TracyCharUtil.hpp" +#include "TracyVector.hpp" + +namespace tracy +{ + +template +class StringDiscovery +{ +public: + tracy_force_inline Vector& Data() { return m_data; } + tracy_force_inline const Vector& Data() const { return m_data; } + + tracy_force_inline bool IsPending() const { return !m_pending.empty(); } + + // Merge( destination, postponed ) + tracy_force_inline bool StringDiscovered( uint64_t name, const StringLocation& sl, std::function Merge ) + { + auto pit = m_pending.find( name ); + assert( pit != m_pending.end() ); + + auto it = m_rev.find( sl.ptr ); + bool add = it == m_rev.end(); + if( add ) + { + m_map.emplace( name, pit->second ); + m_rev.emplace( sl.ptr, pit->second ); + m_data.push_back( pit->second ); + } + else + { + auto item = it->second; + m_map.emplace( name, item ); + Merge( item, pit->second ); + } + + m_pending.erase( pit ); + + return add; + } + + tracy_force_inline T Retrieve( uint64_t name, std::function Create, std::function 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 m_data; + flat_hash_map> m_pending; + flat_hash_map> m_map; + flat_hash_map m_rev; +}; + +} + +#endif diff --git a/standalone/build/win32/Tracy.vcxproj b/standalone/build/win32/Tracy.vcxproj index fd2651ad..c5a324aa 100644 --- a/standalone/build/win32/Tracy.vcxproj +++ b/standalone/build/win32/Tracy.vcxproj @@ -139,6 +139,7 @@ + diff --git a/standalone/build/win32/Tracy.vcxproj.filters b/standalone/build/win32/Tracy.vcxproj.filters index 39b02feb..9b336b01 100644 --- a/standalone/build/win32/Tracy.vcxproj.filters +++ b/standalone/build/win32/Tracy.vcxproj.filters @@ -188,6 +188,9 @@ server + + server +