Bug 1372274 - Use LookupForAdd instead of Get+Put, and LookupRemoveIf instead of Get+Remove, to avoid unnecessary hashtable lookups. r=froydnj

MozReview-Commit-ID: Fo23d82qpaP
This commit is contained in:
Mats Palmgren 2017-06-14 17:27:25 +02:00
Родитель cfd3f9f9cf
Коммит 45166146e9
1 изменённых файлов: 12 добавлений и 7 удалений

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

@ -2026,12 +2026,11 @@ Console::StartTimer(JSContext* aCx, const JS::Value& aName,
aTimerLabel = label;
DOMHighResTimeStamp entry = 0;
if (mTimerRegistry.Get(label, &entry)) {
auto entry = mTimerRegistry.LookupForAdd(label);
if (entry) {
return eTimerAlreadyExists;
}
mTimerRegistry.Put(label, aTimestamp);
entry.OrInsert([&aTimestamp](){ return aTimestamp; });
*aTimerValue = aTimestamp;
return eTimerDone;
@ -2084,12 +2083,18 @@ Console::StopTimer(JSContext* aCx, const JS::Value& aName,
aTimerLabel = key;
DOMHighResTimeStamp entry = 0;
if (NS_WARN_IF(!mTimerRegistry.Get(key, &entry))) {
bool found = false;
mTimerRegistry.LookupRemoveIf(key,
[&found, &entry] (const DOMHighResTimeStamp& aValue) {
entry = aValue;
found = true;
return true; // remove it
});
if (NS_WARN_IF(!found)) {
return eTimerDoesntExist;
}
mTimerRegistry.Remove(key);
*aTimerDuration = aTimestamp - entry;
return eTimerDone;
}