summaryrefslogtreecommitdiffstats
path: root/base/trace_event
diff options
context:
space:
mode:
authorruuda <ruuda@google.com>2015-11-23 13:46:57 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-23 21:47:44 +0000
commitb425288a3f4168d1813d7c4db83de3c801cd9365 (patch)
tree61691b66a2be26ee937027f2aa10e0dfa94123cb /base/trace_event
parent97b9851546675bd7ccc4d1dfb48cddbf3502ca94 (diff)
downloadchromium_src-b425288a3f4168d1813d7c4db83de3c801cd9365.zip
chromium_src-b425288a3f4168d1813d7c4db83de3c801cd9365.tar.gz
chromium_src-b425288a3f4168d1813d7c4db83de3c801cd9365.tar.bz2
[StyleGuide] Allow begin and end non-member functions
Allow usage of |std::begin| and |std::end|. This is useful for iterating fixed-size arrays. Discussion thread: https://groups.google.com/a/chromium.org/d/topic/cxx/5iFNE8P5qT4/discussion Furthermore, this CL replaces home-brewn |std::end|-like functions in base/trace_event with |std::end| to verify that <iterator> is supported on all platforms. Review URL: https://codereview.chromium.org/1471683002 Cr-Commit-Position: refs/heads/master@{#361192}
Diffstat (limited to 'base/trace_event')
-rw-r--r--base/trace_event/heap_profiler_allocation_context_tracker.cc12
-rw-r--r--base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc17
2 files changed, 9 insertions, 20 deletions
diff --git a/base/trace_event/heap_profiler_allocation_context_tracker.cc b/base/trace_event/heap_profiler_allocation_context_tracker.cc
index b58fb60..51e4590 100644
--- a/base/trace_event/heap_profiler_allocation_context_tracker.cc
+++ b/base/trace_event/heap_profiler_allocation_context_tracker.cc
@@ -5,6 +5,7 @@
#include "base/trace_event/heap_profiler_allocation_context_tracker.h"
#include <algorithm>
+#include <iterator>
#include "base/atomicops.h"
#include "base/threading/thread_local_storage.h"
@@ -25,13 +26,6 @@ void DestructAllocationContextTracker(void* alloc_ctx_tracker) {
delete static_cast<AllocationContextTracker*>(alloc_ctx_tracker);
}
-// Returns a pointer past the end of the fixed-size array |array| of |T| of
-// length |N|, identical to C++11 |std::end|.
-template <typename T, int N>
-T* End(T(&array)[N]) {
- return array + N;
-}
-
} // namespace
AllocationContextTracker::AllocationContextTracker() {}
@@ -99,9 +93,9 @@ AllocationContext AllocationContextTracker::GetContextSnapshot() {
// Fill the backtrace.
{
auto src = tracker->pseudo_stack_.begin();
- auto dst = ctx.backtrace.frames;
+ auto dst = std::begin(ctx.backtrace.frames);
auto src_end = tracker->pseudo_stack_.end();
- auto dst_end = End(ctx.backtrace.frames);
+ auto dst_end = std::end(ctx.backtrace.frames);
// Copy as much of the bottom of the pseudo stack into the backtrace as
// possible.
diff --git a/base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc b/base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc
index fe3f407..130a927 100644
--- a/base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc
+++ b/base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <iterator>
+
#include "base/memory/ref_counted.h"
#include "base/trace_event/heap_profiler_allocation_context.h"
#include "base/trace_event/heap_profiler_allocation_context_tracker.h"
@@ -19,23 +21,16 @@ const char kEclair[] = "Eclair";
const char kFroyo[] = "Froyo";
const char kGingerbread[] = "Gingerbread";
-// Returns a pointer past the end of the fixed-size array |array| of |T| of
-// length |N|, identical to C++11 |std::end|.
-template <typename T, int N>
-const T* End(const T(&array)[N]) {
- return array + N;
-}
-
// Asserts that the fixed-size array |expected_backtrace| matches the backtrace
// in |AllocationContextTracker::GetContextSnapshot|.
template <size_t N>
void AssertBacktraceEquals(const StackFrame(&expected_backtrace)[N]) {
AllocationContext ctx = AllocationContextTracker::GetContextSnapshot();
- auto actual = ctx.backtrace.frames;
- auto actual_bottom = End(ctx.backtrace.frames);
- auto expected = expected_backtrace;
- auto expected_bottom = End(expected_backtrace);
+ auto actual = std::begin(ctx.backtrace.frames);
+ auto actual_bottom = std::end(ctx.backtrace.frames);
+ auto expected = std::begin(expected_backtrace);
+ auto expected_bottom = std::end(expected_backtrace);
// Note that this requires the pointers to be equal, this is not doing a deep
// string comparison.