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

Unified Diff: components/metrics/leak_detector/ranked_set.cc

Issue 1870233003: Record call site history in LeakDetectorImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clarify comments in RankedSet Created 4 years, 8 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: components/metrics/leak_detector/ranked_set.cc
diff --git a/components/metrics/leak_detector/ranked_set.cc b/components/metrics/leak_detector/ranked_set.cc
index 5725fb5c01c83cb6f2a0c456096402375c032355..f8945d7014030ee250d1280eeeafa0e96154ed86 100644
--- a/components/metrics/leak_detector/ranked_set.cc
+++ b/components/metrics/leak_detector/ranked_set.cc
@@ -48,5 +48,20 @@ void RankedSet::Add(const ValueType& value, int count) {
entries_.erase(--entries_.end());
}
+RankedSet::const_iterator RankedSet::Find(const ValueType& value) const {
+ // The entries are stored sorted by |count|, but this function looks for an
+ // entry with a particular |value| field. Thus, std::set::find() will not
+ // work. Nor would std::find(), which matches by both |count| and |value| --
+ // the count is unknown to the caller of this function.
+ //
+ // The most straightforward way is to iterate through the set until a matching
+ // value is found.
+ for (const_iterator iter = begin(); iter != end(); ++iter) {
+ if (iter->value == value)
+ return iter;
+ }
+ return end();
+}
+
} // namespace leak_detector
} // namespace metrics
« no previous file with comments | « components/metrics/leak_detector/ranked_set.h ('k') | components/metrics/leak_detector/ranked_set_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698