OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/metrics/leak_detector/ranked_list.h" |
| 6 |
| 7 #include <algorithm> |
| 8 #include <utility> |
| 9 |
| 10 namespace metrics { |
| 11 namespace leak_detector { |
| 12 |
| 13 RankedList& RankedList::operator= (RankedList&& other) { |
| 14 max_size_ = other.max_size_; |
| 15 entries_ = std::move(other.entries_); |
| 16 return *this; |
| 17 } |
| 18 |
| 19 void RankedList::Add(const ValueType& value, int count) { |
| 20 // Determine where to insert the value given its count. |
| 21 EntryList::iterator iter = |
| 22 std::upper_bound(entries_.begin(), entries_.end(), |
| 23 Entry{ValueType(), count}); |
| 24 |
| 25 // If the list is full, do not add any entry with |count| if does not exceed |
| 26 // the lowest count of the entries in the list. |
| 27 if (size() == max_size_ && iter == end()) |
| 28 return; |
| 29 |
| 30 entries_.insert(iter, Entry({value, count})); |
| 31 |
| 32 // Limit the list size if it exceeds the maximum allowed size. |
| 33 if (entries_.size() > max_size_) |
| 34 entries_.resize(max_size_); |
| 35 } |
| 36 |
| 37 } // namespace leak_detector |
| 38 } // namespace metrics |
OLD | NEW |