Skip to content

Commit 7c1bd62

Browse files
committed
Don't repeat the exact same warning messages
Some warnings are repeated a number of times even though they refer to the same problem. By storing a md5sum of the warnings (less space than the full message) this can be prevented.
1 parent 44f85e4 commit 7c1bd62

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/message.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <cstdlib>
1818
#include <mutex>
1919
#include <atomic>
20+
#include <unordered_set>
2021

2122
#include "config.h"
2223
#include "debug.h"
@@ -25,6 +26,7 @@
2526
#include "doxygen.h"
2627
#include "fileinfo.h"
2728
#include "dir.h"
29+
#include "md5.h"
2830

2931
// globals
3032
static QCString g_warnFormat;
@@ -37,9 +39,20 @@ static QCString g_warnlogFile;
3739
static bool g_warnlogTemp = false;
3840
static std::atomic_bool g_warnStat = false;
3941
static std::mutex g_mutex;
42+
static std::unordered_set<std::string> g_warnHash;
4043

4144
//-----------------------------------------------------------------------------------------
4245

46+
static bool checkWarnMessage(QCString result)
47+
{
48+
uint8_t md5_sig[16];
49+
char sigStr[33];
50+
MD5Buffer(result.data(),result.length(),md5_sig);
51+
MD5SigToString(md5_sig,sigStr);
52+
53+
return g_warnHash.insert(sigStr).second;
54+
}
55+
4356
static void format_warn(const QCString &file,int line,const QCString &text)
4457
{
4558
QCString fileSubst = file.isEmpty() ? "<unknown>" : file;
@@ -70,7 +83,7 @@ static void format_warn(const QCString &file,int line,const QCString &text)
7083
{
7184
std::unique_lock<std::mutex> lock(g_mutex);
7285
// print resulting message
73-
fwrite(msgText.data(),1,msgText.length(),g_warnFile);
86+
if (checkWarnMessage(msgText)) fwrite(msgText.data(),1,msgText.length(),g_warnFile);
7487
}
7588
if (g_warnBehavior == WARN_AS_ERROR_t::YES)
7689
{
@@ -150,15 +163,15 @@ void warn_(WarningType type, const QCString &file, int line, fmt::string_view fm
150163

151164
void warn_uncond_(fmt::string_view fmt, fmt::format_args args)
152165
{
153-
fmt::print(g_warnFile,"{}{}",g_warningStr,vformat(fmt,args));
166+
if (checkWarnMessage(g_errorStr+fmt::vformat(fmt,args))) fmt::print(g_warnFile,"{}{}",g_warningStr,vformat(fmt,args));
154167
handle_warn_as_error();
155168
}
156169

157170
//-----------------------------------------------------------------------------------------
158171

159172
void err_(fmt::string_view fmt, fmt::format_args args)
160173
{
161-
fmt::print(g_warnFile,"{}{}",g_errorStr,fmt::vformat(fmt,args));
174+
if (checkWarnMessage(g_errorStr+fmt::vformat(fmt,args))) fmt::print(g_warnFile,"{}{}",g_errorStr,fmt::vformat(fmt,args));
162175
handle_warn_as_error();
163176
}
164177

@@ -175,7 +188,7 @@ void term_(fmt::string_view fmt, fmt::format_args args)
175188
{
176189
{
177190
std::unique_lock<std::mutex> lock(g_mutex);
178-
fmt::print(g_warnFile, "{}{}", g_errorStr, fmt::vformat(fmt,args));
191+
if (checkWarnMessage(g_errorStr+fmt::vformat(fmt,args))) fmt::print(g_warnFile, "{}{}", g_errorStr, fmt::vformat(fmt,args));
179192
if (g_warnFile != stderr)
180193
{
181194
size_t l = strlen(g_errorStr);

0 commit comments

Comments
 (0)