Skip to content

Commit

Permalink
use more appropriate container for error list
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Jul 31, 2023
1 parent daa8543 commit bcb2f12
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
3 changes: 1 addition & 2 deletions cli/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ bool Executor::hasToLog(const ErrorMessage &msg)
return false;

std::lock_guard<std::mutex> lg(mErrorListSync);
if (std::find(mErrorList.cbegin(), mErrorList.cend(), errmsg) == mErrorList.cend()) {
mErrorList.emplace_back(std::move(errmsg));
if (mErrorList.emplace(std::move(errmsg)).second) {
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions cli/executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#define EXECUTOR_H

#include <cstddef>
#include <list>
#include <map>
#include <mutex>
#include <string>
#include <unordered_set>

class Settings;
class ErrorLogger;
Expand Down Expand Up @@ -71,7 +71,7 @@ class Executor {
private:
std::mutex mErrorListSync;
// TODO: store hashes instead of full messages
std::list<std::string> mErrorList;
std::unordered_set<std::string> mErrorList;
};

/// @}
Expand Down
4 changes: 1 addition & 3 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@ void CppCheck::reportErr(const ErrorMessage &msg)
return;

// Alert only about unique errors
if (std::find(mErrorList.cbegin(), mErrorList.cend(), errmsg) != mErrorList.cend())
if (!mErrorList.emplace(std::move(errmsg)).second)
return;

if (!mSettings.buildDir.empty())
Expand All @@ -1613,8 +1613,6 @@ void CppCheck::reportErr(const ErrorMessage &msg)
mExitCode = 1;
}

mErrorList.emplace_back(std::move(errmsg));

mErrorLogger.reportErr(msg);
// check if plistOutput should be populated and the current output file is open and the error is not suppressed
if (!mSettings.plistOutput.empty() && mPlistFile.is_open() && !mSettings.nomsg.isSuppressed(errorMessage)) {
Expand Down
3 changes: 2 additions & 1 deletion lib/cppcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <list>
#include <map>
#include <string>
#include <unordered_set>
#include <vector>

class Tokenizer;
Expand Down Expand Up @@ -208,7 +209,7 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
void reportOut(const std::string &outmsg, Color c = Color::Reset) override;

// TODO: store hashes instead of the full messages
std::list<std::string> mErrorList;
std::unordered_set<std::string> mErrorList;
Settings mSettings;

void reportProgress(const std::string &filename, const char stage[], const std::size_t value) override;
Expand Down

0 comments on commit bcb2f12

Please sign in to comment.