mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1372323 - Use LookupForAdd instead of Get+Put to avoid unnecessary hashtable lookups. r=froydnj
MozReview-Commit-ID: GWsRF1vSLXx
This commit is contained in:
parent
45166146e9
commit
95d8ecc7bf
@ -2195,15 +2195,19 @@ Console::IncreaseCounter(JSContext* aCx, const Sequence<JS::Value>& aArguments,
|
||||
|
||||
aCountLabel = string;
|
||||
|
||||
uint32_t count = 0;
|
||||
if (!mCounterRegistry.Get(aCountLabel, &count) &&
|
||||
mCounterRegistry.Count() >= MAX_PAGE_COUNTERS) {
|
||||
return MAX_PAGE_COUNTERS;
|
||||
const bool maxCountersReached = mCounterRegistry.Count() >= MAX_PAGE_COUNTERS;
|
||||
auto entry = mCounterRegistry.LookupForAdd(aCountLabel);
|
||||
if (entry) {
|
||||
++entry.Data();
|
||||
} else {
|
||||
entry.OrInsert([](){ return 1; });
|
||||
if (maxCountersReached) {
|
||||
// oops, we speculatively added an entry even though we shouldn't
|
||||
mCounterRegistry.Remove(aCountLabel);
|
||||
return MAX_PAGE_COUNTERS;
|
||||
}
|
||||
}
|
||||
|
||||
++count;
|
||||
mCounterRegistry.Put(aCountLabel, count);
|
||||
return count;
|
||||
return entry.Data();
|
||||
}
|
||||
|
||||
JS::Value
|
||||
|
Loading…
Reference in New Issue
Block a user