summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-02-25 16:18:14 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2014-02-25 16:18:14 (GMT)
commit958cd84431b02f5b912d54bba6d22f73d7d7c81b (patch)
treebc3fad67e8b4809ba478ab392a513e74abf84fec /Source
parent049790c0eb7ba76975d3256c8cc66d59eed25a96 (diff)
parent048be20536b6960e3a4a5001ba3d642e2e5cdad1 (diff)
downloadCMake-958cd84431b02f5b912d54bba6d22f73d7d7c81b.zip
CMake-958cd84431b02f5b912d54bba6d22f73d7d7c81b.tar.gz
CMake-958cd84431b02f5b912d54bba6d22f73d7d7c81b.tar.bz2
Merge topic 'dev/faster-parsers'
048be205 Help: Add release notes for the 'faster-parsers' topic 7c565d2f cmGeneratorExpression: Improve parsing in StripEmptyListElements 68eb1757 cmGeneratorExpressionLexer: Use a switch statement to parse 67253133 ExpandListArguments: Optimize the parser
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGeneratorExpression.cxx13
-rw-r--r--Source/cmGeneratorExpressionLexer.cxx70
-rw-r--r--Source/cmSystemTools.cxx51
3 files changed, 63 insertions, 71 deletions
diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx
index 2e66d78..cd30546 100644
--- a/Source/cmGeneratorExpression.cxx
+++ b/Source/cmGeneratorExpression.cxx
@@ -157,17 +157,24 @@ cmCompiledGeneratorExpression::~cmCompiledGeneratorExpression()
std::string cmGeneratorExpression::StripEmptyListElements(
const std::string &input)
{
+ if (input.find(';') == input.npos)
+ {
+ return input;
+ }
std::string result;
+ result.reserve(input.size());
const char *c = input.c_str();
+ const char *last = c;
bool skipSemiColons = true;
for ( ; *c; ++c)
{
- if(c[0] == ';')
+ if(*c == ';')
{
if(skipSemiColons)
{
- continue;
+ result.append(last, c - last);
+ last = c + 1;
}
skipSemiColons = true;
}
@@ -175,8 +182,8 @@ std::string cmGeneratorExpression::StripEmptyListElements(
{
skipSemiColons = false;
}
- result += *c;
}
+ result.append(last);
if (!result.empty() && *(result.end() - 1) == ';')
{
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);
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index ff05975..7cc63bb 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -1044,7 +1044,7 @@ void cmSystemTools::ExpandListArgument(const std::string& arg,
bool emptyArgs)
{
// If argument is empty, it is an empty list.
- if(arg.length() == 0 && !emptyArgs)
+ if(!emptyArgs && arg.empty())
{
return;
}
@@ -1054,10 +1054,11 @@ void cmSystemTools::ExpandListArgument(const std::string& arg,
newargs.push_back(arg);
return;
}
- std::vector<char> newArgVec;
+ std::string newArg;
+ const char *last = arg.c_str();
// Break the string at non-escaped semicolons not nested in [].
int squareNesting = 0;
- for(const char* c = arg.c_str(); *c; ++c)
+ for(const char* c = last; *c; ++c)
{
switch(*c)
{
@@ -1065,34 +1066,21 @@ void cmSystemTools::ExpandListArgument(const std::string& arg,
{
// We only want to allow escaping of semicolons. Other
// escapes should not be processed here.
- ++c;
- if(*c == ';')
- {
- newArgVec.push_back(*c);
- }
- else
+ const char* next = c + 1;
+ if(*next == ';')
{
- newArgVec.push_back('\\');
- if(*c)
- {
- newArgVec.push_back(*c);
- }
- else
- {
- // Terminate the loop properly.
- --c;
- }
+ newArg.append(last, c - last);
+ // Skip over the escape character
+ last = c = next;
}
} break;
case '[':
{
++squareNesting;
- newArgVec.push_back(*c);
} break;
case ']':
{
--squareNesting;
- newArgVec.push_back(*c);
} break;
case ';':
{
@@ -1100,31 +1088,28 @@ void cmSystemTools::ExpandListArgument(const std::string& arg,
// brackets.
if(squareNesting == 0)
{
- if ( newArgVec.size() || emptyArgs )
+ newArg.append(last, c - last);
+ // Skip over the semicolon
+ last = c + 1;
+ if ( !newArg.empty() || emptyArgs )
{
// Add the last argument if the string is not empty.
- newArgVec.push_back(0);
- newargs.push_back(&*newArgVec.begin());
- newArgVec.clear();
+ newargs.push_back(newArg);
+ newArg = "";
}
}
- else
- {
- newArgVec.push_back(*c);
- }
} break;
default:
{
// Just append this character.
- newArgVec.push_back(*c);
} break;
}
}
- if ( newArgVec.size() || emptyArgs )
+ newArg.append(last);
+ if ( !newArg.empty() || emptyArgs )
{
// Add the last argument if the string is not empty.
- newArgVec.push_back(0);
- newargs.push_back(&*newArgVec.begin());
+ newargs.push_back(newArg);
}
}