diff options
author | Artur Ryt <artur.ryt@gmail.com> | 2019-03-30 15:11:21 (GMT) |
---|---|---|
committer | Artur Ryt <artur.ryt@gmail.com> | 2019-03-30 15:15:05 (GMT) |
commit | 2d66567dca2a5a80e41493ec0a9d6d86f7d955f5 (patch) | |
tree | 84468e248f456f65c75a99033ba8073e48ea0f5b | |
parent | 5bdee3786359b6560eb9ee1d6fab8664feb90db4 (diff) | |
download | CMake-2d66567dca2a5a80e41493ec0a9d6d86f7d955f5.zip CMake-2d66567dca2a5a80e41493ec0a9d6d86f7d955f5.tar.gz CMake-2d66567dca2a5a80e41493ec0a9d6d86f7d955f5.tar.bz2 |
Modernize: Prefer .substr in place of .c_str() + int
A lot of temporary/local strings were created out of C-strings
substr can utilize current string size, so in theory be a little
more efficient.
-rw-r--r-- | Source/CPack/cpack.cxx | 2 | ||||
-rw-r--r-- | Source/CTest/cmCTestBuildHandler.cxx | 4 | ||||
-rw-r--r-- | Source/CTest/cmCTestGIT.cxx | 2 | ||||
-rw-r--r-- | Source/CTest/cmCTestLaunch.cxx | 2 | ||||
-rw-r--r-- | Source/CTest/cmCTestSVN.cxx | 4 | ||||
-rw-r--r-- | Source/CTest/cmCTestTestHandler.cxx | 4 | ||||
-rw-r--r-- | Source/cmDependsFortran.cxx | 2 | ||||
-rw-r--r-- | Source/cmDependsJavaParserHelper.cxx | 13 | ||||
-rw-r--r-- | Source/cmFileInstaller.cxx | 2 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 2 | ||||
-rw-r--r-- | Source/cmTargetPropertyComputer.h | 2 | ||||
-rw-r--r-- | Source/cmcmd.cxx | 2 |
12 files changed, 19 insertions, 22 deletions
diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index da9575b..3ceb824 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -82,7 +82,7 @@ int cpackDefinitionArgument(const char* argument, const char* cValue, return 0; } std::string key = value.substr(0, pos); - value = value.c_str() + pos + 1; + value = value.substr(pos + 1); def->Map[key] = value; cmCPack_Log(def->Log, cmCPackLog::LOG_DEBUG, "Set CPack variable: " << key << " to \"" << value << "\"" diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index 8ea9a83..8480309 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -387,7 +387,7 @@ int cmCTestBuildHandler::ProcessHandler() std::string srcdirrep; for (cc = srcdir.size() - 2; cc > 0; cc--) { if (srcdir[cc] == '/') { - srcdirrep = srcdir.c_str() + cc; + srcdirrep = srcdir.substr(cc); srcdirrep = "/..." + srcdirrep; srcdir = srcdir.substr(0, cc + 1); break; @@ -401,7 +401,7 @@ int cmCTestBuildHandler::ProcessHandler() std::string bindirrep; for (cc = bindir.size() - 2; cc > 0; cc--) { if (bindir[cc] == '/') { - bindirrep = bindir.c_str() + cc; + bindirrep = bindir.substr(cc); bindirrep = "/..." + bindirrep; bindir = bindir.substr(0, cc + 1); break; diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index 11cd005..9d9761c 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -547,7 +547,7 @@ private: { // Look for header fields that we need. if (cmHasLiteralPrefix(this->Line, "commit ")) { - this->Rev.Rev = this->Line.c_str() + 7; + this->Rev.Rev = this->Line.substr(7); } else if (cmHasLiteralPrefix(this->Line, "author ")) { Person author; this->ParsePerson(this->Line.c_str() + 7, author); diff --git a/Source/CTest/cmCTestLaunch.cxx b/Source/CTest/cmCTestLaunch.cxx index 5e66e05..a96513e 100644 --- a/Source/CTest/cmCTestLaunch.cxx +++ b/Source/CTest/cmCTestLaunch.cxx @@ -308,7 +308,7 @@ void cmCTestLaunch::LoadLabels() if (line[0] == ' ') { // Label lines appear indented by one space. if (inTarget || inSource) { - this->Labels.insert(line.c_str() + 1); + this->Labels.insert(line.substr(1)); } } else if (!this->OptionSource.empty() && !inSource) { // Non-indented lines specify a source file name. The first one diff --git a/Source/CTest/cmCTestSVN.cxx b/Source/CTest/cmCTestSVN.cxx index b7a4e4c..04749b7 100644 --- a/Source/CTest/cmCTestSVN.cxx +++ b/Source/CTest/cmCTestSVN.cxx @@ -515,7 +515,7 @@ private: if (path.size() > this->SVN->SourceDirectory.size() && strncmp(path.c_str(), this->SVN->SourceDirectory.c_str(), this->SVN->SourceDirectory.size()) == 0) { - local_path = path.c_str() + this->SVN->SourceDirectory.size() + 1; + local_path = path.substr(this->SVN->SourceDirectory.size() + 1); } else { local_path = path; } @@ -554,7 +554,7 @@ std::string cmCTestSVN::SVNInfo::BuildLocalPath(std::string const& path) const // Add path with base prefix removed if (path.size() > this->Base.size() && strncmp(path.c_str(), this->Base.c_str(), this->Base.size()) == 0) { - local_path += (path.c_str() + this->Base.size()); + local_path += path.substr(this->Base.size()); } else { local_path += path; } diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index c9783e4..0ed56c8 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -2265,8 +2265,8 @@ bool cmCTestTestHandler::SetTestsProperties( size_t pos = val.find_first_of('='); if (pos != std::string::npos) { std::string mKey = val.substr(0, pos); - const char* mVal = val.c_str() + pos + 1; - rt.Measurements[mKey] = mVal; + std::string mVal = val.substr(pos + 1); + rt.Measurements[mKey] = std::move(mVal); } else { rt.Measurements[val] = "1"; } diff --git a/Source/cmDependsFortran.cxx b/Source/cmDependsFortran.cxx index 3f036a9..178e18b 100644 --- a/Source/cmDependsFortran.cxx +++ b/Source/cmDependsFortran.cxx @@ -295,7 +295,7 @@ void cmDependsFortran::MatchRemoteModules(std::istream& fin, // They do not include the ".mod" extension. mod += ".mod"; } - this->ConsiderModule(mod.c_str() + 1, stampDir); + this->ConsiderModule(mod.substr(1), stampDir); } } else if (line == "provides") { doing_provides = true; diff --git a/Source/cmDependsJavaParserHelper.cxx b/Source/cmDependsJavaParserHelper.cxx index 792db48..12d875d 100644 --- a/Source/cmDependsJavaParserHelper.cxx +++ b/Source/cmDependsJavaParserHelper.cxx @@ -5,6 +5,7 @@ #include "cmDependsJavaLexer.h" #include "cmSystemTools.h" +#include "cm_string_view.hxx" #include "cmsys/FStream.hxx" #include <iostream> #include <stdio.h> @@ -298,14 +299,10 @@ void cmDependsJavaParserHelper::Error(const char* str) unsigned long pos = static_cast<unsigned long>(this->InputBufferPos); fprintf(stderr, "JPError: %s (%lu / Line: %d)\n", str, pos, this->CurrentLine); - int cc; - std::cerr << "String: ["; - for (cc = 0; - cc < 30 && *(this->InputBuffer.c_str() + this->InputBufferPos + cc); - cc++) { - std::cerr << *(this->InputBuffer.c_str() + this->InputBufferPos + cc); - } - std::cerr << "]" << std::endl; + std::cerr << "String: [" + << cm::string_view{ this->InputBuffer }.substr( + this->InputBufferPos, 30) + << "]" << std::endl; } void cmDependsJavaParserHelper::UpdateCombine(const char* str1, diff --git a/Source/cmFileInstaller.cxx b/Source/cmFileInstaller.cxx index f3544c1..d4f76fd 100644 --- a/Source/cmFileInstaller.cxx +++ b/Source/cmFileInstaller.cxx @@ -319,7 +319,7 @@ bool cmFileInstaller::HandleInstallDestination() return false; } } - destination = sdestdir + (destination.c_str() + skip); + destination = sdestdir + destination.substr(skip); this->DestDirLength = int(sdestdir.size()); } diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 2c145e0..40b8e19 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2266,7 +2266,7 @@ void cmLocalGenerator::JoinDefines(const std::set<std::string>& defines, def += define.substr(0, eq); if (eq != std::string::npos) { def += "="; - def += this->EscapeForShell(define.c_str() + eq + 1, true); + def += this->EscapeForShell(define.substr(eq + 1), true); } } definesString += itemSeparator; diff --git a/Source/cmTargetPropertyComputer.h b/Source/cmTargetPropertyComputer.h index 97e4fba..efbf95f 100644 --- a/Source/cmTargetPropertyComputer.h +++ b/Source/cmTargetPropertyComputer.h @@ -81,7 +81,7 @@ private: context)) { return nullptr; } - const char* configName = prop.c_str() + 9; + std::string configName = prop.substr(9); return ComputeLocation(tgt, configName); } diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 8d63971..9b635ea 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -620,7 +620,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args) std::string const& a = *ai; if (cmHasLiteralPrefix(a, "--unset=")) { // Unset environment variable. - cmSystemTools::UnPutEnv(a.c_str() + 8); + cmSystemTools::UnPutEnv(a.substr(8)); } else if (!a.empty() && a[0] == '-') { // Environment variable and command names cannot start in '-', // so this must be an unknown option. |