Commit 907aabb6 by John Kessenich

PP: Non-functional: Only use string <-> atom mapping when needed.

Also, eliminate the 'atom' field of TPpToken. Parsing a real 300 line shader, through to making the AST, is about 10% faster. Memory is slightly reduced (< 1%). The whole google-test suite, inclusive of all testing overhead, SPIR-V generation, etc., runs 3% faster. Since this is a code *simplification* that leads to perf. improvement, I'm not going to invest too much more in measuring the perf. than this. The PP code is simply now in a better state to see how to further rationalize/improve it.
parent 54af2de7
...@@ -2,5 +2,5 @@ ...@@ -2,5 +2,5 @@
// For the version, it uses the latest git tag followed by the number of commits. // For the version, it uses the latest git tag followed by the number of commits.
// For the date, it uses the current date (when then script is run). // For the date, it uses the current date (when then script is run).
#define GLSLANG_REVISION "Overload400-PrecQual.1713" #define GLSLANG_REVISION "Overload400-PrecQual.1715"
#define GLSLANG_DATE "20-Dec-2016" #define GLSLANG_DATE "20-Dec-2016"
...@@ -120,7 +120,6 @@ const struct { ...@@ -120,7 +120,6 @@ const struct {
{ PpAtomIncrement, "++" }, { PpAtomIncrement, "++" },
{ PpAtomDefine, "define" }, { PpAtomDefine, "define" },
{ PpAtomDefined, "defined" },
{ PpAtomUndef, "undef" }, { PpAtomUndef, "undef" },
{ PpAtomIf, "if" }, { PpAtomIf, "if" },
{ PpAtomElif, "elif" }, { PpAtomElif, "elif" },
...@@ -150,16 +149,28 @@ const struct { ...@@ -150,16 +149,28 @@ const struct {
namespace glslang { namespace glslang {
// //
// Map an existing string to an atom.
//
// Return 0 if no existing string.
//
int TPpContext::LookUpString(const char* s)
{
auto it = atomMap.find(s);
return it == atomMap.end() ? 0 : it->second;
}
//
// Map a new or existing string to an atom, inventing a new atom if necessary. // Map a new or existing string to an atom, inventing a new atom if necessary.
// //
int TPpContext::LookUpAddString(const char* s) int TPpContext::LookUpAddString(const char* s)
{ {
auto it = atomMap.find(s); int atom = LookUpString(s);
if (it == atomMap.end()) { if (atom == 0) {
AddAtomFixed(s, nextAtom); atom = nextAtom++;
return nextAtom++; AddAtomFixed(s, atom);
} else }
return it->second;
return atom;
} }
// //
......
...@@ -92,7 +92,7 @@ namespace glslang { ...@@ -92,7 +92,7 @@ namespace glslang {
class TPpToken { class TPpToken {
public: public:
TPpToken() : space(false), ival(0), dval(0.0), i64val(0), atom(0) TPpToken() : space(false), ival(0), dval(0.0), i64val(0)
{ {
loc.init(); loc.init();
name[0] = 0; name[0] = 0;
...@@ -112,7 +112,6 @@ public: ...@@ -112,7 +112,6 @@ public:
int ival; int ival;
double dval; double dval;
long long i64val; long long i64val;
int atom;
char name[MaxTokenLength + 1]; char name[MaxTokenLength + 1];
}; };
...@@ -551,6 +550,7 @@ protected: ...@@ -551,6 +550,7 @@ protected:
int nextAtom; int nextAtom;
void InitAtomTable(); void InitAtomTable();
void AddAtomFixed(const char* s, int atom); void AddAtomFixed(const char* s, int atom);
int LookUpString(const char* s);
int LookUpAddString(const char* s); int LookUpAddString(const char* s);
const char* GetAtomString(int atom); const char* GetAtomString(int atom);
}; };
......
...@@ -247,7 +247,6 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken) ...@@ -247,7 +247,6 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
// //
int TPpContext::tStringInput::scan(TPpToken* ppToken) int TPpContext::tStringInput::scan(TPpToken* ppToken)
{ {
char* tokenText = ppToken->name;
int AlreadyComplained = 0; int AlreadyComplained = 0;
int len = 0; int len = 0;
int ch = 0; int ch = 0;
...@@ -286,7 +285,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) ...@@ -286,7 +285,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
case 'z': case 'z':
do { do {
if (len < MaxTokenLength) { if (len < MaxTokenLength) {
tokenText[len++] = (char)ch; ppToken->name[len++] = (char)ch;
ch = getch(); ch = getch();
} else { } else {
if (! AlreadyComplained) { if (! AlreadyComplained) {
...@@ -304,9 +303,8 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) ...@@ -304,9 +303,8 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
if (len == 0) if (len == 0)
continue; continue;
tokenText[len] = '\0'; ppToken->name[len] = '\0';
ungetch(); ungetch();
ppToken->atom = pp->LookUpAddString(tokenText);
return PpAtomIdentifier; return PpAtomIdentifier;
case '0': case '0':
ppToken->name[len++] = (char)ch; ppToken->name[len++] = (char)ch;
...@@ -693,13 +691,13 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) ...@@ -693,13 +691,13 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
ch = getch(); ch = getch();
while (ch != '"' && ch != '\n' && ch != EndOfInput) { while (ch != '"' && ch != '\n' && ch != EndOfInput) {
if (len < MaxTokenLength) { if (len < MaxTokenLength) {
tokenText[len] = (char)ch; ppToken->name[len] = (char)ch;
len++; len++;
ch = getch(); ch = getch();
} else } else
break; break;
}; };
tokenText[len] = '\0'; ppToken->name[len] = '\0';
if (ch != '"') { if (ch != '"') {
ungetch(); ungetch();
pp->parseContext.ppError(ppToken->loc, "End of line in string", "string", ""); pp->parseContext.ppError(ppToken->loc, "End of line in string", "string", "");
...@@ -821,7 +819,6 @@ int TPpContext::tokenPaste(int token, TPpToken& ppToken) ...@@ -821,7 +819,6 @@ int TPpContext::tokenPaste(int token, TPpToken& ppToken)
if (strlen(ppToken.name) + strlen(pastedPpToken.name) > MaxTokenLength) if (strlen(ppToken.name) + strlen(pastedPpToken.name) > MaxTokenLength)
parseContext.ppError(ppToken.loc, "combined tokens are too long", "##", ""); parseContext.ppError(ppToken.loc, "combined tokens are too long", "##", "");
strncat(ppToken.name, pastedPpToken.name, MaxTokenLength - strlen(ppToken.name)); strncat(ppToken.name, pastedPpToken.name, MaxTokenLength - strlen(ppToken.name));
ppToken.atom = LookUpAddString(ppToken.name);
} }
return resultToken; return resultToken;
......
...@@ -218,7 +218,6 @@ int TPpContext::ReadToken(TokenStream& pTok, TPpToken *ppToken) ...@@ -218,7 +218,6 @@ int TPpContext::ReadToken(TokenStream& pTok, TPpToken *ppToken)
switch (ltoken) { switch (ltoken) {
case PpAtomIdentifier: case PpAtomIdentifier:
ppToken->atom = LookUpAddString(ppToken->name);
break; break;
case PpAtomConstString: case PpAtomConstString:
break; break;
......
...@@ -134,7 +134,6 @@ enum EFixedAtoms { ...@@ -134,7 +134,6 @@ enum EFixedAtoms {
// preprocessor "keywords" // preprocessor "keywords"
PpAtomDefine, PpAtomDefine,
PpAtomDefined,
PpAtomUndef, PpAtomUndef,
PpAtomIf, PpAtomIf,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment