use std::string::rfind() instead of open coding it

While at it avoid creating a new string.
This commit is contained in:
Rolf Eike Beer
2020-03-18 21:23:40 +01:00
parent 871bf0cc88
commit 0415fa3be7
+8 -12
View File
@@ -386,24 +386,20 @@ int cmCTestBuildHandler::ProcessHandler()
if (this->CTest->GetCTestConfiguration("SourceDirectory").size() > 20) {
std::string srcdir =
this->CTest->GetCTestConfiguration("SourceDirectory") + "/";
for (cc = srcdir.size() - 2; cc > 0; cc--) {
if (srcdir[cc] == '/') {
srcdir = srcdir.substr(0, cc + 1);
break;
}
cc = srcdir.rfind('/', srcdir.size() - 2);
if (cc != std::string::npos) {
srcdir.resize(cc + 1);
this->SimplifySourceDir = std::move(srcdir);
}
this->SimplifySourceDir = srcdir;
}
if (this->CTest->GetCTestConfiguration("BuildDirectory").size() > 20) {
std::string bindir =
this->CTest->GetCTestConfiguration("BuildDirectory") + "/";
for (cc = bindir.size() - 2; cc > 0; cc--) {
if (bindir[cc] == '/') {
bindir = bindir.substr(0, cc + 1);
break;
}
cc = bindir.rfind('/', bindir.size() - 2);
if (cc != std::string::npos) {
bindir.resize(cc + 1);
this->SimplifyBuildDir = std::move(bindir);
}
this->SimplifyBuildDir = bindir;
}
// Ok, let's do the build