Bug 1396870 P1 Avoid dirting the image cache queue when inserting a new item into a clean queue. r=tnikkel

This commit is contained in:
Ben Kelly 2017-09-05 16:20:17 -07:00
Родитель 6b32afedd6
Коммит 43dc8a817a
1 изменённых файлов: 7 добавлений и 1 удалений

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

@ -990,7 +990,11 @@ imgCacheQueue::Push(imgCacheEntry* entry)
RefPtr<imgCacheEntry> refptr(entry);
mQueue.push_back(refptr);
MarkDirty();
// If we're not dirty already, then we can efficiently add this to the
// binary heap immediately. This is only O(log n).
if (!IsDirty()) {
std::push_heap(mQueue.begin(), mQueue.end(), imgLoader::CompareCacheEntries);
}
}
already_AddRefed<imgCacheEntry>
@ -1014,6 +1018,8 @@ imgCacheQueue::Pop()
void
imgCacheQueue::Refresh()
{
// Resort the list. This is an O(3 * n) operation and best avoided
// if possible.
std::make_heap(mQueue.begin(), mQueue.end(), imgLoader::CompareCacheEntries);
mDirty = false;
}