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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/disk_cache/simple/simple_index_file.h » ('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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #include "net/disk_cache/simple/simple_index.h" 5 #include "net/disk_cache/simple/simple_index.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 352
353 SimpleIndex::EntrySet* index_file_entries = &load_result->entries; 353 SimpleIndex::EntrySet* index_file_entries = &load_result->entries;
354 // First, remove the entries that are in the |removed_entries_| from both 354 // First, remove the entries that are in the |removed_entries_| from both
355 // sets. 355 // sets.
356 for (base::hash_set<uint64>::const_iterator it = 356 for (base::hash_set<uint64>::const_iterator it =
357 removed_entries_.begin(); it != removed_entries_.end(); ++it) { 357 removed_entries_.begin(); it != removed_entries_.end(); ++it) {
358 entries_set_.erase(*it); 358 entries_set_.erase(*it);
359 index_file_entries->erase(*it); 359 index_file_entries->erase(*it);
360 } 360 }
361 361
362 // Recalculate the cache size while merging the two sets. 362 for (EntrySet::const_iterator it = entries_set_.begin();
363 for (EntrySet::const_iterator it = index_file_entries->begin(); 363 it != entries_set_.end(); ++it) {
364 const uint64 entry_hash = it->first;
365 std::pair<EntrySet::iterator, bool> insert_result =
366 index_file_entries->insert(EntrySet::value_type(entry_hash,
367 EntryMetadata()));
368 EntrySet::iterator& possibly_inserted_entry = insert_result.first;
369 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
370 }
371
372 uint64 merged_cache_size = 0;
373 for (EntrySet::iterator it = index_file_entries->begin();
364 it != index_file_entries->end(); ++it) { 374 it != index_file_entries->end(); ++it) {
365 // If there is already an entry in the current entries_set_, we need to 375 merged_cache_size += it->second.GetEntrySize();
366 // merge the new data there with the data loaded in the initialization.
367 EntrySet::iterator current_entry = entries_set_.find(it->first);
368 // When Merging, existing data in the |current_entry| will prevail.
369 if (current_entry == entries_set_.end()) {
370 InsertInEntrySet(it->first, it->second, &entries_set_);
371 cache_size_ += it->second.GetEntrySize();
372 }
373 } 376 }
377
378 entries_set_.swap(*index_file_entries);
379 cache_size_ = merged_cache_size;
374 initialized_ = true; 380 initialized_ = true;
375 removed_entries_.clear(); 381 removed_entries_.clear();
376 382
377 // The actual IO is asynchronous, so calling WriteToDisk() shouldn't slow the 383 // The actual IO is asynchronous, so calling WriteToDisk() shouldn't slow the
378 // merge down much. 384 // merge down much.
379 if (load_result->flush_required) 385 if (load_result->flush_required)
380 WriteToDisk(); 386 WriteToDisk();
381 387
382 UMA_HISTOGRAM_CUSTOM_COUNTS("SimpleCache.IndexInitializationWaiters", 388 UMA_HISTOGRAM_CUSTOM_COUNTS("SimpleCache.IndexInitializationWaiters",
383 to_run_when_initialized_.size(), 0, 100, 20); 389 to_run_when_initialized_.size(), 0, 100, 20);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 entries_set_.erase(it++); 452 entries_set_.erase(it++);
447 continue; 453 continue;
448 } 454 }
449 } 455 }
450 ++it; 456 ++it;
451 } 457 }
452 return ret_hashes.Pass(); 458 return ret_hashes.Pass();
453 } 459 }
454 460
455 } // namespace disk_cache 461 } // namespace disk_cache
OLDNEW
« 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