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

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: DCHECK 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..b0c2b3ba05e44eb294577ccdb18d3ad7222274b4 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,8 +93,12 @@ InstantRestrictedIDCache<T>::~InstantRestrictedIDCache() {
template <typename T>
void InstantRestrictedIDCache<T>::AddItems(const ItemVector& items) {
- if (items.size() == 0 || items.size() > cache_.max_size())
+ DCHECK_LE(items.size(), cache_.max_size());
+
+ if (items.empty()) {
+ last_add_start_ = cache_.rend();
return;
+ }
for (size_t i = 0; i < items.size(); ++i) {
InstantRestrictedID id = ++last_restricted_id_;
@@ -106,8 +111,12 @@ 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())
+ DCHECK_LE(items.size(), cache_.max_size());
+
+ if (items.empty()) {
+ last_add_start_ = cache_.rend();
return;
+ }
std::set<InstantRestrictedID> ids_added;
for (size_t i = 0; i < items.size(); ++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