22
22
#include " msg-filter.hh"
23
23
#include " parser.hh"
24
24
25
+ #include < cassert>
25
26
#include < map>
26
27
27
28
typedef std::vector<Defect> TDefList;
@@ -82,11 +83,7 @@ static bool defLookupCore(TDefList &defList)
82
83
{
83
84
// just remove an arbitrary one
84
85
// 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 );
90
87
91
88
return true ;
92
89
}
@@ -105,11 +102,13 @@ bool DefLookup::lookup(const Defect &def)
105
102
106
103
// look for file name
107
104
TDefByFile &byPath = itByChecker->second ;
105
+ assert (!byPath.empty ());
108
106
TDefByFile::iterator itByPath = byPath.find (path);
109
107
if (byPath.end () == itByPath)
110
108
return false ;
111
109
112
110
TDefByEvt &byEvt = itByPath->second ;
111
+ assert (!byEvt.empty ());
113
112
if (!d->usePartialResults && byEvt.end () != byEvt.find (" internal warning" ))
114
113
// if the analyzer produced an "internal warning" diagnostic message,
115
114
// we assume partial results, which cannot be reliably used for
@@ -124,16 +123,31 @@ bool DefLookup::lookup(const Defect &def)
124
123
125
124
// look by msg
126
125
TDefByMsg &byMsg = itByEvent->second ;
126
+ assert (!byMsg.empty ());
127
127
const std::string msg = filter.filterMsg (evt.msg , def.checker );
128
128
TDefByMsg::iterator itByMsg = byMsg.find (msg);
129
129
if (byMsg.end () == itByMsg)
130
130
return false ;
131
131
132
132
// process the resulting list of defects sequentially
133
133
TDefList &defList = itByMsg->second ;
134
+ assert (!defList.empty ());
134
135
if (!defLookupCore (defList))
135
136
return false ;
136
137
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
+
137
151
// found!
138
152
return true ;
139
153
}
0 commit comments