Performance: Simple upgrade/cleanup of stl c++11 containers (10% perf. increase).
This commit is contained in:
parent
f4673162b7
commit
2f273369e4
10 changed files with 58 additions and 54 deletions
|
|
@ -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<TString, TExtensionBehavior> extensionBehavior; // for each extension string, what its current behavior is set to
|
||||
std::unordered_map<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;
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@
|
|||
//
|
||||
|
||||
#include <string.h>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
#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<std::string, int>* KeywordMap = 0;
|
||||
std::set<std::string>* ReservedSet = 0;
|
||||
std::unordered_map<std::string, int>* KeywordMap = 0;
|
||||
std::unordered_set<std::string>* ReservedSet = 0;
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -307,7 +309,7 @@ void TScanContext::fillInKeywordMap()
|
|||
// but, the only risk is if two threads called simultaneously
|
||||
return;
|
||||
}
|
||||
KeywordMap = new std::map<std::string, int>;
|
||||
KeywordMap = new std::unordered_map<std::string, int>;
|
||||
|
||||
(*KeywordMap)["const"] = CONST;
|
||||
(*KeywordMap)["uniform"] = UNIFORM;
|
||||
|
|
@ -476,7 +478,7 @@ void TScanContext::fillInKeywordMap()
|
|||
(*KeywordMap)["resource"] = RESOURCE;
|
||||
(*KeywordMap)["superp"] = SUPERP;
|
||||
|
||||
ReservedSet = new std::set<std::string>;
|
||||
ReservedSet = new std::unordered_set<std::string>;
|
||||
|
||||
ReservedSet->insert("common");
|
||||
ReservedSet->insert("partition");
|
||||
|
|
@ -610,7 +612,7 @@ int TScanContext::tokenizeIdentifier()
|
|||
if (ReservedSet->find(tokenText) != ReservedSet->end())
|
||||
return reservedWord();
|
||||
|
||||
std::map<std::string, int>::const_iterator it = KeywordMap->find(tokenText);
|
||||
auto it = KeywordMap->find(tokenText);
|
||||
if (it == KeywordMap->end()) {
|
||||
// Should have an identifier of some sort
|
||||
return identifierOrType();
|
||||
|
|
|
|||
|
|
@ -441,7 +441,7 @@ void TParseContext::requireExtensions(TSourceLoc loc, int numExtensions, const c
|
|||
|
||||
TExtensionBehavior TParseContext::getExtensionBehavior(const char* extension)
|
||||
{
|
||||
TMap<TString, TExtensionBehavior>::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<TString, TExtensionBehavior>::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:
|
||||
|
|
|
|||
|
|
@ -649,7 +649,7 @@ void TIntermediate::output(TInfoSink& infoSink, bool tree)
|
|||
{
|
||||
infoSink.debug << "Shader version: " << version << "\n";
|
||||
if (requestedExtensions.size() > 0) {
|
||||
for (std::set<std::string>::const_iterator extIt = requestedExtensions.begin(); extIt != requestedExtensions.end(); ++extIt)
|
||||
for (auto extIt = requestedExtensions.begin(); extIt != requestedExtensions.end(); ++extIt)
|
||||
infoSink.debug << "Requested " << *extIt << "\n";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<TString, int>(s, atom)).first;
|
||||
auto it = atomMap.insert(std::pair<TString, int>(s, atom)).first;
|
||||
if (stringMap.size() < (size_t)atom + 1)
|
||||
stringMap.resize(atom + 100, 0);
|
||||
stringMap[atom] = &it->first;
|
||||
|
|
|
|||
|
|
@ -78,6 +78,8 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#ifndef PPCONTEXT_H
|
||||
#define PPCONTEXT_H
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "../ParseHelper.h"
|
||||
|
||||
#pragma warning(disable : 4127)
|
||||
|
|
@ -190,7 +192,7 @@ public:
|
|||
};
|
||||
|
||||
MemoryPool *pool;
|
||||
typedef std::map<int, Symbol*> TSymbolMap;
|
||||
typedef TUnorderedMap<int, Symbol*> TSymbolMap;
|
||||
TSymbolMap symbols; // this has light use... just defined macros
|
||||
|
||||
protected:
|
||||
|
|
@ -459,7 +461,7 @@ protected:
|
|||
//
|
||||
// From PpAtom.cpp
|
||||
//
|
||||
typedef std::map<const TString, int> TAtomMap;
|
||||
typedef TUnorderedMap<const TString, int, TStringHash> TAtomMap;
|
||||
typedef TVector<const TString*> TStringMap;
|
||||
TAtomMap atomMap;
|
||||
TStringMap stringMap;
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ public:
|
|||
protected:
|
||||
friend class glslang::TLiveTraverser;
|
||||
|
||||
typedef std::map<TString, int> TNameToIndex;
|
||||
typedef std::unordered_map<TString, int> TNameToIndex;
|
||||
typedef std::vector<TObjectReflection> TMapIndexToReflection;
|
||||
|
||||
TObjectReflection badReflection; // return for queries of -1 or generally out of range; has expected descriptions with in it for this
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue