Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Unified Diff: cc/resources/resource_pool.cc

Issue 1420433009: cc: Keep most recently used resources at the front of resource queue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« cc/resources/resource_pool.h ('K') | « cc/resources/resource_pool.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>(
« cc/resources/resource_pool.h ('K') | « cc/resources/resource_pool.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698