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

Unified Diff: base/metrics/persistent_sample_map.cc

Issue 1803253002: Improved iterator for persistent memory allocator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor-hp
Patch Set: rebased and fixed up a bit Created 4 years, 9 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: base/metrics/persistent_sample_map.cc
diff --git a/base/metrics/persistent_sample_map.cc b/base/metrics/persistent_sample_map.cc
index 014a86528e7b8e8b5c6eabbe5e0069b60e53cf92..050ad2ec5eb4dacdf49fd0dd4e6f39c61bbcb8e0 100644
--- a/base/metrics/persistent_sample_map.cc
+++ b/base/metrics/persistent_sample_map.cc
@@ -95,11 +95,8 @@ PersistentSampleMap::PersistentSampleMap(
PersistentMemoryAllocator* allocator,
Metadata* meta)
: HistogramSamples(id, meta),
- allocator_(allocator) {
- // This is created once but will continue to return new iterables even when
- // it has previously reached the end.
- allocator->CreateIterator(&sample_iter_);
-
+ allocator_(allocator),
+ sample_iter_(allocator) {
// Load all existing samples during construction. It's no worse to do it
// here than at some point in the future and could be better if construction
// takes place on some background thread. New samples could be created at
@@ -230,35 +227,32 @@ Count* PersistentSampleMap::ImportSamples(Sample until_value) {
//
// This will be addressed in a future CL.
- uint32_t type_id;
PersistentMemoryAllocator::Reference ref;
- while ((ref = allocator_->GetNextIterable(&sample_iter_, &type_id)) != 0) {
- if (type_id == kTypeIdSampleRecord) {
- SampleRecord* record =
- allocator_->GetAsObject<SampleRecord>(ref, kTypeIdSampleRecord);
- if (!record)
- continue;
-
- // A sample record has been found but may not be for this histogram.
- if (record->id != id())
- continue;
-
- // Check if the record's value is already known.
- if (!ContainsKey(sample_counts_, record->value)) {
- // No: Add it to map of known values if the value is valid.
- if (record->value >= 0)
- sample_counts_[record->value] = &record->count;
- } else {
- // Yes: Ignore it; it's a duplicate caused by a race condition -- see
- // code & comment in GetOrCreateSampleCountStorage() for details.
- // Check that nothing ever operated on the duplicate record.
- DCHECK_EQ(0, record->count);
- }
-
- // Stop if it's the value being searched for.
- if (record->value == until_value)
- return &record->count;
+ while ((ref = sample_iter_.GetNextOfType(kTypeIdSampleRecord)) != 0) {
+ SampleRecord* record =
+ allocator_->GetAsObject<SampleRecord>(ref, kTypeIdSampleRecord);
+ if (!record)
+ continue;
+
+ // A sample record has been found but may not be for this histogram.
+ if (record->id != id())
+ continue;
+
+ // Check if the record's value is already known.
+ if (!ContainsKey(sample_counts_, record->value)) {
+ // No: Add it to map of known values if the value is valid.
+ if (record->value >= 0)
+ sample_counts_[record->value] = &record->count;
+ } else {
+ // Yes: Ignore it; it's a duplicate caused by a race condition -- see
+ // code & comment in GetOrCreateSampleCountStorage() for details.
+ // Check that nothing ever operated on the duplicate record.
+ DCHECK_EQ(0, record->count);
}
+
+ // Stop if it's the value being searched for.
+ if (record->value == until_value)
+ return &record->count;
}
return nullptr;

Powered by Google App Engine
This is Rietveld 408576698