Index: cc/resources/resource_pool.cc |
diff --git a/cc/resources/resource_pool.cc b/cc/resources/resource_pool.cc |
index 835c37d6c32d9f23029bcfea419ad6f8f2b3f2fc..2a9a10c7cc3f04c69293289b2d3961afdea695e9 100644 |
--- a/cc/resources/resource_pool.cc |
+++ b/cc/resources/resource_pool.cc |
@@ -91,9 +91,13 @@ ResourcePool::~ResourcePool() { |
Resource* ResourcePool::AcquireResource(const gfx::Size& size, |
ResourceFormat format) { |
- for (ResourceDeque::iterator it = unused_resources_.begin(); |
- it != unused_resources_.end(); ++it) { |
- ScopedResource* resource = *it; |
+ // Traverse the |unused_resources_| from rear end as MRU resources are |
+ // held at the rear end of the queue. This touches LRU resources only if |
+ // needed, which inreases possibility of expiring more LRU resources |
+ // within kResourceExpirationDelayMs. |
+ for (ResourceDeque::reverse_iterator rit = unused_resources_.rbegin(); |
+ rit != unused_resources_.rend(); ++rit) { |
+ ScopedResource* resource = *rit; |
DCHECK(resource_provider_->CanLockForWrite(resource->id())); |
if (resource->format() != format) |
@@ -101,6 +105,9 @@ Resource* ResourcePool::AcquireResource(const gfx::Size& size, |
if (resource->size() != size) |
continue; |
+ // Get iterator from reverse_iterator pointing to the same resource. |
+ ResourceDeque::iterator it = |
+ static_cast<ResourceDeque::iterator>(--rit.base()); |
reveman
2015/11/02 06:07:51
if we need this then can we add a base() function
prashant.n
2015/11/02 17:56:45
IMO, iterators are different, so typecast would be
|
// Transfer resource to |in_use_resources_|. |
in_use_resources_.set(resource->id(), unused_resources_.take(it)); |
in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( |