cmGeneratorExpressionLexer: Use a switch statement to parse

Optimize cmGeneratorExpressionLexer::Tokenize to use a switch statement.
The many dereferences of the input pointer were expensive. Also remove
excess pointer arithmetic.
This commit is contained in:
Ben Boeckel 2014-02-08 12:01:30 -05:00 committed by Ben Boeckel
parent 67253133f8
commit 68eb175744
1 changed files with 35 additions and 35 deletions

View File

@ -42,42 +42,42 @@ cmGeneratorExpressionLexer::Tokenize(const char *input)
const char *upto = c; const char *upto = c;
for ( ; *c; ++c) for ( ; *c; ++c)
{
if(c[0] == '$' && c[1] == '<')
{ {
InsertText(upto, c, result); switch(*c)
upto = c; {
result.push_back(cmGeneratorExpressionToken( case '$':
cmGeneratorExpressionToken::BeginExpression, upto, 2)); if(c[1] == '<')
upto = c + 2; {
++c; InsertText(upto, c, result);
SawBeginExpression = true; result.push_back(cmGeneratorExpressionToken(
} cmGeneratorExpressionToken::BeginExpression, c, 2));
else if(c[0] == '>') upto = c + 2;
{ ++c;
InsertText(upto, c, result); SawBeginExpression = true;
upto = c; }
result.push_back(cmGeneratorExpressionToken( break;
cmGeneratorExpressionToken::EndExpression, upto, 1)); case '>':
upto = c + 1; InsertText(upto, c, result);
SawGeneratorExpression = SawBeginExpression; result.push_back(cmGeneratorExpressionToken(
} cmGeneratorExpressionToken::EndExpression, c, 1));
else if(c[0] == ':') upto = c + 1;
{ SawGeneratorExpression = SawBeginExpression;
InsertText(upto, c, result); break;
upto = c; case ':':
result.push_back(cmGeneratorExpressionToken( InsertText(upto, c, result);
cmGeneratorExpressionToken::ColonSeparator, upto, 1)); result.push_back(cmGeneratorExpressionToken(
upto = c + 1; cmGeneratorExpressionToken::ColonSeparator, c, 1));
} upto = c + 1;
else if(c[0] == ',') break;
{ case ',':
InsertText(upto, c, result); InsertText(upto, c, result);
upto = c; result.push_back(cmGeneratorExpressionToken(
result.push_back(cmGeneratorExpressionToken( cmGeneratorExpressionToken::CommaSeparator, c, 1));
cmGeneratorExpressionToken::CommaSeparator, upto, 1)); upto = c + 1;
upto = c + 1; break;
} default:
break;
}
} }
InsertText(upto, c, result); InsertText(upto, c, result);