summaryrefslogtreecommitdiffstats
path: root/Source/cmGeneratorExpression.cxx
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2014-02-09 10:09:52 (GMT)
committerBen Boeckel <ben.boeckel@kitware.com>2014-02-21 21:56:06 (GMT)
commit7c565d2fd5e86d420ea83eb724ad5380ca5c2e97 (patch)
tree908a8b39fed89225ac6804cb58de8e009def5d44 /Source/cmGeneratorExpression.cxx
parent68eb1757445dd1bb6537e32be8c9a72360112978 (diff)
downloadCMake-7c565d2fd5e86d420ea83eb724ad5380ca5c2e97.zip
CMake-7c565d2fd5e86d420ea83eb724ad5380ca5c2e97.tar.gz
CMake-7c565d2fd5e86d420ea83eb724ad5380ca5c2e97.tar.bz2
cmGeneratorExpression: Improve parsing in StripEmptyListElements
The char-by-char parsing causes lots of reallocations which shouldn't be necessary. To improve this, fast-path strings without a semicolon, reserve space in the result, and insert into the result in chunks.
Diffstat (limited to 'Source/cmGeneratorExpression.cxx')
-rw-r--r--Source/cmGeneratorExpression.cxx13
1 files changed, 10 insertions, 3 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) == ';')
{