@@ -190,8 +190,8 @@ CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
190
190
static int GetnScore (const CService& addr)
191
191
{
192
192
LOCK (cs_mapLocalHost);
193
- if ( mapLocalHost.count (addr) == 0 ) return 0 ;
194
- return mapLocalHost[addr]. nScore ;
193
+ const auto it = mapLocalHost.find (addr);
194
+ return (it != mapLocalHost. end ()) ? it-> second . nScore : 0 ;
195
195
}
196
196
197
197
// Is our peer's addrLocal potentially useful as an external IP source?
@@ -243,10 +243,10 @@ bool AddLocal(const CService& addr, int nScore)
243
243
244
244
{
245
245
LOCK (cs_mapLocalHost);
246
- bool fAlready = mapLocalHost.count (addr) > 0 ;
247
- LocalServiceInfo &info = mapLocalHost[addr] ;
248
- if (! fAlready || nScore >= info.nScore ) {
249
- info.nScore = nScore + (fAlready ? 1 : 0 );
246
+ const auto [it, is_newly_added] = mapLocalHost.emplace (addr, LocalServiceInfo ()) ;
247
+ LocalServiceInfo &info = it-> second ;
248
+ if (is_newly_added || nScore >= info.nScore ) {
249
+ info.nScore = nScore + (is_newly_added ? 0 : 1 );
250
250
info.nPort = addr.GetPort ();
251
251
}
252
252
}
@@ -288,12 +288,10 @@ bool IsReachable(const CNetAddr &addr)
288
288
/* * vote for a local address */
289
289
bool SeenLocal (const CService& addr)
290
290
{
291
- {
292
- LOCK (cs_mapLocalHost);
293
- if (mapLocalHost.count (addr) == 0 )
294
- return false ;
295
- mapLocalHost[addr].nScore ++;
296
- }
291
+ LOCK (cs_mapLocalHost);
292
+ const auto it = mapLocalHost.find (addr);
293
+ if (it == mapLocalHost.end ()) return false ;
294
+ ++it->second .nScore ;
297
295
return true ;
298
296
}
299
297
0 commit comments