1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-19 20:16:10 +08:00

Improve CUtlStringToken string constructor

Prevent hashing attempts on emtpy or null strings
This commit is contained in:
GAMMACASE
2024-10-04 03:25:10 +03:00
parent 40a9bb9c02
commit 9f1d960f6a

View File

@ -31,13 +31,17 @@ class CUtlStringToken
{
public:
FORCEINLINE CUtlStringToken( uint32 nHashCode = 0 ) : m_nHashCode( nHashCode ) {}
FORCEINLINE CUtlStringToken( const char *str ) : m_nHashCode( MurmurHash2LowerCase( str, STRINGTOKEN_MURMURHASH_SEED ) )
FORCEINLINE CUtlStringToken( const char *str ) : m_nHashCode( 0 )
{
if(str && *str)
{
m_nHashCode = MurmurHash2LowerCase( str, STRINGTOKEN_MURMURHASH_SEED );
if(g_bUpdateStringTokenDatabase)
{
RegisterStringToken( m_nHashCode, str, 0, true );
}
}
}
FORCEINLINE bool operator==( CUtlStringToken const &other ) const { return ( other.m_nHashCode == m_nHashCode ); }
FORCEINLINE bool operator!=( CUtlStringToken const &other ) const { return !operator==( other ); }