From 87467a472c11e4c749de2de945648152f08752ee Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Tue, 19 Jun 2018 20:54:46 +0200 Subject: [PATCH] Add variable sized const array. --- server/TracyVarArray.hpp | 92 ++++++++++++++++++++ standalone/build/win32/DebugVis.natvis | 9 ++ standalone/build/win32/Tracy.vcxproj | 1 + standalone/build/win32/Tracy.vcxproj.filters | 3 + 4 files changed, 105 insertions(+) create mode 100644 server/TracyVarArray.hpp diff --git a/server/TracyVarArray.hpp b/server/TracyVarArray.hpp new file mode 100644 index 00000000..7d2f7fd8 --- /dev/null +++ b/server/TracyVarArray.hpp @@ -0,0 +1,92 @@ +#ifndef __TRACYVARARRAY_HPP__ +#define __TRACYVARARRAY_HPP__ + +#include + +#include "../common/TracyForceInline.hpp" +#include "tracy_flat_hash_map.hpp" +#include "TracyCharUtil.hpp" +#include "TracyMemory.hpp" + +namespace tracy +{ + +#pragma pack( 1 ) +template +class VarArray +{ +public: + VarArray( uint8_t size, const T* data ) + : m_size( size ) + , m_hash( charutil::hash( (const char*)data, size * sizeof( T ) ) ) + , m_ptr( data ) + { + } + + VarArray( const VarArray& ) = delete; + VarArray( VarArray&& ) = delete; + + VarArray& operator=( const VarArray& ) = delete; + VarArray& operator=( VarArray&& ) = delete; + + tracy_force_inline uint32_t get_hash() const { return m_hash; } + + tracy_force_inline bool empty() const { return m_size == 0; } + tracy_force_inline uint8_t size() const { return m_size; } + + tracy_force_inline const T* data() const { return m_ptr; }; + + tracy_force_inline const T* begin() const { return m_ptr; } + tracy_force_inline const T* end() const { return m_ptr + m_size; } + + tracy_force_inline const T& front() const { assert( m_size > 0 ); return m_ptr[0]; } + tracy_force_inline const T& back() const { assert( m_size > 0 ); return m_ptr[m_size - 1]; } + + tracy_force_inline const T& operator[]( size_t idx ) const { return m_ptr[idx]; } + +private: + uint8_t m_size; + uint32_t m_hash; + const T* m_ptr; +}; +#pragma pack() + +template +bool Compare( const VarArray& lhs, const VarArray& rhs ) +{ + if( lhs.size() != rhs.size() || lhs.get_hash() != rhs.get_hash() ) return false; + const auto sz = lhs.size(); + for( uint8_t i=0; i +struct VarArrayHasher +{ + size_t operator()( const VarArray* arr ) const + { + return arr->get_hash(); + } +}; + +template +struct VarArrayHasherPOT : public VarArrayHasher +{ + typedef tracy::power_of_two_hash_policy hash_policy; +}; + +template +struct VarArrayComparator +{ + bool operator()( const VarArray* lhs, const VarArray* rhs ) const + { + return Compare( *lhs, *rhs ); + } +}; + +} + +#endif diff --git a/standalone/build/win32/DebugVis.natvis b/standalone/build/win32/DebugVis.natvis index 783fdc4d..bd0d15da 100644 --- a/standalone/build/win32/DebugVis.natvis +++ b/standalone/build/win32/DebugVis.natvis @@ -10,4 +10,13 @@ + + {{ size={m_size} hash={m_hash} }} + + + m_size + m_ptr + + + diff --git a/standalone/build/win32/Tracy.vcxproj b/standalone/build/win32/Tracy.vcxproj index bcc8b7f6..229f6ef7 100644 --- a/standalone/build/win32/Tracy.vcxproj +++ b/standalone/build/win32/Tracy.vcxproj @@ -132,6 +132,7 @@ + diff --git a/standalone/build/win32/Tracy.vcxproj.filters b/standalone/build/win32/Tracy.vcxproj.filters index 6982ab8b..051bdd51 100644 --- a/standalone/build/win32/Tracy.vcxproj.filters +++ b/standalone/build/win32/Tracy.vcxproj.filters @@ -176,6 +176,9 @@ server + + server +