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.
This commit is contained in:
John Kessenich 2016-12-20 21:47:30 -07:00
parent 54af2de761
commit 907aabb6b0
7 changed files with 74 additions and 63 deletions

View file

@ -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;