Chromium Code Reviews| 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(size_t max_size) : max_size_(max_size) {} | |
| 13 | |
| 14 RankedList::~RankedList() {} | |
| 15 | |
| 16 RankedList::RankedList(RankedList&& other) | |
| 17 : max_size_(other.max_size_) { | |
| 18 entries_.swap(other.entries_); | |
|
dcheng
2015/12/08 02:04:51
entries_(std::move(other.entries_)) to keep the tw
Simon Que
2015/12/08 02:24:16
Done.
| |
| 19 } | |
| 20 | |
| 21 RankedList& RankedList::operator=(RankedList&& other) { | |
| 22 max_size_ = other.max_size_; | |
| 23 entries_ = std::move(other.entries_); | |
| 24 return *this; | |
| 25 } | |
| 26 | |
| 27 void RankedList::Add(const ValueType& value, int count) { | |
| 28 // Determine where to insert the value given its count. | |
| 29 EntryList::iterator iter = std::upper_bound(entries_.begin(), entries_.end(), | |
| 30 Entry{ValueType(), count}); | |
|
dcheng
2015/12/08 02:04:51
Note that uniform initialization syntax isn't yet
Simon Que
2015/12/08 02:24:16
Done.
| |
| 31 | |
| 32 // If the list is full, do not add any entry with |count| if does not exceed | |
| 33 // the lowest count of the entries in the list. | |
| 34 if (size() == max_size_ && iter == end()) | |
| 35 return; | |
| 36 | |
| 37 entries_.insert(iter, Entry({value, count})); | |
|
dcheng
2015/12/08 02:04:51
Ditto.
Simon Que
2015/12/08 02:24:16
Done.
| |
| 38 | |
| 39 // Limit the list size if it exceeds the maximum allowed size. | |
| 40 if (entries_.size() > max_size_) | |
| 41 entries_.resize(max_size_); | |
| 42 } | |
| 43 | |
| 44 } // namespace leak_detector | |
| 45 } // namespace metrics | |
| OLD | NEW |