Bug 1688833 - Migrate LookupForAdd to WithEntryHandle in dom/console. r=nika

Differential Revision: https://phabricator.services.mozilla.com/D104228
This commit is contained in:
Simon Giesecke 2021-02-09 18:19:44 +00:00
Родитель 8efcd9e1fd
Коммит ba3b6a2b06
1 изменённых файлов: 19 добавлений и 15 удалений

Просмотреть файл

@ -2118,11 +2118,15 @@ Console::TimerStatus Console::StartTimer(JSContext* aCx, const JS::Value& aName,
aTimerLabel = label;
auto entry = mTimerRegistry.LookupForAdd(label);
if (entry) {
if (mTimerRegistry.WithEntryHandle(label, [&](auto&& entry) {
if (entry) {
return true;
}
entry.Insert(aTimestamp);
return false;
})) {
return eTimerAlreadyExists;
}
entry.OrInsert([&aTimestamp]() { return aTimestamp; });
*aTimerValue = aTimestamp;
return eTimerDone;
@ -2274,18 +2278,18 @@ uint32_t Console::IncreaseCounter(JSContext* aCx,
aCountLabel = string;
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;
}
}
return entry.Data();
return mCounterRegistry.WithEntryHandle(
aCountLabel, [maxCountersReached](auto&& entry) -> uint32_t {
if (entry) {
++entry.Data();
} else {
if (maxCountersReached) {
return MAX_PAGE_COUNTERS;
}
entry.Insert(1);
}
return entry.Data();
});
}
uint32_t Console::ResetCounter(JSContext* aCx,