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

Side by Side Diff: cc/base/scoped_ptr_deque.h

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: Corrected implementation. 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 unified diff | Download patch
« no previous file with comments | « no previous file | cc/resources/resource_pool.h » ('j') | cc/resources/resource_pool.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CC_BASE_SCOPED_PTR_DEQUE_H_ 5 #ifndef CC_BASE_SCOPED_PTR_DEQUE_H_
6 #define CC_BASE_SCOPED_PTR_DEQUE_H_ 6 #define CC_BASE_SCOPED_PTR_DEQUE_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <deque> 9 #include <deque>
10 10
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 data_.insert(position, item.release()); 99 data_.insert(position, item.release());
100 } 100 }
101 101
102 scoped_ptr<T> take(iterator position) { 102 scoped_ptr<T> take(iterator position) {
103 DCHECK(position < end()); 103 DCHECK(position < end());
104 scoped_ptr<T> ret(*position); 104 scoped_ptr<T> ret(*position);
105 data_.erase(position); 105 data_.erase(position);
106 return ret.Pass(); 106 return ret.Pass();
107 } 107 }
108 108
109 scoped_ptr<T> rtake(reverse_iterator position) {
reveman 2015/11/02 01:47:07 Instead of adding this, can the user of this class
prashant.n 2015/11/02 04:07:20 I think same thing we'll have to do. iterator it
reveman 2015/11/02 04:32:59 as there's no rerase in std::deque I think it's be
110 DCHECK(position < rend());
111 scoped_ptr<T> ret(*position);
112 data_.erase(--position.base());
113 return ret.Pass();
114 }
115
109 void swap(iterator a, iterator b) { 116 void swap(iterator a, iterator b) {
110 DCHECK(a < end()); 117 DCHECK(a < end());
111 DCHECK(b < end()); 118 DCHECK(b < end());
112 if (a == end() || b == end() || a == b) 119 if (a == end() || b == end() || a == b)
113 return; 120 return;
114 typename std::deque<T*>::iterator writable_a = a; 121 typename std::deque<T*>::iterator writable_a = a;
115 typename std::deque<T*>::iterator writable_b = b; 122 typename std::deque<T*>::iterator writable_b = b;
116 std::swap(*writable_a, *writable_b); 123 std::swap(*writable_a, *writable_b);
117 } 124 }
118 125
119 iterator begin() { return static_cast<iterator>(data_.begin()); } 126 iterator begin() { return static_cast<iterator>(data_.begin()); }
120 const_iterator begin() const { return data_.begin(); } 127 const_iterator begin() const { return data_.begin(); }
121 iterator end() { return static_cast<iterator>(data_.end()); } 128 iterator end() { return static_cast<iterator>(data_.end()); }
122 const_iterator end() const { return data_.end(); } 129 const_iterator end() const { return data_.end(); }
123 130
124 reverse_iterator rbegin() { return data_.rbegin(); } 131 reverse_iterator rbegin() { return data_.rbegin(); }
125 const_reverse_iterator rbegin() const { return data_.rbegin(); } 132 const_reverse_iterator rbegin() const { return data_.rbegin(); }
126 reverse_iterator rend() { return data_.rend(); } 133 reverse_iterator rend() { return data_.rend(); }
127 const_reverse_iterator rend() const { return data_.rend(); } 134 const_reverse_iterator rend() const { return data_.rend(); }
128 135
129 private: 136 private:
130 std::deque<T*> data_; 137 std::deque<T*> data_;
131 138
132 DISALLOW_COPY_AND_ASSIGN(ScopedPtrDeque); 139 DISALLOW_COPY_AND_ASSIGN(ScopedPtrDeque);
133 }; 140 };
134 141
135 } // namespace cc 142 } // namespace cc
136 143
137 #endif // CC_BASE_SCOPED_PTR_DEQUE_H_ 144 #endif // CC_BASE_SCOPED_PTR_DEQUE_H_
OLDNEW
« no previous file with comments | « no previous file | cc/resources/resource_pool.h » ('j') | cc/resources/resource_pool.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698