Perf: Put in a portable std::hash that works with the pool. This turns on the 10-15% perf gain.
This commit is contained in:
parent
96f4911351
commit
1056110c30
@ -86,16 +86,37 @@
|
||||
|
||||
namespace glslang {
|
||||
|
||||
//
|
||||
// Pool version of string.
|
||||
//
|
||||
typedef pool_allocator<char> TStringAllocator;
|
||||
typedef std::basic_string <char, std::char_traits<char>, TStringAllocator> TString;
|
||||
//
|
||||
// Pool version of string.
|
||||
//
|
||||
typedef pool_allocator<char> TStringAllocator;
|
||||
typedef std::basic_string <char, std::char_traits<char>, TStringAllocator> TString;
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
// Repackage the std::hash for use by unordered map/set with a TString key.
|
||||
//struct TStringHash {
|
||||
// size_t operator()(const TString& string) const { return std::hash<TString>()(string); }
|
||||
//};
|
||||
namespace std {
|
||||
|
||||
template<> struct hash<glslang::TString> {
|
||||
std::size_t operator()(const glslang::TString& s) const
|
||||
{
|
||||
const unsigned _FNV_offset_basis = 2166136261U;
|
||||
const unsigned _FNV_prime = 16777619U;
|
||||
unsigned _Val = _FNV_offset_basis;
|
||||
unsigned _Count = s.size();
|
||||
const char* _First = s.c_str();
|
||||
for (unsigned _Next = 0; _Next < _Count; ++_Next)
|
||||
{
|
||||
_Val ^= (unsigned)_First[_Next];
|
||||
_Val *= _FNV_prime;
|
||||
}
|
||||
|
||||
return _Val;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace glslang {
|
||||
|
||||
inline TString* NewPoolTString(const char* s)
|
||||
{
|
||||
|
||||
@ -306,8 +306,7 @@ protected:
|
||||
TInputScanner* currentScanner;
|
||||
int numErrors; // number of compile-time errors encountered
|
||||
bool parsingBuiltins; // true if parsing built-in symbols/functions
|
||||
// need portable TStringHash TUnorderedMap<TString, TExtensionBehavior, TStringHash> extensionBehavior; // for each extension string, what its current behavior is set to
|
||||
TMap<TString, TExtensionBehavior> extensionBehavior; // for each extension string, what its current behavior is set to
|
||||
TUnorderedMap<TString, TExtensionBehavior> extensionBehavior; // for each extension string, what its current behavior is set to
|
||||
static const int maxSamplerIndex = EsdNumDims * (EbtNumTypes * (2 * 2 * 2)); // see computeSamplerTypeIndex()
|
||||
TPrecisionQualifier defaultSamplerPrecision[maxSamplerIndex];
|
||||
bool afterEOF;
|
||||
|
||||
@ -192,7 +192,6 @@ public:
|
||||
};
|
||||
|
||||
MemoryPool *pool;
|
||||
// need portable hash typedef TUnorderedMap<int, Symbol*> TSymbolMap;
|
||||
typedef TMap<int, Symbol*> TSymbolMap;
|
||||
TSymbolMap symbols; // this has light use... just defined macros
|
||||
|
||||
@ -437,8 +436,7 @@ protected:
|
||||
//
|
||||
// From PpAtom.cpp
|
||||
//
|
||||
// need portable TStringHash typedef TUnorderedMap<const TString, int, TStringHash> TAtomMap;
|
||||
typedef TMap<const TString, int> TAtomMap;
|
||||
typedef TUnorderedMap<TString, int> TAtomMap;
|
||||
typedef TVector<const TString*> TStringMap;
|
||||
TAtomMap atomMap;
|
||||
TStringMap stringMap;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user