summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/simple/simple_index.cc
diff options
context:
space:
mode:
authorpliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-08 08:52:08 +0000
committerpliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-08 08:52:08 +0000
commit26a3ecc9bb9639a9dd7fdfed63a71a63255a9cea (patch)
treeb9cbf0dd9f47300cf8bf0e5ac80d97eb61c71ba0 /net/disk_cache/simple/simple_index.cc
parentf7eb888b58b3e9a664be32b64d9c06ac0c682e84 (diff)
downloadchromium_src-26a3ecc9bb9639a9dd7fdfed63a71a63255a9cea.zip
chromium_src-26a3ecc9bb9639a9dd7fdfed63a71a63255a9cea.tar.gz
chromium_src-26a3ecc9bb9639a9dd7fdfed63a71a63255a9cea.tar.bz2
Make simple cache index take hashes in rather than key strings.
The index was re-hashing keys that were already hashed. This CL also adds an ImmutableArray helper class for testing. BUG=257616 R=gavinp@chromium.org, pasko@chromium.org Review URL: https://codereview.chromium.org/21037003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216372 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/simple/simple_index.cc')
-rw-r--r--net/disk_cache/simple/simple_index.cc26
1 files changed, 12 insertions, 14 deletions
diff --git a/net/disk_cache/simple/simple_index.cc b/net/disk_cache/simple/simple_index.cc
index caec19f60..f5c1270 100644
--- a/net/disk_cache/simple/simple_index.cc
+++ b/net/disk_cache/simple/simple_index.cc
@@ -199,30 +199,28 @@ int32 SimpleIndex::GetEntryCount() const {
return entries_set_.size();
}
-void SimpleIndex::Insert(const std::string& key) {
+void SimpleIndex::Insert(uint64 entry_hash) {
DCHECK(io_thread_checker_.CalledOnValidThread());
// Upon insert we don't know yet the size of the entry.
// It will be updated later when the SimpleEntryImpl finishes opening or
// creating the new entry, and then UpdateEntrySize will be called.
- const uint64 hash_key = simple_util::GetEntryHashKey(key);
InsertInEntrySet(
- hash_key, EntryMetadata(base::Time::Now(), 0), &entries_set_);
+ entry_hash, EntryMetadata(base::Time::Now(), 0), &entries_set_);
if (!initialized_)
- removed_entries_.erase(hash_key);
+ removed_entries_.erase(entry_hash);
PostponeWritingToDisk();
}
-void SimpleIndex::Remove(const std::string& key) {
+void SimpleIndex::Remove(uint64 entry_hash) {
DCHECK(io_thread_checker_.CalledOnValidThread());
- const uint64 hash_key = simple_util::GetEntryHashKey(key);
- EntrySet::iterator it = entries_set_.find(hash_key);
+ EntrySet::iterator it = entries_set_.find(entry_hash);
if (it != entries_set_.end()) {
UpdateEntryIteratorSize(&it, 0);
entries_set_.erase(it);
}
if (!initialized_)
- removed_entries_.insert(hash_key);
+ removed_entries_.insert(entry_hash);
PostponeWritingToDisk();
}
@@ -232,11 +230,11 @@ bool SimpleIndex::Has(uint64 hash) const {
return !initialized_ || entries_set_.count(hash) > 0;
}
-bool SimpleIndex::UseIfExists(const std::string& key) {
+bool SimpleIndex::UseIfExists(uint64 entry_hash) {
DCHECK(io_thread_checker_.CalledOnValidThread());
// Always update the last used time, even if it is during initialization.
// It will be merged later.
- EntrySet::iterator it = entries_set_.find(simple_util::GetEntryHashKey(key));
+ EntrySet::iterator it = entries_set_.find(entry_hash);
if (it == entries_set_.end())
// If not initialized, always return true, forcing it to go to the disk.
return !initialized_;
@@ -292,9 +290,9 @@ void SimpleIndex::StartEvictionIfNeeded() {
base::Bind(&SimpleIndex::EvictionDone, AsWeakPtr()));
}
-bool SimpleIndex::UpdateEntrySize(const std::string& key, uint64 entry_size) {
+bool SimpleIndex::UpdateEntrySize(uint64 entry_hash, uint64 entry_size) {
DCHECK(io_thread_checker_.CalledOnValidThread());
- EntrySet::iterator it = entries_set_.find(simple_util::GetEntryHashKey(key));
+ EntrySet::iterator it = entries_set_.find(entry_hash);
if (it == entries_set_.end())
return false;
@@ -318,11 +316,11 @@ void SimpleIndex::EvictionDone(int result) {
// static
void SimpleIndex::InsertInEntrySet(
- uint64 hash_key,
+ uint64 entry_hash,
const disk_cache::EntryMetadata& entry_metadata,
EntrySet* entry_set) {
DCHECK(entry_set);
- entry_set->insert(std::make_pair(hash_key, entry_metadata));
+ entry_set->insert(std::make_pair(entry_hash, entry_metadata));
}
void SimpleIndex::PostponeWritingToDisk() {