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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
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..f02c16e395efd156e240787c2e88e0a78d0fa74f
--- /dev/null
+++ b/components/metrics/leak_detector/ranked_list.cc
@@ -0,0 +1,36 @@
+// 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>
+#include <utility>
+
+namespace leak_detector {
+
+RankedList& RankedList::operator= (RankedList&& other) {
Simon Que 2015/08/23 23:30:53 Implemented std::move support.
+ 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});
+
+ // 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}));
+
+ // Limit the list size if it exceeds the maximum allowed size.
+ if (entries_.size() > max_size_)
+ entries_.resize(max_size_);
+}
+
+} // namespace leak_detector

Powered by Google App Engine
This is Rietveld 408576698