summaryrefslogtreecommitdiffstats
path: root/Source/kwsys
diff options
context:
space:
mode:
authorKen Martin <ken.martin@kitware.com>2003-06-24 19:23:34 (GMT)
committerKen Martin <ken.martin@kitware.com>2003-06-24 19:23:34 (GMT)
commite315bff47b144764bc9202b707c82d48298bab25 (patch)
tree71465be92e00f6eb4738c87dcfd4ee942240b4ec /Source/kwsys
parent76b344c6fe1e0b66da040649f37f55215e0745a7 (diff)
downloadCMake-e315bff47b144764bc9202b707c82d48298bab25.zip
CMake-e315bff47b144764bc9202b707c82d48298bab25.tar.gz
CMake-e315bff47b144764bc9202b707c82d48298bab25.tar.bz2
performance improvements
Diffstat (limited to 'Source/kwsys')
-rw-r--r--Source/kwsys/SystemTools.cxx36
1 files changed, 25 insertions, 11 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index 70d0d96..0b887fc 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -252,23 +252,37 @@ void SystemTools::ReplaceString(kwsys_std::string& source,
const char* replace,
const char* with)
{
+ const char *src = source.c_str();
+ char *searchPos = strstr(src,replace);
+
// get out quick if string is not found
- kwsys_std::string::size_type start = source.find(replace);
- if(start == kwsys_std::string::npos)
+ if (!searchPos)
{
return;
}
- kwsys_std::string rest;
- kwsys_std::string::size_type lengthReplace = strlen(replace);
- kwsys_std::string::size_type lengthWith = strlen(with);
- while(start != kwsys_std::string::npos)
- {
- rest = source.substr(start+lengthReplace);
- source = source.substr(0, start);
+
+ // perform replacements until done
+ size_t replaceSize = strlen(replace);
+ char *orig = strdup(src);
+ char *currentPos = orig;
+ searchPos = searchPos - src + orig;
+
+ // initialize the result
+ source.clear();
+ do
+ {
+ *searchPos = '\0';
+ source += currentPos;
+ currentPos = searchPos + replaceSize;
+ // replace
source += with;
- source += rest;
- start = source.find(replace, start + lengthWith );
+ searchPos = strstr(currentPos,replace);
}
+ while (searchPos);
+
+ // copy any trailing text
+ source += currentPos;
+ free(orig);
}
// Read a registry value.