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

Side by Side 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: Add unit test coverage 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/metrics/leak_detector/ranked_set.h" 5 #include "components/metrics/leak_detector/ranked_set.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 namespace metrics { 9 namespace metrics {
10 namespace leak_detector { 10 namespace leak_detector {
(...skipping 30 matching lines...) Expand all
41 new_entry.count = count; 41 new_entry.count = count;
42 entries_.insert(new_entry); 42 entries_.insert(new_entry);
43 43
44 // Limit the container size if it exceeds the maximum allowed size, by 44 // Limit the container size if it exceeds the maximum allowed size, by
45 // deleting the last element. This should only iterate once because the size 45 // deleting the last element. This should only iterate once because the size
46 // can only have increased by 1, but use a while loop just to be safe. 46 // can only have increased by 1, but use a while loop just to be safe.
47 while (entries_.size() > max_size_) 47 while (entries_.size() > max_size_)
48 entries_.erase(--entries_.end()); 48 entries_.erase(--entries_.end());
49 } 49 }
50 50
51 RankedSet::const_iterator RankedSet::Find(const ValueType& value) const {
52 // Due to the unusual way the entries are stored, it is best to manually
53 // iterate through them until an entry with a matching value is found.
54 // e.g. std::find() would not work because it depends on exact matching by the
55 // whole Entry struct.
Will Harris 2016/04/09 20:10:23 can't you just implement the operators in Entry ra
Simon Que 2016/04/09 21:04:11 The operator would have to look something like:
Will Harris 2016/04/11 17:26:37 I think as long as it's commented (perhaps explain
Simon Que 2016/04/11 18:41:08 Done.
56 for (const_iterator iter = begin(); iter != end(); ++iter) {
57 if (iter->value == value)
58 return iter;
59 }
60 return end();
61 }
62
51 } // namespace leak_detector 63 } // namespace leak_detector
52 } // namespace metrics 64 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698