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

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

Issue 2922973003: RFC: use some in-memory state in SimpleCache to quickly cache-miss some CantConditionalize cases
Patch Set: omewhat better take at higher-level HC::T impl, a bit lessy hacky, and actually write to cache now. Created 3 years, 6 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.cc
diff --git a/net/disk_cache/simple/simple_index.cc b/net/disk_cache/simple/simple_index.cc
index c41c829bdefd808db4ea55dded03e54f4574b641..e65e251fa739e393a6cb43e342c51f48496839f6 100644
--- a/net/disk_cache/simple/simple_index.cc
+++ b/net/disk_cache/simple/simple_index.cc
@@ -60,7 +60,8 @@ EntryMetadata::EntryMetadata()
EntryMetadata::EntryMetadata(base::Time last_used_time,
base::StrictNumeric<uint32_t> entry_size)
- : last_used_time_seconds_since_epoch_(0), entry_size_(entry_size) {
+ : last_used_time_seconds_since_epoch_(0), entry_size_(0) {
+ SetEntrySize(entry_size); // to round/pack properly.
SetLastUsedTime(last_used_time);
}
@@ -88,11 +89,12 @@ void EntryMetadata::SetLastUsedTime(const base::Time& last_used_time) {
}
uint32_t EntryMetadata::GetEntrySize() const {
- return entry_size_;
+ return entry_size_ << 8;
}
void EntryMetadata::SetEntrySize(base::StrictNumeric<uint32_t> entry_size) {
- entry_size_ = entry_size;
+ // ### what happens if we overflow here?
+ entry_size_ = (static_cast<uint32_t>(entry_size) + 255) >> 8;
}
void EntryMetadata::Serialize(base::Pickle* pickle) const {
@@ -100,11 +102,13 @@ void EntryMetadata::Serialize(base::Pickle* pickle) const {
int64_t internal_last_used_time = GetLastUsedTime().ToInternalValue();
// If you modify the size of the size of the pickle, be sure to update
// kOnDiskSizeBytes.
+ uint32_t packed_entry_info = (entry_size_ << 8) | memory_entry_data_;
pickle->WriteInt64(internal_last_used_time);
- pickle->WriteUInt64(entry_size_);
+ pickle->WriteUInt64(packed_entry_info);
}
-bool EntryMetadata::Deserialize(base::PickleIterator* it) {
+bool EntryMetadata::Deserialize(base::PickleIterator* it,
+ bool has_memory_entry_data) {
DCHECK(it);
int64_t tmp_last_used_time;
uint64_t tmp_entry_size;
@@ -112,7 +116,14 @@ bool EntryMetadata::Deserialize(base::PickleIterator* it) {
tmp_entry_size > std::numeric_limits<decltype(entry_size_)>::max())
return false;
SetLastUsedTime(base::Time::FromInternalValue(tmp_last_used_time));
- entry_size_ = static_cast<uint32_t>(tmp_entry_size);
+ if (has_memory_entry_data) {
+ // tmp_entry_size actually packs entry_size_ and memory_entry_data_.
+ SetEntrySize(static_cast<uint32_t>(tmp_entry_size & 0xFFFFFF00));
+ SetMemoryEntryData(static_cast<uint8_t>(tmp_entry_size & 0xFF));
+ } else {
+ SetEntrySize(static_cast<uint32_t>(tmp_entry_size));
+ SetMemoryEntryData(0);
+ }
return true;
}
@@ -281,6 +292,22 @@ bool SimpleIndex::Has(uint64_t hash) const {
return !initialized_ || entries_set_.count(hash) > 0;
}
+uint8_t SimpleIndex::GetMemoryEntryData(uint64_t entry_hash) const {
+ DCHECK(io_thread_checker_.CalledOnValidThread());
+ EntrySet::const_iterator it = entries_set_.find(entry_hash);
+ if (it == entries_set_.end())
+ return 0;
+ return it->second.GetMemoryEntryData();
+}
+
+void SimpleIndex::SetMemoryEntryData(uint64_t entry_hash, uint8_t value) {
+ DCHECK(io_thread_checker_.CalledOnValidThread());
+ EntrySet::iterator it = entries_set_.find(entry_hash);
+ if (it == entries_set_.end())
+ return;
+ return it->second.SetMemoryEntryData(value);
+}
+
bool SimpleIndex::UseIfExists(uint64_t entry_hash) {
DCHECK(io_thread_checker_.CalledOnValidThread());
// Always update the last used time, even if it is during initialization.
@@ -410,8 +437,9 @@ void SimpleIndex::UpdateEntryIteratorSize(
DCHECK(io_thread_checker_.CalledOnValidThread());
DCHECK_GE(cache_size_, (*it)->second.GetEntrySize());
cache_size_ -= (*it)->second.GetEntrySize();
- cache_size_ += static_cast<uint32_t>(entry_size);
(*it)->second.SetEntrySize(entry_size);
+ // We use GetEntrySize to get consistent rounding.
+ cache_size_ += (*it)->second.GetEntrySize();
}
void SimpleIndex::MergeInitializingSet(

Powered by Google App Engine
This is Rietveld 408576698