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

Unified Diff: net/disk_cache/simple/simple_index_file.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
Index: net/disk_cache/simple/simple_index_file.cc
diff --git a/net/disk_cache/simple/simple_index_file.cc b/net/disk_cache/simple/simple_index_file.cc
index 596b816cbbf9b058f13b93693258d7b746549ec3..7bcea7cdfa86255360a7416d4eff5731ca24ae7c 100644
--- a/net/disk_cache/simple/simple_index_file.cc
+++ b/net/disk_cache/simple/simple_index_file.cc
@@ -8,6 +8,7 @@
#include "base/file_util.h"
#include "base/files/file_enumerator.h"
+#include "base/files/memory_mapped_file.h"
#include "base/hash.h"
#include "base/logging.h"
#include "base/metrics/histogram.h"
@@ -254,14 +255,16 @@ void SimpleIndexFile::SyncLoadFromDisk(const base::FilePath& index_filename,
SimpleIndexLoadResult* out_result) {
out_result->Reset();
- std::string contents;
- if (!file_util::ReadFileToString(index_filename, &contents)) {
- LOG(WARNING) << "Could not read Simple Index file.";
+ base::MemoryMappedFile index_file_map;
+ if (!index_file_map.Initialize(index_filename)) {
+ LOG(WARNING) << "Could not map Simple Index file.";
base::DeleteFile(index_filename, false);
return;
}
- SimpleIndexFile::Deserialize(contents.data(), contents.size(), out_result);
+ SimpleIndexFile::Deserialize(
+ reinterpret_cast<const char*>(index_file_map.data()),
+ index_file_map.length(), out_result);
if (!out_result->did_load)
base::DeleteFile(index_filename, false);
@@ -322,6 +325,10 @@ void SimpleIndexFile::Deserialize(const char* data, int data_len,
return;
}
+#if !defined(OS_WIN)
+ // TODO(gavinp): Consider using std::unordered_map.
+ entries->resize(index_metadata.GetNumberOfEntries() + kExtraSizeForMerge);
+#endif
while (entries->size() < index_metadata.GetNumberOfEntries()) {
uint64 hash_key;
EntryMetadata entry_metadata;

Powered by Google App Engine
This is Rietveld 408576698