| OLD | NEW |
| 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 Loading... |
| 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 // The entries are stored sorted by |count|, but this function looks for an |
| 53 // entry with a particular |value| field. Thus, std::set::find() will not |
| 54 // work. Nor would std::find(), which matches by both |count| and |value| -- |
| 55 // the count is unknown to the caller of this function. |
| 56 // |
| 57 // The most straightforward way is to iterate through the set until a matching |
| 58 // value is found. |
| 59 for (const_iterator iter = begin(); iter != end(); ++iter) { |
| 60 if (iter->value == value) |
| 61 return iter; |
| 62 } |
| 63 return end(); |
| 64 } |
| 65 |
| 51 } // namespace leak_detector | 66 } // namespace leak_detector |
| 52 } // namespace metrics | 67 } // namespace metrics |
| OLD | NEW |