ENH: perfomance: seeking of one char is more efficiently

This commit is contained in:
uburuntu 2017-05-27 04:15:54 +02:00 committed by Daniel Marjamäki
parent a1081f961c
commit d41d091c07
2 changed files with 8 additions and 8 deletions

View File

@ -143,11 +143,11 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin
if (!_settings.plistOutput.empty()) {
std::string filename2;
if (filename.find("/") != std::string::npos)
filename2 = filename.substr(filename.rfind("/") + 1);
if (filename.find('/') != std::string::npos)
filename2 = filename.substr(filename.rfind('/') + 1);
else
filename2 = filename;
filename2 = _settings.plistOutput + filename2.substr(0, filename2.find(".")) + ".plist";
filename2 = _settings.plistOutput + filename2.substr(0, filename2.find('.')) + ".plist";
plistFile.open(filename2);
plistFile << ErrorLogger::plistHeader(version(), files);
}

View File

@ -37,7 +37,7 @@ static std::string builddir(std::string filename)
static std::string objfile(std::string cppfile)
{
cppfile.erase(cppfile.rfind("."));
cppfile.erase(cppfile.rfind('.'));
return builddir(cppfile + ".o");
}
@ -50,15 +50,15 @@ static void getDeps(const std::string &filename, std::vector<std::string> &depfi
std::ifstream f(filename.c_str());
if (! f.is_open()) {
if (filename.compare(0, 4, "cli/") == 0 || filename.compare(0, 5, "test/") == 0)
getDeps("lib" + filename.substr(filename.find("/")), depfiles);
getDeps("lib" + filename.substr(filename.find('/')), depfiles);
return;
}
if (filename.find(".c") == std::string::npos)
depfiles.push_back(filename);
std::string path(filename);
if (path.find("/") != std::string::npos)
path.erase(1 + path.rfind("/"));
if (path.find('/') != std::string::npos)
path.erase(1 + path.rfind('/'));
std::string line;
while (std::getline(f, line)) {
@ -67,7 +67,7 @@ static void getDeps(const std::string &filename, std::vector<std::string> &depfi
continue;
pos1 += 10;
std::string::size_type pos2 = line.find("\"", pos1);
std::string::size_type pos2 = line.find('\"', pos1);
std::string hfile(path + line.substr(pos1, pos2 - pos1));
if (hfile.find("/../") != std::string::npos) // TODO: Ugly fix
hfile.erase(0, 4 + hfile.find("/../"));