Skip to content

Commit

Permalink
sped up Tokenizer::dump() (#5009)
Browse files Browse the repository at this point in the history
Scanning the `cli` folder with `DISABLE_VALUEFLOW=1` `Tokenizer::dump()`
will consume almost 25% of the total Ir count when an addon is
specified. This is mainly caused by the usage of `std::ostream`.

Encountered while profiling #4958.
  • Loading branch information
firewave committed Aug 31, 2023
1 parent 98401a3 commit 0fadf9e
Show file tree
Hide file tree
Showing 7 changed files with 684 additions and 287 deletions.
20 changes: 10 additions & 10 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ static void createDumpFile(const Settings& settings,
break;
}

fdump << "<?xml version=\"1.0\"?>" << std::endl;
fdump << "<dumps" << language << ">" << std::endl;
fdump << "<?xml version=\"1.0\"?>\n";
fdump << "<dumps" << language << ">\n";
fdump << " <platform"
<< " name=\"" << settings.platform.toString() << '\"'
<< " char_bit=\"" << settings.platform.char_bit << '\"'
Expand All @@ -325,7 +325,7 @@ static void createDumpFile(const Settings& settings,
<< " long_bit=\"" << settings.platform.long_bit << '\"'
<< " long_long_bit=\"" << settings.platform.long_long_bit << '\"'
<< " pointer_bit=\"" << (settings.platform.sizeof_pointer * settings.platform.char_bit) << '\"'
<< "/>\n";
<< "/>" << '\n';
}

static std::string executeAddon(const AddonInfo &addonInfo,
Expand Down Expand Up @@ -571,16 +571,16 @@ unsigned int CppCheck::check(const std::string &path)
std::string dumpFile;
createDumpFile(mSettings, path, fdump, dumpFile);
if (fdump.is_open()) {
fdump << "<dump cfg=\"\">" << std::endl;
fdump << "<dump cfg=\"\">\n";
for (const ErrorMessage& errmsg: compilerWarnings)
fdump << " <clang-warning file=\"" << toxml(errmsg.callStack.front().getfile()) << "\" line=\"" << errmsg.callStack.front().line << "\" column=\"" << errmsg.callStack.front().column << "\" message=\"" << toxml(errmsg.shortMessage()) << "\"/>\n";
fdump << " <standards>" << std::endl;
fdump << " <c version=\"" << mSettings.standards.getC() << "\"/>" << std::endl;
fdump << " <cpp version=\"" << mSettings.standards.getCPP() << "\"/>" << std::endl;
fdump << " </standards>" << std::endl;
fdump << " <standards>\n";
fdump << " <c version=\"" << mSettings.standards.getC() << "\"/>\n";
fdump << " <cpp version=\"" << mSettings.standards.getCPP() << "\"/>\n";
fdump << " </standards>\n";
tokenizer.dump(fdump);
fdump << "</dump>" << std::endl;
fdump << "</dumps>" << std::endl;
fdump << "</dump>\n";
fdump << "</dumps>\n";
fdump.close();
}

Expand Down
20 changes: 10 additions & 10 deletions lib/errorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,36 +731,36 @@ std::string ErrorMessage::FileLocation::stringify() const

std::string ErrorLogger::toxml(const std::string &str)
{
std::ostringstream xml;
std::string xml;
for (const unsigned char c : str) {
switch (c) {
case '<':
xml << "&lt;";
xml += "&lt;";
break;
case '>':
xml << "&gt;";
xml += "&gt;";
break;
case '&':
xml << "&amp;";
xml += "&amp;";
break;
case '\"':
xml << "&quot;";
xml += "&quot;";
break;
case '\'':
xml << "&apos;";
xml += "&apos;";
break;
case '\0':
xml << "\\0";
xml += "\\0";
break;
default:
if (c >= ' ' && c <= 0x7f)
xml << c;
xml += c;
else
xml << 'x';
xml += 'x';
break;
}
}
return xml.str();
return xml;
}

std::string ErrorLogger::plistHeader(const std::string &version, const std::vector<std::string> &files)
Expand Down
Loading

0 comments on commit 0fadf9e

Please sign in to comment.