Optimize handling of --append=<file> option (execution time, memory)

Whitespace was removed from the append data for every configuration
and every file: n(configuration) * n(files).

Removing whitespace immediately after the append data was read can
significantly reduce the execution time and memory usage.
It also allows further improvement because copies to the temporary
object appendCode are no longer needed.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2011-11-13 22:31:04 +01:00 committed by Stefan Weil
parent d11f18b5df
commit 785bc3d04b
3 changed files with 5 additions and 5 deletions

View File

@ -234,9 +234,7 @@ unsigned int CppCheck::processFile()
_errorLogger.reportOut(std::string("Checking ") + fixedpath + ": " + cfg + std::string("...")); _errorLogger.reportOut(std::string("Checking ") + fixedpath + ": " + cfg + std::string("..."));
} }
std::string appendCode = _settings.append(); const std::string &appendCode = _settings.append();
if (!appendCode.empty())
Preprocessor::preprocessWhitespaces(appendCode);
if (_settings.debugFalsePositive) { if (_settings.debugFalsePositive) {
if (findError(codeWithoutCfg + appendCode, _filename.c_str())) { if (findError(codeWithoutCfg + appendCode, _filename.c_str())) {

View File

@ -18,6 +18,7 @@
#include "settings.h" #include "settings.h"
#include "path.h" #include "path.h"
#include "preprocessor.h" // Preprocessor
#include <fstream> #include <fstream>
#include <set> #include <set>
@ -129,10 +130,11 @@ bool Settings::append(const std::string &filename)
while (std::getline(fin, line)) { while (std::getline(fin, line)) {
_append += line + "\n"; _append += line + "\n";
} }
Preprocessor::preprocessWhitespaces(_append);
return true; return true;
} }
std::string Settings::append() const const std::string &Settings::append() const
{ {
return _append; return _append;
} }

View File

@ -119,7 +119,7 @@ public:
bool append(const std::string &filename); bool append(const std::string &filename);
/** @brief get append code (--append) */ /** @brief get append code (--append) */
std::string append() const; const std::string &append() const;
/** @brief Maximum number of configurations to check before bailing. /** @brief Maximum number of configurations to check before bailing.
Default is 12. (--max-configs=N) */ Default is 12. (--max-configs=N) */