diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 7f9214c8..e177cfad 100644 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -117,11 +117,11 @@ protected: const glslang::TIntermediate* glslangIntermediate; spv::Id stdBuiltins; - std::map symbolValues; - std::set constReadOnlyParameters; // set of formal function parameters that have glslang qualifier constReadOnly, so we know they are not local function "const" that are write-once - std::map functionMap; - std::map structMap; - std::map > memberRemapper; // for mapping glslang block indices to spv indices (e.g., due to hidden members) + std::unordered_map symbolValues; + std::unordered_set constReadOnlyParameters; // set of formal function parameters that have glslang qualifier constReadOnly, so we know they are not local function "const" that are write-once + std::unordered_map functionMap; + std::unordered_map structMap; + std::unordered_map > memberRemapper; // for mapping glslang block indices to spv indices (e.g., due to hidden members) std::stack breakForLoop; // false means break for switch std::stack loopTerminal; // code from the last part of a for loop: for(...; ...; terminal), needed for e.g., continue }; }; @@ -361,8 +361,8 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(const glslang::TIntermediate* gls builder.addEntryPoint(executionModel, shaderEntry); // Add the source extensions - const std::set& sourceExtensions = glslangIntermediate->getRequestedExtensions(); - for (std::set::const_iterator it = sourceExtensions.begin(); it != sourceExtensions.end(); ++it) + const auto& sourceExtensions = glslangIntermediate->getRequestedExtensions(); + for (auto it = sourceExtensions.begin(); it != sourceExtensions.end(); ++it) builder.addSourceExtension(it->c_str()); // Add the top-level modes for this shader. @@ -2385,8 +2385,7 @@ spv::Id TGlslangToSpvTraverser::createNoArgOperation(glslang::TOperator op) spv::Id TGlslangToSpvTraverser::getSymbolId(const glslang::TIntermSymbol* symbol) { - std::map::iterator iter; - iter = symbolValues.find(symbol->getId()); + auto iter = symbolValues.find(symbol->getId()); spv::Id id; if (symbolValues.end() != iter) { id = iter->second; diff --git a/glslang/Include/Common.h b/glslang/Include/Common.h index 0940f30a..f57a36be 100644 --- a/glslang/Include/Common.h +++ b/glslang/Include/Common.h @@ -59,8 +59,10 @@ #endif #include +#include #include #include +#include #include #include #include @@ -82,10 +84,6 @@ void operator delete[](void*) { } \ void operator delete[](void *, void *) { } -#define TBaseMap std::map -#define TBaseList std::list -#define TBaseSet std::set - namespace glslang { // @@ -93,10 +91,15 @@ namespace glslang { // typedef pool_allocator TStringAllocator; typedef std::basic_string , TStringAllocator> TString; + +struct TStringHash { + size_t operator()(const TString& string) const { return std::hash()(string); } +}; + inline TString* NewPoolTString(const char* s) { - void* memory = GetThreadPoolAllocator().allocate(sizeof(TString)); - return new(memory) TString(s); + void* memory = GetThreadPoolAllocator().allocate(sizeof(TString)); + return new(memory) TString(s); } template inline T* NewPoolObject(T) @@ -123,28 +126,32 @@ public: TVector(size_type i, const T& val) : std::vector >(i, val) {} }; -template class TList : public TBaseList > { +template class TList : public std::list > { public: - typedef typename TBaseList >::size_type size_type; - TList() : TBaseList >() {} - TList(const pool_allocator& a) : TBaseList >(a) {} - TList(size_type i): TBaseList >(i) {} + typedef typename std::list >::size_type size_type; + TList() : std::list >() {} + TList(const pool_allocator& a) : std::list >(a) {} + TList(size_type i): std::list >(i) {} }; -// This is called TStlSet, because TSet is taken by an existing compiler class. -template class TStlSet : public std::set > { - // No pool allocator versions of constructors in std::set. -}; - - template > -class TMap : public TBaseMap > > { +class TMap : public std::map > > { public: typedef pool_allocator > tAllocator; - TMap() : TBaseMap() {} + TMap() : std::map() {} // use correct two-stage name lookup supported in gcc 3.4 and above - TMap(const tAllocator& a) : TBaseMap(TBaseMap::key_compare(), a) {} + TMap(const tAllocator& a) : std::map(TBaseMap::key_compare(), a) {} +}; + +template , class PRED = std::equal_to > +class TUnorderedMap : public std::unordered_map > > { +public: + typedef pool_allocator > tAllocator; + + TUnorderedMap() : std::unordered_map() {} + // use correct two-stage name lookup supported in gcc 3.4 and above + TUnorderedMap(const tAllocator& a) : std::unordered_map(TBaseMap::key_compare(), a) {} }; // @@ -184,7 +191,6 @@ struct TSourceLoc { }; typedef TMap TPragmaTable; -typedef TMap::tAllocator TPragmaTableAllocator; const int GlslangMaxTokenLength = 1024; diff --git a/glslang/Include/Types.h b/glslang/Include/Types.h index 1e8b24c3..5cac73ee 100644 --- a/glslang/Include/Types.h +++ b/glslang/Include/Types.h @@ -849,9 +849,6 @@ public: } }; -typedef std::map TStructureMap; -typedef std::map::const_iterator TStructureMapIterator; - // // Base class for things that have a type. // @@ -957,7 +954,6 @@ public: if (copyOf.structure) { structure = new TTypeList; - TStructureMapIterator iter; for (unsigned int i = 0; i < copyOf.structure->size(); ++i) { TTypeLoc typeLoc; typeLoc.loc = (*copyOf.structure)[i].loc; diff --git a/glslang/MachineIndependent/ParseHelper.h b/glslang/MachineIndependent/ParseHelper.h index 176bcf7b..0680f27f 100644 --- a/glslang/MachineIndependent/ParseHelper.h +++ b/glslang/MachineIndependent/ParseHelper.h @@ -48,10 +48,10 @@ namespace glslang { struct TPragma { - TPragma(bool o, bool d) : optimize(o), debug(d) { } - bool optimize; - bool debug; - TPragmaTable pragmaTable; + TPragma(bool o, bool d) : optimize(o), debug(d) { } + bool optimize; + bool debug; + TPragmaTable pragmaTable; }; class TScanContext; @@ -306,7 +306,7 @@ protected: TInputScanner* currentScanner; int numErrors; // number of compile-time errors encountered bool parsingBuiltins; // true if parsing built-in symbols/functions - TMap extensionBehavior; // for each extension string, what its current behavior is set to + std::unordered_map 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; diff --git a/glslang/MachineIndependent/Scan.cpp b/glslang/MachineIndependent/Scan.cpp index 34f35ae8..8b22cdbb 100644 --- a/glslang/MachineIndependent/Scan.cpp +++ b/glslang/MachineIndependent/Scan.cpp @@ -39,6 +39,8 @@ // #include +#include +#include #include "../Include/Types.h" #include "SymbolTable.h" @@ -293,8 +295,8 @@ namespace { // A single global usable by all threads, by all versions, by all languages. // After a single process-level initialization, this is read only and thread safe -std::map* KeywordMap = 0; -std::set* ReservedSet = 0; +std::unordered_map* KeywordMap = 0; +std::unordered_set* ReservedSet = 0; }; @@ -307,7 +309,7 @@ void TScanContext::fillInKeywordMap() // but, the only risk is if two threads called simultaneously return; } - KeywordMap = new std::map; + KeywordMap = new std::unordered_map; (*KeywordMap)["const"] = CONST; (*KeywordMap)["uniform"] = UNIFORM; @@ -476,7 +478,7 @@ void TScanContext::fillInKeywordMap() (*KeywordMap)["resource"] = RESOURCE; (*KeywordMap)["superp"] = SUPERP; - ReservedSet = new std::set; + ReservedSet = new std::unordered_set; ReservedSet->insert("common"); ReservedSet->insert("partition"); @@ -610,7 +612,7 @@ int TScanContext::tokenizeIdentifier() if (ReservedSet->find(tokenText) != ReservedSet->end()) return reservedWord(); - std::map::const_iterator it = KeywordMap->find(tokenText); + auto it = KeywordMap->find(tokenText); if (it == KeywordMap->end()) { // Should have an identifier of some sort return identifierOrType(); diff --git a/glslang/MachineIndependent/Versions.cpp b/glslang/MachineIndependent/Versions.cpp index 6f5b9c88..c525912c 100644 --- a/glslang/MachineIndependent/Versions.cpp +++ b/glslang/MachineIndependent/Versions.cpp @@ -441,7 +441,7 @@ void TParseContext::requireExtensions(TSourceLoc loc, int numExtensions, const c TExtensionBehavior TParseContext::getExtensionBehavior(const char* extension) { - TMap::iterator iter = extensionBehavior.find(TString(extension)); + auto iter = extensionBehavior.find(TString(extension)); if (iter == extensionBehavior.end()) return EBhMissing; else @@ -527,19 +527,18 @@ void TParseContext::updateExtensionBehavior(int line, const char* extension, con void TParseContext::updateExtensionBehavior(const char* extension, TExtensionBehavior behavior) { // Update the current behavior - TMap::iterator iter; if (strcmp(extension, "all") == 0) { // special case for the 'all' extension; apply it to every extension present if (behavior == EBhRequire || behavior == EBhEnable) { error(getCurrentLoc(), "extension 'all' cannot have 'require' or 'enable' behavior", "#extension", ""); return; } else { - for (iter = extensionBehavior.begin(); iter != extensionBehavior.end(); ++iter) + for (auto iter = extensionBehavior.begin(); iter != extensionBehavior.end(); ++iter) iter->second = behavior; } } else { // Do the update for this single extension - iter = extensionBehavior.find(TString(extension)); + auto iter = extensionBehavior.find(TString(extension)); if (iter == extensionBehavior.end()) { switch (behavior) { case EBhRequire: diff --git a/glslang/MachineIndependent/intermOut.cpp b/glslang/MachineIndependent/intermOut.cpp index 8bccbd6a..7dcec826 100644 --- a/glslang/MachineIndependent/intermOut.cpp +++ b/glslang/MachineIndependent/intermOut.cpp @@ -649,7 +649,7 @@ void TIntermediate::output(TInfoSink& infoSink, bool tree) { infoSink.debug << "Shader version: " << version << "\n"; if (requestedExtensions.size() > 0) { - for (std::set::const_iterator extIt = requestedExtensions.begin(); extIt != requestedExtensions.end(); ++extIt) + for (auto extIt = requestedExtensions.begin(); extIt != requestedExtensions.end(); ++extIt) infoSink.debug << "Requested " << *extIt << "\n"; } diff --git a/glslang/MachineIndependent/preprocessor/PpAtom.cpp b/glslang/MachineIndependent/preprocessor/PpAtom.cpp index b6609da1..d058d5d8 100644 --- a/glslang/MachineIndependent/preprocessor/PpAtom.cpp +++ b/glslang/MachineIndependent/preprocessor/PpAtom.cpp @@ -130,7 +130,7 @@ namespace glslang { // int TPpContext::LookUpAddString(const char* s) { - TAtomMap::const_iterator it = atomMap.find(s); + auto it = atomMap.find(s); if (it == atomMap.end()) return AddAtomFixed(s, nextAtom++); else @@ -161,7 +161,7 @@ const char* TPpContext::GetAtomString(int atom) // int TPpContext::AddAtomFixed(const char* s, int atom) { - TAtomMap::const_iterator it = atomMap.insert(std::pair(s, atom)).first; + auto it = atomMap.insert(std::pair(s, atom)).first; if (stringMap.size() < (size_t)atom + 1) stringMap.resize(atom + 100, 0); stringMap[atom] = &it->first; diff --git a/glslang/MachineIndependent/preprocessor/PpContext.h b/glslang/MachineIndependent/preprocessor/PpContext.h index eb32a422..dadf706b 100644 --- a/glslang/MachineIndependent/preprocessor/PpContext.h +++ b/glslang/MachineIndependent/preprocessor/PpContext.h @@ -78,6 +78,8 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef PPCONTEXT_H #define PPCONTEXT_H +#include + #include "../ParseHelper.h" #pragma warning(disable : 4127) @@ -190,7 +192,7 @@ public: }; MemoryPool *pool; - typedef std::map TSymbolMap; + typedef TUnorderedMap TSymbolMap; TSymbolMap symbols; // this has light use... just defined macros protected: @@ -459,7 +461,7 @@ protected: // // From PpAtom.cpp // - typedef std::map TAtomMap; + typedef TUnorderedMap TAtomMap; typedef TVector TStringMap; TAtomMap atomMap; TStringMap stringMap; diff --git a/glslang/MachineIndependent/reflection.h b/glslang/MachineIndependent/reflection.h index 47b51cdc..1378a6a4 100644 --- a/glslang/MachineIndependent/reflection.h +++ b/glslang/MachineIndependent/reflection.h @@ -108,7 +108,7 @@ public: protected: friend class glslang::TLiveTraverser; - typedef std::map TNameToIndex; + typedef std::unordered_map TNameToIndex; typedef std::vector TMapIndexToReflection; TObjectReflection badReflection; // return for queries of -1 or generally out of range; has expected descriptions with in it for this