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

Side by Side Diff: base/containers/mru_cache.h

Issue 2844443002: Remove warning about std::map::emplace (Closed)
Patch Set: Created 3 years, 7 months 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 | styleguide/c++/c++11.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // This file contains a template for a Most Recently Used cache that allows 5 // This file contains a template for a Most Recently Used cache that allows
6 // constant-time access to items using a key, but easy identification of the 6 // constant-time access to items using a key, but easy identification of the
7 // least-recently-used items for removal. Each key can only be associated with 7 // least-recently-used items for removal. Each key can only be associated with
8 // one payload item at a time. 8 // one payload item at a time.
9 // 9 //
10 // The key object will be stored twice, so it should support efficient copying. 10 // The key object will be stored twice, so it should support efficient copying.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 if (index_iter != index_.end()) { 90 if (index_iter != index_.end()) {
91 // Erase the reference to it. The index reference will be replaced in the 91 // Erase the reference to it. The index reference will be replaced in the
92 // code below. 92 // code below.
93 Erase(index_iter->second); 93 Erase(index_iter->second);
94 } else if (max_size_ != NO_AUTO_EVICT) { 94 } else if (max_size_ != NO_AUTO_EVICT) {
95 // New item is being inserted which might make it larger than the maximum 95 // New item is being inserted which might make it larger than the maximum
96 // size: kick the oldest thing out if necessary. 96 // size: kick the oldest thing out if necessary.
97 ShrinkToSize(max_size_ - 1); 97 ShrinkToSize(max_size_ - 1);
98 } 98 }
99 99
100 ordering_.push_front(value_type(key, std::forward<Payload>(payload))); 100 ordering_.emplace_front(key, std::forward<Payload>(payload));
101 index_.insert(std::make_pair(key, ordering_.begin())); 101 index_.emplace(key, ordering_.begin());
jdoerrie 2017/04/25 11:33:47 While |index_|'s type is a template parameter, it
102 return ordering_.begin(); 102 return ordering_.begin();
103 } 103 }
104 104
105 // Retrieves the contents of the given key, or end() if not found. This method 105 // Retrieves the contents of the given key, or end() if not found. This method
106 // has the side effect of moving the requested item to the front of the 106 // has the side effect of moving the requested item to the front of the
107 // recency list. 107 // recency list.
108 iterator Get(const KeyType& key) { 108 iterator Get(const KeyType& key) {
109 typename KeyIndex::iterator index_iter = index_.find(key); 109 typename KeyIndex::iterator index_iter = index_.find(key);
110 if (index_iter == index_.end()) 110 if (index_iter == index_.end())
111 return end(); 111 return end();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 : ParentType(max_size) {} 247 : ParentType(max_size) {}
248 virtual ~HashingMRUCache() {} 248 virtual ~HashingMRUCache() {}
249 249
250 private: 250 private:
251 DISALLOW_COPY_AND_ASSIGN(HashingMRUCache); 251 DISALLOW_COPY_AND_ASSIGN(HashingMRUCache);
252 }; 252 };
253 253
254 } // namespace base 254 } // namespace base
255 255
256 #endif // BASE_CONTAINERS_MRU_CACHE_H_ 256 #endif // BASE_CONTAINERS_MRU_CACHE_H_
OLDNEW
« no previous file with comments | « no previous file | styleguide/c++/c++11.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698