Index: cc/resources/resource_pool.cc |
diff --git a/cc/resources/resource_pool.cc b/cc/resources/resource_pool.cc |
index 835c37d6c32d9f23029bcfea419ad6f8f2b3f2fc..227fecf43b1ca51bf07a053094a17171ef909b15 100644 |
--- a/cc/resources/resource_pool.cc |
+++ b/cc/resources/resource_pool.cc |
@@ -91,8 +91,12 @@ ResourcePool::~ResourcePool() { |
Resource* ResourcePool::AcquireResource(const gfx::Size& size, |
ResourceFormat format) { |
- for (ResourceDeque::iterator it = unused_resources_.begin(); |
- it != unused_resources_.end(); ++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 it = unused_resources_.rbegin(); |
+ it != unused_resources_.rend(); ++it) { |
ScopedResource* resource = *it; |
DCHECK(resource_provider_->CanLockForWrite(resource->id())); |
@@ -102,7 +106,7 @@ Resource* ResourcePool::AcquireResource(const gfx::Size& size, |
continue; |
// Transfer resource to |in_use_resources_|. |
- in_use_resources_.set(resource->id(), unused_resources_.take(it)); |
+ in_use_resources_.set(resource->id(), unused_resources_.rtake(it)); |
in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( |
resource->size(), resource->format()); |
return resource; |
@@ -130,18 +134,22 @@ Resource* ResourcePool::AcquireResource(const gfx::Size& size, |
Resource* ResourcePool::TryAcquireResourceWithContentId(uint64_t content_id) { |
reveman
2015/11/02 01:47:07
It shouldn't matter in what order we search the re
prashant.n
2015/11/02 04:07:20
Ahh! I missed one content id = one resource (next_
|
DCHECK(content_id); |
- auto it = std::find_if(unused_resources_.begin(), unused_resources_.end(), |
- [content_id](const PoolResource* pool_resource) { |
- return pool_resource->content_id() == content_id; |
- }); |
- if (it == unused_resources_.end()) |
+ // TODO(prashant.n): Move resource finding logic to common function. |
reveman
2015/11/02 01:47:07
I don't see much duplication of resource finding l
prashant.n
2015/11/02 04:07:20
Yes most of the code in getting resource from unus
reveman
2015/11/02 04:32:59
Ok, feel free to put up a patch for that and I'll
|
+ ResourceDeque::reverse_iterator it = unused_resources_.rbegin(); |
+ for (; it != unused_resources_.rend(); ++it) { |
+ PoolResource* pool_resource = *it; |
+ if (pool_resource->content_id() != content_id) |
+ continue; |
+ } |
+ |
+ if (it == unused_resources_.rend()) |
return nullptr; |
Resource* resource = *it; |
DCHECK(resource_provider_->CanLockForWrite(resource->id())); |
// Transfer resource to |in_use_resources_|. |
- in_use_resources_.set(resource->id(), unused_resources_.take(it)); |
+ in_use_resources_.set(resource->id(), unused_resources_.rtake(it)); |
in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( |
resource->size(), resource->format()); |
return resource; |