зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1688833 - Migrate LookupForAdd to WithEntryHandle in dom/console. r=nika
Differential Revision: https://phabricator.services.mozilla.com/D104228
This commit is contained in:
Родитель
8efcd9e1fd
Коммит
ba3b6a2b06
|
@ -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,
|
||||
|
|
Загрузка…
Ссылка в новой задаче