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 @@
// 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).
#define GLSLANG_REVISION "Overload400-PrecQual.1713"
#define GLSLANG_REVISION "Overload400-PrecQual.1715"
#define GLSLANG_DATE "20-Dec-2016"
......@@ -120,7 +120,6 @@ const struct {
{ PpAtomIncrement, "++" },
{ PpAtomDefine, "define" },
{ PpAtomDefined, "defined" },
{ PpAtomUndef, "undef" },
{ PpAtomIf, "if" },
{ PpAtomElif, "elif" },
......@@ -150,16 +149,28 @@ const struct {
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.
//
int TPpContext::LookUpAddString(const char* s)
{
auto it = atomMap.find(s);
if (it == atomMap.end()) {
AddAtomFixed(s, nextAtom);
return nextAtom++;
} else
return it->second;
int atom = LookUpString(s);
if (atom == 0) {
atom = nextAtom++;
AddAtomFixed(s, atom);
}
return atom;
}
//
......
......@@ -92,7 +92,7 @@ namespace glslang {
class TPpToken {
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();
name[0] = 0;
......@@ -112,7 +112,6 @@ public:
int ival;
double dval;
long long i64val;
int atom;
char name[MaxTokenLength + 1];
};
......@@ -551,6 +550,7 @@ protected:
int nextAtom;
void InitAtomTable();
void AddAtomFixed(const char* s, int atom);
int LookUpString(const char* s);
int LookUpAddString(const char* s);
const char* GetAtomString(int atom);
};
......
......@@ -247,7 +247,6 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
//
int TPpContext::tStringInput::scan(TPpToken* ppToken)
{
char* tokenText = ppToken->name;
int AlreadyComplained = 0;
int len = 0;
int ch = 0;
......@@ -286,7 +285,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
case 'z':
do {
if (len < MaxTokenLength) {
tokenText[len++] = (char)ch;
ppToken->name[len++] = (char)ch;
ch = getch();
} else {
if (! AlreadyComplained) {
......@@ -304,9 +303,8 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
if (len == 0)
continue;
tokenText[len] = '\0';
ppToken->name[len] = '\0';
ungetch();
ppToken->atom = pp->LookUpAddString(tokenText);
return PpAtomIdentifier;
case '0':
ppToken->name[len++] = (char)ch;
......@@ -693,13 +691,13 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
ch = getch();
while (ch != '"' && ch != '\n' && ch != EndOfInput) {
if (len < MaxTokenLength) {
tokenText[len] = (char)ch;
ppToken->name[len] = (char)ch;
len++;
ch = getch();
} else
break;
};
tokenText[len] = '\0';
ppToken->name[len] = '\0';
if (ch != '"') {
ungetch();
pp->parseContext.ppError(ppToken->loc, "End of line in string", "string", "");
......@@ -821,7 +819,6 @@ int TPpContext::tokenPaste(int token, TPpToken& ppToken)
if (strlen(ppToken.name) + strlen(pastedPpToken.name) > MaxTokenLength)
parseContext.ppError(ppToken.loc, "combined tokens are too long", "##", "");
strncat(ppToken.name, pastedPpToken.name, MaxTokenLength - strlen(ppToken.name));
ppToken.atom = LookUpAddString(ppToken.name);
}
return resultToken;
......
......@@ -218,7 +218,6 @@ int TPpContext::ReadToken(TokenStream& pTok, TPpToken *ppToken)
switch (ltoken) {
case PpAtomIdentifier:
ppToken->atom = LookUpAddString(ppToken->name);
break;
case PpAtomConstString:
break;
......
......@@ -134,7 +134,6 @@ enum EFixedAtoms {
// preprocessor "keywords"
PpAtomDefine,
PpAtomDefined,
PpAtomUndef,
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