Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: components/metrics/leak_detector/ranked_list.cc

Issue 986503002: components/metrics: Add runtime memory leak detector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac build fixes: const arg in comparator, rm const in func return type Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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::RValue other)
17 : max_size_(other.object->max_size_) {
18 entries_.swap(other.object->entries_);
19 }
20
21 RankedList& RankedList::operator=(RankedList::RValue other) {
22 max_size_ = other.object->max_size_;
23 entries_.swap(other.object->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});
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}));
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
OLDNEW
« no previous file with comments | « components/metrics/leak_detector/ranked_list.h ('k') | components/metrics/leak_detector/ranked_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698