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

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: LeakDetectorImpl stores addrs as uintptr_t; Implement move semantics for RankedList Created 5 years, 3 months 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 #include <utility>
9
10 namespace leak_detector {
11
12 RankedList& RankedList::operator= (RankedList&& other) {
Simon Que 2015/08/23 23:30:53 Implemented std::move support.
13 max_size_ = other.max_size_;
14 entries_ = std::move(other.entries_);
15 return *this;
16 }
17
18 void RankedList::Add(const ValueType& value, int count) {
19 // Determine where to insert the value given its count.
20 EntryList::iterator iter =
21 std::upper_bound(entries_.begin(), entries_.end(),
22 Entry{ValueType(), count});
23
24 // If the list is full, do not add any entry with |count| if does not exceed
25 // the lowest count of the entries in the list.
26 if (size() == max_size_ && iter == end())
27 return;
28
29 entries_.insert(iter, Entry({value, count}));
30
31 // Limit the list size if it exceeds the maximum allowed size.
32 if (entries_.size() > max_size_)
33 entries_.resize(max_size_);
34 }
35
36 } // namespace leak_detector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698