mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Bug 1396982 Make imageCacheQueue use nsTArray instead of std::vector. r=tnikkel
This commit is contained in:
parent
437049b633
commit
35a2dafbcf
@ -975,31 +975,31 @@ using namespace std;
|
|||||||
void
|
void
|
||||||
imgCacheQueue::Remove(imgCacheEntry* entry)
|
imgCacheQueue::Remove(imgCacheEntry* entry)
|
||||||
{
|
{
|
||||||
auto it = find(mQueue.begin(), mQueue.end(), entry);
|
uint64_t index = mQueue.IndexOf(entry);
|
||||||
if (it == mQueue.end()) {
|
if (index == queueContainer::NoIndex) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mSize -= (*it)->GetDataSize();
|
mSize -= mQueue[index]->GetDataSize();
|
||||||
|
|
||||||
// If the queue is clean and this is the first entry,
|
// If the queue is clean and this is the first entry,
|
||||||
// then we can efficiently remove the entry without
|
// then we can efficiently remove the entry without
|
||||||
// dirtying the sort order.
|
// dirtying the sort order.
|
||||||
if (!IsDirty() && it == mQueue.begin()) {
|
if (!IsDirty() && index == 0) {
|
||||||
std::pop_heap(mQueue.begin(), mQueue.end(),
|
std::pop_heap(mQueue.begin(), mQueue.end(),
|
||||||
imgLoader::CompareCacheEntries);
|
imgLoader::CompareCacheEntries);
|
||||||
mQueue.pop_back();
|
mQueue.RemoveElementAt(mQueue.Length() - 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove from the middle of the list. This potentially
|
// Remove from the middle of the list. This potentially
|
||||||
// breaks the binary heap sort order.
|
// breaks the binary heap sort order.
|
||||||
mQueue.erase(it);
|
mQueue.RemoveElementAt(index);
|
||||||
|
|
||||||
// If we only have one entry or the queue is empty, though,
|
// If we only have one entry or the queue is empty, though,
|
||||||
// then the sort order is still effectively good. Simply
|
// then the sort order is still effectively good. Simply
|
||||||
// refresh the list to clear the dirty flag.
|
// refresh the list to clear the dirty flag.
|
||||||
if (mQueue.size() <= 1) {
|
if (mQueue.Length() <= 1) {
|
||||||
Refresh();
|
Refresh();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1015,7 +1015,7 @@ imgCacheQueue::Push(imgCacheEntry* entry)
|
|||||||
mSize += entry->GetDataSize();
|
mSize += entry->GetDataSize();
|
||||||
|
|
||||||
RefPtr<imgCacheEntry> refptr(entry);
|
RefPtr<imgCacheEntry> refptr(entry);
|
||||||
mQueue.push_back(refptr);
|
mQueue.AppendElement(Move(refptr));
|
||||||
// If we're not dirty already, then we can efficiently add this to the
|
// If we're not dirty already, then we can efficiently add this to the
|
||||||
// binary heap immediately. This is only O(log n).
|
// binary heap immediately. This is only O(log n).
|
||||||
if (!IsDirty()) {
|
if (!IsDirty()) {
|
||||||
@ -1026,16 +1026,16 @@ imgCacheQueue::Push(imgCacheEntry* entry)
|
|||||||
already_AddRefed<imgCacheEntry>
|
already_AddRefed<imgCacheEntry>
|
||||||
imgCacheQueue::Pop()
|
imgCacheQueue::Pop()
|
||||||
{
|
{
|
||||||
if (mQueue.empty()) {
|
if (mQueue.IsEmpty()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (IsDirty()) {
|
if (IsDirty()) {
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<imgCacheEntry> entry = mQueue[0];
|
|
||||||
std::pop_heap(mQueue.begin(), mQueue.end(), imgLoader::CompareCacheEntries);
|
std::pop_heap(mQueue.begin(), mQueue.end(), imgLoader::CompareCacheEntries);
|
||||||
mQueue.pop_back();
|
RefPtr<imgCacheEntry> entry = Move(mQueue.LastElement());
|
||||||
|
mQueue.RemoveElementAt(mQueue.Length() - 1);
|
||||||
|
|
||||||
mSize -= entry->GetDataSize();
|
mSize -= entry->GetDataSize();
|
||||||
return entry.forget();
|
return entry.forget();
|
||||||
@ -1065,7 +1065,7 @@ imgCacheQueue::IsDirty()
|
|||||||
uint32_t
|
uint32_t
|
||||||
imgCacheQueue::GetNumElements() const
|
imgCacheQueue::GetNumElements() const
|
||||||
{
|
{
|
||||||
return mQueue.size();
|
return mQueue.Length();
|
||||||
}
|
}
|
||||||
|
|
||||||
imgCacheQueue::iterator
|
imgCacheQueue::iterator
|
||||||
@ -2046,13 +2046,13 @@ imgLoader::EvictEntries(imgCacheQueue& aQueueToClear)
|
|||||||
// We have to make a temporary, since RemoveFromCache removes the element
|
// We have to make a temporary, since RemoveFromCache removes the element
|
||||||
// from the queue, invalidating iterators.
|
// from the queue, invalidating iterators.
|
||||||
nsTArray<RefPtr<imgCacheEntry> > entries(aQueueToClear.GetNumElements());
|
nsTArray<RefPtr<imgCacheEntry> > entries(aQueueToClear.GetNumElements());
|
||||||
for (imgCacheQueue::const_iterator i = aQueueToClear.begin();
|
for (auto i = aQueueToClear.begin(); i != aQueueToClear.end(); ++i) {
|
||||||
i != aQueueToClear.end(); ++i) {
|
|
||||||
entries.AppendElement(*i);
|
entries.AppendElement(*i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; i < entries.Length(); ++i) {
|
// Iterate in reverse order to minimize array copying.
|
||||||
if (!RemoveFromCache(entries[i])) {
|
for (auto& entry : entries) {
|
||||||
|
if (!RemoveFromCache(entry)) {
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,7 @@ public:
|
|||||||
uint32_t GetSize() const;
|
uint32_t GetSize() const;
|
||||||
void UpdateSize(int32_t diff);
|
void UpdateSize(int32_t diff);
|
||||||
uint32_t GetNumElements() const;
|
uint32_t GetNumElements() const;
|
||||||
typedef std::vector<RefPtr<imgCacheEntry> > queueContainer;
|
typedef nsTArray<RefPtr<imgCacheEntry> > queueContainer;
|
||||||
typedef queueContainer::iterator iterator;
|
typedef queueContainer::iterator iterator;
|
||||||
typedef queueContainer::const_iterator const_iterator;
|
typedef queueContainer::const_iterator const_iterator;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user