diff --git a/AMBuildScript b/AMBuildScript index 0cd89365..0d2670ea 100644 --- a/AMBuildScript +++ b/AMBuildScript @@ -93,6 +93,8 @@ class SDKConfig(object): '-Wno-tautological-overlap-compare', '-Wno-tautological-constant-out-of-range-compare', '-Wno-undefined-bool-conversion', + '-Wno-nontrivial-memcall', + '-Wno-sync-alignment', '-msse', '-fPIC' ] diff --git a/public/tier1/KeyValues.h b/public/tier1/KeyValues.h index 838bf0b8..e7fa52f3 100644 --- a/public/tier1/KeyValues.h +++ b/public/tier1/KeyValues.h @@ -109,11 +109,14 @@ public: KeyValues( const char *setName, const char *firstKey, int firstValue ); KeyValues( const char *setName, const char *firstKey, const char *firstValue, const char *secondKey, const char *secondValue ); KeyValues( const char *setName, const char *firstKey, int firstValue, const char *secondKey, int secondValue ); + KeyValues( const char *setName, bool bUsesLocalStorage ); // Section name const char *GetName() const; void SetName( const char *setName); + bool IsUsingLocalStorage() const { return m_bIsUsingLocalStringTable != 0; } + // gets the name as a unique int int GetNameSymbol() const { return m_iKeyName; } @@ -330,12 +333,14 @@ private: char m_iDataType; char m_bHasEscapeSequences; // true, if while parsing this KeyValue, Escape Sequences are used (default false) char m_bEvaluateConditionals; // true, if while parsing this KeyValue, conditionals blocks are evaluated (default true) - char unused[1]; + char m_bIsUsingLocalStringTable; // true if this node uses a per-instance growable string table KeyValues *m_pPeer; // pointer to next key in list KeyValues *m_pSub; // pointer to Start of a new sub key list KeyValues *m_pChain;// Search here if it's not in our list + CKeyValuesGrowableStringTable *m_pLocalStringTable; + private: // Statics to implement the optional growable string table // Function pointers that will determine which mode we are in diff --git a/tier1/KeyValues.cpp b/tier1/KeyValues.cpp index f394bebe..f83f3b8e 100644 --- a/tier1/KeyValues.cpp +++ b/tier1/KeyValues.cpp @@ -229,7 +229,7 @@ static CLeakTrack track; class CKeyValuesGrowableStringTable { public: - // Constructor + // Constructor for global singleton string table CKeyValuesGrowableStringTable() : m_hashLookup( 2048, 0, 0, m_Functor, m_Functor ), #ifdef PLATFORM_64BITS @@ -241,6 +241,14 @@ public: m_vecStrings.AddToTail( '\0' ); } + // Constructor for per-instance string table + CKeyValuesGrowableStringTable( int nInitialStringCapacity ) : + m_hashLookup( 16, 0, 0, m_Functor, m_Functor ), + m_vecStrings( 0, nInitialStringCapacity ) + { + m_vecStrings.AddToTail( '\0' ); + } + // Translates a string to an index int GetSymbolForString( const char *name, bool bCreate = true ) { @@ -381,6 +389,22 @@ KeyValues::KeyValues( const char *setName ) SetName ( setName ); } +//----------------------------------------------------------------------------- +// Purpose: Constructor with optional per-instance string table +//----------------------------------------------------------------------------- +KeyValues::KeyValues( const char *setName, bool bUsesLocalStorage ) +{ + TRACK_KV_ADD( this, setName ); + + Init(); + if ( bUsesLocalStorage ) + { + m_pLocalStringTable = new CKeyValuesGrowableStringTable( 256 ); + m_bIsUsingLocalStringTable = true; + } + SetName( setName ); +} + //----------------------------------------------------------------------------- // Purpose: Constructor //----------------------------------------------------------------------------- @@ -461,9 +485,8 @@ void KeyValues::Init() m_bHasEscapeSequences = false; m_bEvaluateConditionals = true; - - // for future proof - memset( unused, 0, sizeof(unused) ); + m_bIsUsingLocalStringTable = false; + m_pLocalStringTable = NULL; } //----------------------------------------------------------------------------- @@ -501,6 +524,8 @@ void KeyValues::RemoveEverything() m_sValue = NULL; delete [] m_wsValue; m_wsValue = NULL; + delete m_pLocalStringTable; + m_pLocalStringTable = NULL; } //----------------------------------------------------------------------------- @@ -528,6 +553,11 @@ void KeyValues::ChainKeyValue( KeyValues* pChain ) //----------------------------------------------------------------------------- const char *KeyValues::GetName( void ) const { + if ( m_bIsUsingLocalStringTable ) + { + Assert( m_pLocalStringTable ); + return m_pLocalStringTable->GetStringForSymbol( m_iKeyName ); + } return s_pfGetStringForSymbol( m_iKeyName ); }