Commit 91429382 authored by Hans Johnson's avatar Hans Johnson
Browse files

PERF: emplace_back method results in potentially more efficient code

The check flags insertions to an STL-style container done by calling the
push_back method with an explicitly-constructed temporary of the container
element type. In this case, the corresponding emplace_back method results in
less verbose and potentially more efficient code.
parent 6d20e7c9
......@@ -208,7 +208,7 @@ bool Directory::Load(const std::string& name)
}
for (kwsys_dirent* d = readdir(dir); d; d = readdir(dir)) {
this->Internal->Files.push_back(d->d_name);
this->Internal->Files.emplace_back(d->d_name);
}
this->Internal->Path = name;
closedir(dir);
......
......@@ -415,8 +415,7 @@ bool Glob::FindFiles(const std::string& inexpr, GlobMessages* messages)
void Glob::AddExpression(const std::string& expr)
{
this->Internals->Expressions.push_back(
kwsys::RegularExpression(this->PatternToRegex(expr)));
this->Internals->Expressions.emplace_back(this->PatternToRegex(expr));
}
void Glob::SetRelative(const char* dir)
......
......@@ -928,7 +928,7 @@ int LoadLines(FILE* file, std::vector<std::string>& lines)
*pBuf = '\0';
pBuf += 1;
}
lines.push_back(buf);
lines.emplace_back(buf);
++nRead;
}
if (ferror(file)) {
......
......@@ -1893,7 +1893,7 @@ std::vector<std::string> SystemTools::SplitString(const std::string& p,
}
if (isPath && path[0] == '/') {
path.erase(path.begin());
paths.push_back("/");
paths.emplace_back("/");
}
std::string::size_type pos1 = 0;
std::string::size_type pos2 = path.find(sep, pos1 + 1);
......@@ -3571,14 +3571,14 @@ void SystemTools::SplitPath(const std::string& p,
for (; *last; ++last) {
if (*last == '/' || *last == '\\') {
// End of a component. Save it.
components.push_back(std::string(first, last));
components.emplace_back(first, last);
first = last + 1;
}
}
// Save the last component unless there were no components.
if (last != c) {
components.push_back(std::string(first, last));
components.emplace_back(first, last);
}
}
......
......@@ -743,16 +743,16 @@ static bool CheckGetPath()
const char* registryPath = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MyApp; MyKey]";
std::vector<std::string> originalPaths;
originalPaths.push_back(registryPath);
originalPaths.emplace_back(registryPath);
std::vector<std::string> expectedPaths;
expectedPaths.push_back(registryPath);
expectedPaths.emplace_back(registryPath);
#ifdef _WIN32
expectedPaths.push_back("C:/Somewhere/something");
expectedPaths.push_back("D:/Temp");
#else
expectedPaths.push_back("/Somewhere/something");
expectedPaths.push_back("/tmp");
expectedPaths.emplace_back("/Somewhere/something");
expectedPaths.emplace_back("/tmp");
#endif
bool res = true;
......@@ -817,7 +817,7 @@ static bool CheckFind()
}
std::vector<std::string> searchPaths;
searchPaths.push_back(TEST_SYSTEMTOOLS_BINARY_DIR);
searchPaths.emplace_back(TEST_SYSTEMTOOLS_BINARY_DIR);
if (kwsys::SystemTools::FindFile(testFindFileName, searchPaths, true)
.empty()) {
std::cerr << "Problem with FindFile without system paths for: "
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment