Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 35a2daf

Browse files
committed
Bug 1396982 Make imageCacheQueue use nsTArray instead of std::vector. r=tnikkel
1 parent 437049b commit 35a2daf

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

image/imgLoader.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -975,31 +975,31 @@ using namespace std;
975975
void
976976
imgCacheQueue::Remove(imgCacheEntry* entry)
977977
{
978-
auto it = find(mQueue.begin(), mQueue.end(), entry);
979-
if (it == mQueue.end()) {
978+
uint64_t index = mQueue.IndexOf(entry);
979+
if (index == queueContainer::NoIndex) {
980980
return;
981981
}
982982

983-
mSize -= (*it)->GetDataSize();
983+
mSize -= mQueue[index]->GetDataSize();
984984

985985
// If the queue is clean and this is the first entry,
986986
// then we can efficiently remove the entry without
987987
// dirtying the sort order.
988-
if (!IsDirty() && it == mQueue.begin()) {
988+
if (!IsDirty() && index == 0) {
989989
std::pop_heap(mQueue.begin(), mQueue.end(),
990990
imgLoader::CompareCacheEntries);
991-
mQueue.pop_back();
991+
mQueue.RemoveElementAt(mQueue.Length() - 1);
992992
return;
993993
}
994994

995995
// Remove from the middle of the list. This potentially
996996
// breaks the binary heap sort order.
997-
mQueue.erase(it);
997+
mQueue.RemoveElementAt(index);
998998

999999
// If we only have one entry or the queue is empty, though,
10001000
// then the sort order is still effectively good. Simply
10011001
// refresh the list to clear the dirty flag.
1002-
if (mQueue.size() <= 1) {
1002+
if (mQueue.Length() <= 1) {
10031003
Refresh();
10041004
return;
10051005
}
@@ -1015,7 +1015,7 @@ imgCacheQueue::Push(imgCacheEntry* entry)
10151015
mSize += entry->GetDataSize();
10161016

10171017
RefPtr<imgCacheEntry> refptr(entry);
1018-
mQueue.push_back(refptr);
1018+
mQueue.AppendElement(Move(refptr));
10191019
// If we're not dirty already, then we can efficiently add this to the
10201020
// binary heap immediately. This is only O(log n).
10211021
if (!IsDirty()) {
@@ -1026,16 +1026,16 @@ imgCacheQueue::Push(imgCacheEntry* entry)
10261026
already_AddRefed<imgCacheEntry>
10271027
imgCacheQueue::Pop()
10281028
{
1029-
if (mQueue.empty()) {
1029+
if (mQueue.IsEmpty()) {
10301030
return nullptr;
10311031
}
10321032
if (IsDirty()) {
10331033
Refresh();
10341034
}
10351035

1036-
RefPtr<imgCacheEntry> entry = mQueue[0];
10371036
std::pop_heap(mQueue.begin(), mQueue.end(), imgLoader::CompareCacheEntries);
1038-
mQueue.pop_back();
1037+
RefPtr<imgCacheEntry> entry = Move(mQueue.LastElement());
1038+
mQueue.RemoveElementAt(mQueue.Length() - 1);
10391039

10401040
mSize -= entry->GetDataSize();
10411041
return entry.forget();
@@ -1065,7 +1065,7 @@ imgCacheQueue::IsDirty()
10651065
uint32_t
10661066
imgCacheQueue::GetNumElements() const
10671067
{
1068-
return mQueue.size();
1068+
return mQueue.Length();
10691069
}
10701070

10711071
imgCacheQueue::iterator
@@ -2046,13 +2046,13 @@ imgLoader::EvictEntries(imgCacheQueue& aQueueToClear)
20462046
// We have to make a temporary, since RemoveFromCache removes the element
20472047
// from the queue, invalidating iterators.
20482048
nsTArray<RefPtr<imgCacheEntry> > entries(aQueueToClear.GetNumElements());
2049-
for (imgCacheQueue::const_iterator i = aQueueToClear.begin();
2050-
i != aQueueToClear.end(); ++i) {
2049+
for (auto i = aQueueToClear.begin(); i != aQueueToClear.end(); ++i) {
20512050
entries.AppendElement(*i);
20522051
}
20532052

2054-
for (uint32_t i = 0; i < entries.Length(); ++i) {
2055-
if (!RemoveFromCache(entries[i])) {
2053+
// Iterate in reverse order to minimize array copying.
2054+
for (auto& entry : entries) {
2055+
if (!RemoveFromCache(entry)) {
20562056
return NS_ERROR_FAILURE;
20572057
}
20582058
}

image/imgLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class imgCacheQueue
201201
uint32_t GetSize() const;
202202
void UpdateSize(int32_t diff);
203203
uint32_t GetNumElements() const;
204-
typedef std::vector<RefPtr<imgCacheEntry> > queueContainer;
204+
typedef nsTArray<RefPtr<imgCacheEntry> > queueContainer;
205205
typedef queueContainer::iterator iterator;
206206
typedef queueContainer::const_iterator const_iterator;
207207

0 commit comments

Comments
 (0)