ENH: Improve performance by using vector of char instead of string

This commit is contained in:
Andy Cedilnik 2005-04-13 16:25:55 -04:00
parent 5e02b5ec96
commit c09f6172a4
1 changed files with 16 additions and 14 deletions

View File

@ -952,7 +952,6 @@ void cmSystemTools::ExpandList(std::vector<std::string> const& arguments,
void cmSystemTools::ExpandListArgument(const std::string& arg, void cmSystemTools::ExpandListArgument(const std::string& arg,
std::vector<std::string>& newargs) std::vector<std::string>& newargs)
{ {
std::string newarg;
// If argument is empty, it is an empty list. // If argument is empty, it is an empty list.
if(arg.length() == 0) if(arg.length() == 0)
{ {
@ -964,6 +963,7 @@ void cmSystemTools::ExpandListArgument(const std::string& arg,
newargs.push_back(arg); newargs.push_back(arg);
return; return;
} }
std::vector<char> newArgVec;
// Break the string at non-escaped semicolons not nested in []. // Break the string at non-escaped semicolons not nested in [].
int squareNesting = 0; int squareNesting = 0;
for(const char* c = arg.c_str(); *c; ++c) for(const char* c = arg.c_str(); *c; ++c)
@ -977,26 +977,26 @@ void cmSystemTools::ExpandListArgument(const std::string& arg,
++c; ++c;
if(*c == ';') if(*c == ';')
{ {
newarg += ';'; newArgVec.push_back(*c);
} }
else else
{ {
newarg += '\\'; newArgVec.push_back('\\');
if(*c) if(*c)
{ {
newarg += *c; newArgVec.push_back(*c);
} }
} }
} break; } break;
case '[': case '[':
{ {
++squareNesting; ++squareNesting;
newarg += '['; newArgVec.push_back(*c);
} break; } break;
case ']': case ']':
{ {
--squareNesting; --squareNesting;
newarg += ']'; newArgVec.push_back(*c);
} break; } break;
case ';': case ';':
{ {
@ -1004,29 +1004,31 @@ void cmSystemTools::ExpandListArgument(const std::string& arg,
// brackets. // brackets.
if(squareNesting == 0) if(squareNesting == 0)
{ {
if(newarg.length()) if ( newArgVec.size() )
{ {
// Add an argument if the string is not empty. // Add the last argument if the string is not empty.
newargs.push_back(newarg); newArgVec.push_back(0);
newarg = ""; newargs.push_back(&*newArgVec.begin());
newArgVec.clear();
} }
} }
else else
{ {
newarg += ';'; newArgVec.push_back(*c);
} }
} break; } break;
default: default:
{ {
// Just append this character. // Just append this character.
newarg += *c; newArgVec.push_back(*c);
} break; } break;
} }
} }
if(newarg.length()) if ( newArgVec.size() )
{ {
// Add the last argument if the string is not empty. // Add the last argument if the string is not empty.
newargs.push_back(newarg); newArgVec.push_back(0);
newargs.push_back(&*newArgVec.begin());
} }
} }