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

Unified Diff: net/disk_cache/simple/simple_index.cc

Issue 22406005: Index initialization improvements for Simple Cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add unit test, fix windows build. Created 7 years, 4 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 | net/disk_cache/simple/simple_index_file.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/simple/simple_index.cc
diff --git a/net/disk_cache/simple/simple_index.cc b/net/disk_cache/simple/simple_index.cc
index caec19f6068fd9fa2e1571558419ad2ca3096b71..78ce87ed71d6c9006f3b67cdfc5575d3bc9439b3 100644
--- a/net/disk_cache/simple/simple_index.cc
+++ b/net/disk_cache/simple/simple_index.cc
@@ -359,18 +359,24 @@ void SimpleIndex::MergeInitializingSet(
index_file_entries->erase(*it);
}
- // Recalculate the cache size while merging the two sets.
- for (EntrySet::const_iterator it = index_file_entries->begin();
+ for (EntrySet::const_iterator it = entries_set_.begin();
+ it != entries_set_.end(); ++it) {
+ const uint64 entry_hash = it->first;
+ std::pair<EntrySet::iterator, bool> insert_result =
+ index_file_entries->insert(EntrySet::value_type(entry_hash,
+ EntryMetadata()));
+ EntrySet::iterator& possibly_inserted_entry = insert_result.first;
+ possibly_inserted_entry->second = it->second;
Randy Smith (Not in Mondays) 2013/08/12 17:02:20 Suggestion: Why not test insert_result.second to d
gavinp 2013/08/13 11:11:05 I think it's just a copy of EntrySet::data_type yo
+ }
+
+ uint64 merged_cache_size = 0;
+ for (EntrySet::iterator it = index_file_entries->begin();
it != index_file_entries->end(); ++it) {
- // If there is already an entry in the current entries_set_, we need to
- // merge the new data there with the data loaded in the initialization.
- EntrySet::iterator current_entry = entries_set_.find(it->first);
- // When Merging, existing data in the |current_entry| will prevail.
- if (current_entry == entries_set_.end()) {
- InsertInEntrySet(it->first, it->second, &entries_set_);
- cache_size_ += it->second.GetEntrySize();
- }
+ merged_cache_size += it->second.GetEntrySize();
}
+
+ entries_set_.swap(*index_file_entries);
+ cache_size_ = merged_cache_size;
initialized_ = true;
removed_entries_.clear();
« no previous file with comments | « no previous file | net/disk_cache/simple/simple_index_file.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698