diff --git a/SystemTools.cxx b/SystemTools.cxx index 6aac690270f298ef3941ef5c9d8a36b86cc18b7f..0d03453369fc836855970673f7134844037dfc40 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -2894,14 +2894,13 @@ std::string SystemTools::FindProgram(const std::string& name, // the end of it // on windows try .com then .exe if (name.size() <= 3 || name[name.size() - 4] != '.') { - extensions.push_back(".com"); - extensions.push_back(".exe"); + extensions.emplace_back(".com"); + extensions.emplace_back(".exe"); // first try with extensions if the os supports them - for (std::vector<std::string>::iterator i = extensions.begin(); - i != extensions.end(); ++i) { + for (std::string const& ext : extensions) { tryPath = name; - tryPath += *i; + tryPath += ext; if (SystemTools::FileExists(tryPath, true)) { return SystemTools::CollapseFullPath(tryPath); } @@ -2920,43 +2919,33 @@ std::string SystemTools::FindProgram(const std::string& name, SystemTools::GetPath(path); } // now add the additional paths - { - for (std::vector<std::string>::const_iterator i = userPaths.begin(); - i != userPaths.end(); ++i) { - path.push_back(*i); - } - } + path.reserve(path.size() + userPaths.size()); + path.insert(path.end(), userPaths.begin(), userPaths.end()); // Add a trailing slash to all paths to aid the search process. - { - for (std::vector<std::string>::iterator i = path.begin(); i != path.end(); - ++i) { - std::string& p = *i; - if (p.empty() || p.back() != '/') { - p += "/"; - } + for (std::string& p : path) { + if (p.empty() || p.back() != '/') { + p += '/'; } } // Try each path - for (std::vector<std::string>::iterator p = path.begin(); p != path.end(); - ++p) { + for (std::string& p : path) { #ifdef _WIN32 // Remove double quotes from the path on windows - SystemTools::ReplaceString(*p, "\"", ""); + SystemTools::ReplaceString(p, "\"", ""); #endif #if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) // first try with extensions - for (std::vector<std::string>::iterator ext = extensions.begin(); - ext != extensions.end(); ++ext) { - tryPath = *p; + for (std::string const& ext : extensions) { + tryPath = p; tryPath += name; - tryPath += *ext; + tryPath += ext; if (SystemTools::FileExists(tryPath, true)) { return SystemTools::CollapseFullPath(tryPath); } } #endif // now try it without them - tryPath = *p; + tryPath = p; tryPath += name; if (SystemTools::FileExists(tryPath, true)) { return SystemTools::CollapseFullPath(tryPath);