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

Side by Side Diff: net/disk_cache/simple/simple_index_file.cc

Issue 14746019: net/disk_cache/simple: Reduce size of EntrySet nodes. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix two failing unit tests Created 7 years, 7 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
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_file.h" 5 #include "net/disk_cache/simple/simple_index_file.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/hash.h" 8 #include "base/hash.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 104 }
105 105
106 if (!index_metadata.CheckIndexMetadata()) { 106 if (!index_metadata.CheckIndexMetadata()) {
107 LOG(ERROR) << "Invalid index_metadata on Simple Cache Index."; 107 LOG(ERROR) << "Invalid index_metadata on Simple Cache Index.";
108 return scoped_ptr<SimpleIndex::EntrySet>(NULL); 108 return scoped_ptr<SimpleIndex::EntrySet>(NULL);
109 } 109 }
110 110
111 scoped_ptr<SimpleIndex::EntrySet> index_file_entries( 111 scoped_ptr<SimpleIndex::EntrySet> index_file_entries(
112 new SimpleIndex::EntrySet()); 112 new SimpleIndex::EntrySet());
113 while (index_file_entries->size() < index_metadata.GetNumberOfEntries()) { 113 while (index_file_entries->size() < index_metadata.GetNumberOfEntries()) {
114 uint64 hash_key;
114 EntryMetadata entry_metadata; 115 EntryMetadata entry_metadata;
115 if (!entry_metadata.Deserialize(&pickle_it)) { 116 if (!pickle_it.ReadUInt64(&hash_key) ||
117 !entry_metadata.Deserialize(&pickle_it)) {
116 LOG(WARNING) << "Invalid EntryMetadata in Simple Index file."; 118 LOG(WARNING) << "Invalid EntryMetadata in Simple Index file.";
117 return scoped_ptr<SimpleIndex::EntrySet>(NULL); 119 return scoped_ptr<SimpleIndex::EntrySet>(NULL);
118 } 120 }
119 SimpleIndex::InsertInEntrySet(entry_metadata, index_file_entries.get()); 121 SimpleIndex::InsertInEntrySet(
122 hash_key, entry_metadata, index_file_entries.get());
120 } 123 }
121 124
122 return index_file_entries.Pass(); 125 return index_file_entries.Pass();
123 } 126 }
124 127
125 // static 128 // static
126 scoped_ptr<Pickle> SimpleIndexFile::Serialize( 129 scoped_ptr<Pickle> SimpleIndexFile::Serialize(
127 const SimpleIndexFile::IndexMetadata& index_metadata, 130 const SimpleIndexFile::IndexMetadata& index_metadata,
128 const SimpleIndex::EntrySet& entries) { 131 const SimpleIndex::EntrySet& entries) {
129 scoped_ptr<Pickle> pickle(new Pickle(sizeof(SimpleIndexFile::PickleHeader))); 132 scoped_ptr<Pickle> pickle(new Pickle(sizeof(SimpleIndexFile::PickleHeader)));
130 133
131 index_metadata.Serialize(pickle.get()); 134 index_metadata.Serialize(pickle.get());
132 for (SimpleIndex::EntrySet::const_iterator it = entries.begin(); 135 for (SimpleIndex::EntrySet::const_iterator it = entries.begin();
133 it != entries.end(); ++it) { 136 it != entries.end(); ++it) {
137 pickle->WriteUInt64(it->first);
134 it->second.Serialize(pickle.get()); 138 it->second.Serialize(pickle.get());
135 } 139 }
136 SimpleIndexFile::PickleHeader* header_p = 140 SimpleIndexFile::PickleHeader* header_p =
137 pickle->headerT<SimpleIndexFile::PickleHeader>(); 141 pickle->headerT<SimpleIndexFile::PickleHeader>();
138 header_p->crc = CalculatePickleCRC(*pickle); 142 header_p->crc = CalculatePickleCRC(*pickle);
139 return pickle.Pass(); 143 return pickle.Pass();
140 } 144 }
141 145
142 // static 146 // static
143 void SimpleIndexFile::WriteToDisk(const base::FilePath& index_filename, 147 void SimpleIndexFile::WriteToDisk(const base::FilePath& index_filename,
(...skipping 11 matching lines...) Expand all
155 << temp_filename.value(); 159 << temp_filename.value();
156 file_util::Delete(temp_filename, /* recursive = */ false); 160 file_util::Delete(temp_filename, /* recursive = */ false);
157 return; 161 return;
158 } 162 }
159 // Swap temp and index_file. 163 // Swap temp and index_file.
160 bool result = file_util::ReplaceFile(temp_filename, index_filename); 164 bool result = file_util::ReplaceFile(temp_filename, index_filename);
161 DCHECK(result); 165 DCHECK(result);
162 } 166 }
163 167
164 } // namespace disk_cache 168 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698