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