@@ -975,31 +975,31 @@ using namespace std;
975975void
976976imgCacheQueue::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)
10261026already_AddRefed<imgCacheEntry>
10271027imgCacheQueue::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()
10651065uint32_t
10661066imgCacheQueue::GetNumElements () const
10671067{
1068- return mQueue .size ();
1068+ return mQueue .Length ();
10691069}
10701070
10711071imgCacheQueue::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 }
0 commit comments