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

Unified Diff: components/metrics/leak_detector/leak_detector_value_type.cc

Issue 986503002: components/metrics: Add runtime memory leak detector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix style, comments, RAW_CHECK in stl_allocator.h 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/leak_detector_value_type.cc
diff --git a/components/metrics/leak_detector/leak_detector_value_type.cc b/components/metrics/leak_detector/leak_detector_value_type.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fbf29d1905f269f220ebe9ea9ff2314ba1a93435
--- /dev/null
+++ b/components/metrics/leak_detector/leak_detector_value_type.cc
@@ -0,0 +1,69 @@
+// 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/leak_detector_value_type.h"
+
+#include <stdio.h>
+
+namespace leak_detector {
+
+const char* LeakDetectorValueType::GetTypeName() const {
+ switch (type_) {
+ case kSize:
+ return "size";
+ case kCallStack:
+ return "call stack";
+ default:
+ return "(none)";
+ }
+}
+
+const char* LeakDetectorValueType::ToString(char* buffer,
jar (doing other things) 2015/08/21 02:48:43 Please put the mutable target last.
Simon Que 2015/08/21 21:59:20 Done.
+ size_t buffer_size) const {
+ switch (type_) {
+ case kSize:
+ snprintf(buffer, buffer_size, "%u", size_);
+ break;
+ case kCallStack:
+ snprintf(buffer, buffer_size, "%p", call_stack_);
+ break;
+ default:
+ snprintf(buffer, buffer_size, "(none)");
+ break;
+ }
+
+ return buffer;
+}
+
+bool LeakDetectorValueType::operator== (
+ const LeakDetectorValueType& other) const {
+ if (type_ != other.type_)
+ return false;
+
+ switch(type_) {
+ case kSize:
+ return size_ == other.size_;
+ case kCallStack:
+ return call_stack_ == other.call_stack_;
+ default:
+ return false;
+ }
+}
+
+bool LeakDetectorValueType::operator< (
+ const LeakDetectorValueType& other) const {
+ if (type_ < other.type_)
+ return true;
+
+ switch(type_) {
+ case kSize:
+ return size_ < other.size_;
+ case kCallStack:
+ return call_stack_ < other.call_stack_;
+ default:
+ return false;
+ }
+}
+
+} // leak_detector

Powered by Google App Engine
This is Rietveld 408576698