Chromium Code Reviews| Index: components/metrics/leak_detector/ranked_list.cc |
| diff --git a/components/metrics/leak_detector/ranked_list.cc b/components/metrics/leak_detector/ranked_list.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..88fcb18acafd6a24534e1cf6d75cb3928ab46a3c |
| --- /dev/null |
| +++ b/components/metrics/leak_detector/ranked_list.cc |
| @@ -0,0 +1,45 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/metrics/leak_detector/ranked_list.h" |
| + |
| +#include <algorithm> |
| + |
| +namespace metrics { |
| +namespace leak_detector { |
| + |
| +RankedList::RankedList(size_t max_size) : max_size_(max_size) {} |
| + |
| +RankedList::~RankedList() {} |
| + |
| +RankedList::RankedList(RankedList&& other) |
| + : max_size_(other.max_size_) { |
| + 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.
|
| +} |
| + |
| +RankedList& RankedList::operator=(RankedList&& other) { |
| + max_size_ = other.max_size_; |
| + entries_ = std::move(other.entries_); |
| + return *this; |
| +} |
| + |
| +void RankedList::Add(const ValueType& value, int count) { |
| + // Determine where to insert the value given its count. |
| + EntryList::iterator iter = std::upper_bound(entries_.begin(), entries_.end(), |
| + 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.
|
| + |
| + // If the list is full, do not add any entry with |count| if does not exceed |
| + // the lowest count of the entries in the list. |
| + if (size() == max_size_ && iter == end()) |
| + return; |
| + |
| + entries_.insert(iter, Entry({value, count})); |
|
dcheng
2015/12/08 02:04:51
Ditto.
Simon Que
2015/12/08 02:24:16
Done.
|
| + |
| + // Limit the list size if it exceeds the maximum allowed size. |
| + if (entries_.size() > max_size_) |
| + entries_.resize(max_size_); |
| +} |
| + |
| +} // namespace leak_detector |
| +} // namespace metrics |