Index: base/metrics/sample_map.cc |
diff --git a/base/metrics/sample_map.cc b/base/metrics/sample_map.cc |
index 42468cb57f31816fa6a5fbd0c2c5e734a86c6773..f2540a4d00bf08ee5b6548692e80ce9bbb155462 100644 |
--- a/base/metrics/sample_map.cc |
+++ b/base/metrics/sample_map.cc |
@@ -6,8 +6,6 @@ |
#include "base/logging.h" |
-using std::map; |
- |
namespace base { |
typedef HistogramBase::Count Count; |
@@ -24,7 +22,7 @@ void SampleMap::Accumulate(Sample value, Count count) { |
} |
Count SampleMap::GetCount(Sample value) const { |
- map<Sample, Count>::const_iterator it = sample_counts_.find(value); |
+ std::map<Sample, Count>::const_iterator it = sample_counts_.find(value); |
if (it == sample_counts_.end()) |
return 0; |
return it->second; |
@@ -32,10 +30,8 @@ Count SampleMap::GetCount(Sample value) const { |
Count SampleMap::TotalCount() const { |
Count count = 0; |
- for (map<Sample, Count>::const_iterator it = sample_counts_.begin(); |
- it != sample_counts_.end(); |
- ++it) { |
- count += it->second; |
+ for (const auto& entry : sample_counts_) { |
+ count += entry.second; |
} |
return count; |
} |
@@ -53,14 +49,17 @@ bool SampleMap::AddSubtractImpl(SampleCountIterator* iter, |
iter->Get(&min, &max, &count); |
if (min + 1 != max) |
return false; // SparseHistogram only supports bucket with size 1. |
- sample_counts_[min] += (op == HistogramSamples::ADD) ? count : -count; |
+ |
+ sample_counts_[min] += (op == HistogramSamples::ADD) ? count : -count; |
} |
return true; |
} |
SampleMapIterator::SampleMapIterator(const SampleToCountMap& sample_counts) |
: iter_(sample_counts.begin()), |
- end_(sample_counts.end()) {} |
+ end_(sample_counts.end()) { |
+ SkipEmptyBuckets(); |
+} |
SampleMapIterator::~SampleMapIterator() {} |
@@ -70,7 +69,8 @@ bool SampleMapIterator::Done() const { |
void SampleMapIterator::Next() { |
DCHECK(!Done()); |
- iter_++; |
+ ++iter_; |
+ SkipEmptyBuckets(); |
} |
void SampleMapIterator::Get(Sample* min, Sample* max, Count* count) const { |
@@ -83,4 +83,10 @@ void SampleMapIterator::Get(Sample* min, Sample* max, Count* count) const { |
*count = iter_->second; |
} |
+void SampleMapIterator::SkipEmptyBuckets() { |
+ while (!Done() && iter_->second == 0) { |
+ ++iter_; |
+ } |
+} |
+ |
} // namespace base |