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

Unified Diff: chrome/common/instant_restricted_id_cache.h

Issue 12742014: Instant: Allow empty sets to be added to the cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/common/instant_restricted_id_cache_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/instant_restricted_id_cache.h
diff --git a/chrome/common/instant_restricted_id_cache.h b/chrome/common/instant_restricted_id_cache.h
index 66ae060a754be541c57df73a9230ad069c903ab8..1ca09ebffb77c116d9505273cf0ba2900440e330 100644
--- a/chrome/common/instant_restricted_id_cache.h
+++ b/chrome/common/instant_restricted_id_cache.h
@@ -68,6 +68,7 @@ class InstantRestrictedIDCache {
FRIEND_TEST_ALL_PREFIXES(InstantRestrictedIDCacheTest, CrazyIDGeneration);
FRIEND_TEST_ALL_PREFIXES(InstantRestrictedIDCacheTest, ManualIDGeneration);
FRIEND_TEST_ALL_PREFIXES(InstantRestrictedIDCacheTest, MixIDGeneration);
+ FRIEND_TEST_ALL_PREFIXES(InstantRestrictedIDCacheTest, AddEmptySet);
typedef base::MRUCache<InstantRestrictedID, T> CacheImpl;
@@ -92,9 +93,14 @@ InstantRestrictedIDCache<T>::~InstantRestrictedIDCache() {
template <typename T>
void InstantRestrictedIDCache<T>::AddItems(const ItemVector& items) {
- if (items.size() == 0 || items.size() > cache_.max_size())
+ if (items.size() > cache_.max_size())
return;
brettw 2013/03/25 22:26:52 I'm wondering about this. If you add too many item
sreeram 2013/03/25 22:29:33 Adding too many items would be an error situation,
brettw 2013/03/25 22:34:04 Yeah, I like the dcheck.
sreeram 2013/03/25 22:39:26 Done.
+ if (items.empty()) {
+ last_add_start_ = cache_.rend();
+ return;
+ }
+
for (size_t i = 0; i < items.size(); ++i) {
InstantRestrictedID id = ++last_restricted_id_;
cache_.Put(id, items[i]);
@@ -106,9 +112,14 @@ void InstantRestrictedIDCache<T>::AddItems(const ItemVector& items) {
template <typename T>
void InstantRestrictedIDCache<T>::AddItemsWithRestrictedID(
const ItemIDVector& items) {
- if (items.size() == 0 || items.size() > cache_.max_size())
+ if (items.size() > cache_.max_size())
return;
+ if (items.empty()) {
+ last_add_start_ = cache_.rend();
+ return;
+ }
+
std::set<InstantRestrictedID> ids_added;
for (size_t i = 0; i < items.size(); ++i) {
const ItemIDPair& item_id = items[i];
« no previous file with comments | « no previous file | chrome/common/instant_restricted_id_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698