Skip to content

Commit b34d811

Browse files
committed
deflookup: remove empty maps to speed up subsequent lookups
Related: #98
1 parent 4678172 commit b34d811

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

Diff for: src/lib/deflookup.cc

+19-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "msg-filter.hh"
2323
#include "parser.hh"
2424

25+
#include <cassert>
2526
#include <map>
2627

2728
typedef std::vector<Defect> TDefList;
@@ -82,11 +83,7 @@ static bool defLookupCore(TDefList &defList)
8283
{
8384
// just remove an arbitrary one
8485
// TODO: add some other criteria in order to make the match more precise
85-
unsigned cnt = defList.size();
86-
if (cnt)
87-
defList.resize(cnt - 1);
88-
else
89-
return false;
86+
defList.resize(defList.size() - 1U);
9087

9188
return true;
9289
}
@@ -105,11 +102,13 @@ bool DefLookup::lookup(const Defect &def)
105102

106103
// look for file name
107104
TDefByFile &byPath = itByChecker->second;
105+
assert(!byPath.empty());
108106
TDefByFile::iterator itByPath = byPath.find(path);
109107
if (byPath.end() == itByPath)
110108
return false;
111109

112110
TDefByEvt &byEvt = itByPath->second;
111+
assert(!byEvt.empty());
113112
if (!d->usePartialResults && byEvt.end() != byEvt.find("internal warning"))
114113
// if the analyzer produced an "internal warning" diagnostic message,
115114
// we assume partial results, which cannot be reliably used for
@@ -124,16 +123,31 @@ bool DefLookup::lookup(const Defect &def)
124123

125124
// look by msg
126125
TDefByMsg &byMsg = itByEvent->second;
126+
assert(!byMsg.empty());
127127
const std::string msg = filter.filterMsg(evt.msg, def.checker);
128128
TDefByMsg::iterator itByMsg = byMsg.find(msg);
129129
if (byMsg.end() == itByMsg)
130130
return false;
131131

132132
// process the resulting list of defects sequentially
133133
TDefList &defList = itByMsg->second;
134+
assert(!defList.empty());
134135
if (!defLookupCore(defList))
135136
return false;
136137

138+
// remove empty maps to speed up subsequent lookups
139+
if (defList.empty()) {
140+
byMsg.erase(itByMsg);
141+
if (byMsg.empty()) {
142+
byEvt.erase(itByEvent);
143+
if (byEvt.empty()) {
144+
byPath.erase(itByPath);
145+
if (byPath.empty())
146+
d->byChecker.erase(itByChecker);
147+
}
148+
}
149+
}
150+
137151
// found!
138152
return true;
139153
}

0 commit comments

Comments
 (0)