From 68eb1757445dd1bb6537e32be8c9a72360112978 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 8 Feb 2014 12:01:30 -0500 Subject: 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. --- Source/cmGeneratorExpressionLexer.cxx | 70 +++++++++++++++++------------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/Source/cmGeneratorExpressionLexer.cxx b/Source/cmGeneratorExpressionLexer.cxx index cd71ec0..117a24e 100644 --- a/Source/cmGeneratorExpressionLexer.cxx +++ b/Source/cmGeneratorExpressionLexer.cxx @@ -42,42 +42,42 @@ cmGeneratorExpressionLexer::Tokenize(const char *input) const char *upto = c; for ( ; *c; ++c) - { - if(c[0] == '$' && c[1] == '<') { - InsertText(upto, c, result); - upto = c; - result.push_back(cmGeneratorExpressionToken( - cmGeneratorExpressionToken::BeginExpression, upto, 2)); - upto = c + 2; - ++c; - SawBeginExpression = true; - } - else if(c[0] == '>') - { - InsertText(upto, c, result); - upto = c; - result.push_back(cmGeneratorExpressionToken( - cmGeneratorExpressionToken::EndExpression, upto, 1)); - upto = c + 1; - SawGeneratorExpression = SawBeginExpression; - } - else if(c[0] == ':') - { - InsertText(upto, c, result); - upto = c; - result.push_back(cmGeneratorExpressionToken( - cmGeneratorExpressionToken::ColonSeparator, upto, 1)); - upto = c + 1; - } - else if(c[0] == ',') - { - InsertText(upto, c, result); - upto = c; - result.push_back(cmGeneratorExpressionToken( - cmGeneratorExpressionToken::CommaSeparator, upto, 1)); - upto = c + 1; - } + switch(*c) + { + case '$': + if(c[1] == '<') + { + InsertText(upto, c, result); + result.push_back(cmGeneratorExpressionToken( + cmGeneratorExpressionToken::BeginExpression, c, 2)); + upto = c + 2; + ++c; + SawBeginExpression = true; + } + break; + case '>': + InsertText(upto, c, result); + result.push_back(cmGeneratorExpressionToken( + cmGeneratorExpressionToken::EndExpression, c, 1)); + upto = c + 1; + SawGeneratorExpression = SawBeginExpression; + break; + case ':': + InsertText(upto, c, result); + result.push_back(cmGeneratorExpressionToken( + cmGeneratorExpressionToken::ColonSeparator, c, 1)); + upto = c + 1; + break; + case ',': + InsertText(upto, c, result); + result.push_back(cmGeneratorExpressionToken( + cmGeneratorExpressionToken::CommaSeparator, c, 1)); + upto = c + 1; + break; + default: + break; + } } InsertText(upto, c, result); -- cgit v0.12