diff options
author | Rolf Eike Beer <eike@sf-mail.de> | 2020-03-21 11:51:46 (GMT) |
---|---|---|
committer | Rolf Eike Beer <eike@sf-mail.de> | 2020-03-23 21:41:44 (GMT) |
commit | ef778d77e0795ecba8af55a6984ad5fa5f44377a (patch) | |
tree | f2256f9fac53cc2be8840bc69cf1f8feb32c17f6 /Source | |
parent | 77616f46817b6527c7e515de547625e554df21f9 (diff) | |
download | CMake-ef778d77e0795ecba8af55a6984ad5fa5f44377a.zip CMake-ef778d77e0795ecba8af55a6984ad5fa5f44377a.tar.gz CMake-ef778d77e0795ecba8af55a6984ad5fa5f44377a.tar.bz2 |
replace std::string::substr() with operations that do not allocate memory
Modify the original string instead of creating a new copy with substr() when it
is not used for anything else afterwards.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CPack/cmCPackNSISGenerator.cxx | 2 | ||||
-rw-r--r-- | Source/CPack/cpack.cxx | 2 | ||||
-rw-r--r-- | Source/CTest/cmCTestGIT.cxx | 4 | ||||
-rw-r--r-- | Source/CTest/cmCTestScriptHandler.cxx | 4 | ||||
-rw-r--r-- | Source/CTest/cmCTestTestHandler.cxx | 5 | ||||
-rw-r--r-- | Source/CTest/cmParseMumpsCoverage.cxx | 3 | ||||
-rw-r--r-- | Source/bindexplib.cxx | 6 | ||||
-rw-r--r-- | Source/cmCTest.cxx | 4 | ||||
-rw-r--r-- | Source/cmComputeLinkInformation.cxx | 12 | ||||
-rw-r--r-- | Source/cmRST.cxx | 6 |
10 files changed, 28 insertions, 20 deletions
diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx index 363f536..f7edc91 100644 --- a/Source/CPack/cmCPackNSISGenerator.cxx +++ b/Source/CPack/cmCPackNSISGenerator.cxx @@ -103,7 +103,7 @@ int cmCPackNSISGenerator::PackageFiles() componentName = fileN.substr(0, slash); // Strip off the component part of the path. - fileN = fileN.substr(slash + 1); + fileN.erase(0, slash + 1); } } std::replace(fileN.begin(), fileN.end(), '/', '\\'); diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index dc31623..2e5bde2 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -85,7 +85,7 @@ int cpackDefinitionArgument(const char* argument, const char* cValue, return 0; } std::string key = value.substr(0, pos); - value = value.substr(pos + 1); + value.erase(0, pos + 1); def->Map[key] = value; cmCPack_Log(def->Log, cmCPackLog::LOG_DEBUG, "Set CPack variable: " << key << " to \"" << value << "\"" diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index 3f3c107..568b091 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -6,6 +6,7 @@ #include <cstdio> #include <cstdlib> #include <ctime> +#include <utility> #include <vector> #include "cmsys/FStream.hxx" @@ -193,7 +194,8 @@ bool cmCTestGIT::UpdateByFetchAndReset() if (line.find("\tnot-for-merge\t") == std::string::npos) { std::string::size_type pos = line.find('\t'); if (pos != std::string::npos) { - sha1 = line.substr(0, pos); + sha1 = std::move(line); + sha1.resize(pos); } } } diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index 5be9332..4fa4dc0 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -284,12 +284,14 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg) // if the argument has a , in it then it needs to be broken into the fist // argument (which is the script) and the second argument which will be // passed into the scripts as S_ARG - std::string script = total_script_arg; + std::string script; std::string script_arg; const std::string::size_type comma_pos = total_script_arg.find(','); if (comma_pos != std::string::npos) { script = total_script_arg.substr(0, comma_pos); script_arg = total_script_arg.substr(comma_pos + 1); + } else { + script = total_script_arg; } // make sure the file exists if (!cmSystemTools::FileExists(script)) { diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index c7aef6b..77641c6 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -1893,7 +1893,8 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed() continue; } - int val = atoi(line.substr(0, pos).c_str()); + line.erase(pos); + int val = atoi(line.c_str()); this->TestsToRun.push_back(val); } ifs.close(); @@ -2114,7 +2115,7 @@ void cmCTestTestHandler::CleanTestOutput(std::string& output, size_t length) ++current; } } - output = output.substr(0, current - begin); + output.erase(current - begin); // Append truncation message. std::ostringstream msg; diff --git a/Source/CTest/cmParseMumpsCoverage.cxx b/Source/CTest/cmParseMumpsCoverage.cxx index dc1cf30..dc3064d 100644 --- a/Source/CTest/cmParseMumpsCoverage.cxx +++ b/Source/CTest/cmParseMumpsCoverage.cxx @@ -113,7 +113,8 @@ bool cmParseMumpsCoverage::LoadPackages(std::string const& d) glob.FindFiles(pat); for (std::string& file : glob.GetFiles()) { std::string name = cmSystemTools::GetFilenameName(file); - this->RoutineToDirectory[name.substr(0, name.size() - 2)] = file; + name.erase(name.size() - 2); + this->RoutineToDirectory[name] = file; // initialize each file, this is left out until CDash is fixed // to handle large numbers of files this->InitializeMumpsFile(file); diff --git a/Source/bindexplib.cxx b/Source/bindexplib.cxx index 0b2750d..fdfd4c0 100644 --- a/Source/bindexplib.cxx +++ b/Source/bindexplib.cxx @@ -352,14 +352,14 @@ bool DumpFileWithLlvmNm(std::string const& nmPath, const char* filename, line.c_str()); return false; } - const std::string sym = line.substr(0, sym_end); const char sym_type = line[sym_end + 1]; + line.resize(sym_end); switch (sym_type) { case 'D': - dataSymbols.insert(sym); + dataSymbols.insert(line); break; case 'T': - symbols.insert(sym); + symbols.insert(line); break; } } diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 5359492..72ec1b5 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -725,7 +725,7 @@ bool cmCTest::UpdateCTestConfiguration() continue; } while (fin && (line.back() == '\\')) { - line = line.substr(0, line.size() - 1); + line.resize(line.size() - 1); buffer[0] = 0; fin.getline(buffer, 1023); buffer[1023] = 0; @@ -2668,7 +2668,7 @@ std::string cmCTest::GetShortPathToFile(const char* cfname) path = "./" + *res; if (path.back() == '/') { - path = path.substr(0, path.size() - 1); + path.resize(path.size() - 1); } } diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index aff9dd9..8d27699 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -1798,10 +1798,10 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs, if (use_build_rpath) { std::string d = ri; if (!rootPath.empty() && cmHasPrefix(d, rootPath)) { - d = d.substr(rootPath.size()); + d.erase(0, rootPath.size()); } else if (stagePath && *stagePath && cmHasPrefix(d, stagePath)) { - std::string suffix = d.substr(strlen(stagePath)); - d = cmStrCat(installPrefix, '/', suffix); + d.erase(0, strlen(stagePath)); + d = cmStrCat(installPrefix, '/', d); cmSystemTools::ConvertToUnixSlashes(d); } else if (use_relative_build_rpath) { // If expansion of the $ORIGIN token is supported and permitted per @@ -1829,10 +1829,10 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs, !cmSystemTools::IsSubDirectory(ri, topBinaryDir)) { std::string d = ri; if (!rootPath.empty() && cmHasPrefix(d, rootPath)) { - d = d.substr(rootPath.size()); + d.erase(0, rootPath.size()); } else if (stagePath && *stagePath && cmHasPrefix(d, stagePath)) { - std::string suffix = d.substr(strlen(stagePath)); - d = cmStrCat(installPrefix, '/', suffix); + d.erase(0, strlen(stagePath)); + d = cmStrCat(installPrefix, '/', d); cmSystemTools::ConvertToUnixSlashes(d); } if (emitted.insert(d).second) { diff --git a/Source/cmRST.cxx b/Source/cmRST.cxx index 68c15de..c39d162 100644 --- a/Source/cmRST.cxx +++ b/Source/cmRST.cxx @@ -89,7 +89,8 @@ void cmRST::ProcessModule(std::istream& is) this->ProcessLine(line); } else { if (line[0] != '#') { - this->ProcessLine(line.substr(0, pos)); + line.resize(pos); + this->ProcessLine(line); } rst.clear(); this->Reset(); @@ -103,7 +104,8 @@ void cmRST::ProcessModule(std::istream& is) continue; } if (cmHasLiteralPrefix(line, "# ")) { - this->ProcessLine(line.substr(2)); + line.erase(0, 2); + this->ProcessLine(line); continue; } rst.clear(); |