| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/containers/stack_container.h" | 5 #include "base/containers/stack_container.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 } // anonymous namespace | 115 } // anonymous namespace |
| 116 | 116 |
| 117 #define EXPECT_ALIGNED(ptr, align) \ | 117 #define EXPECT_ALIGNED(ptr, align) \ |
| 118 EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(ptr) & (align - 1)) | 118 EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(ptr) & (align - 1)) |
| 119 | 119 |
| 120 TEST(StackContainer, BufferAlignment) { | 120 TEST(StackContainer, BufferAlignment) { |
| 121 StackVector<wchar_t, 16> text; | 121 StackVector<wchar_t, 16> text; |
| 122 text->push_back(L'A'); | 122 text->push_back(L'A'); |
| 123 EXPECT_ALIGNED(&text[0], ALIGNOF(wchar_t)); | 123 EXPECT_ALIGNED(&text[0], alignof(wchar_t)); |
| 124 | 124 |
| 125 StackVector<double, 1> doubles; | 125 StackVector<double, 1> doubles; |
| 126 doubles->push_back(0.0); | 126 doubles->push_back(0.0); |
| 127 EXPECT_ALIGNED(&doubles[0], ALIGNOF(double)); | 127 EXPECT_ALIGNED(&doubles[0], alignof(double)); |
| 128 | 128 |
| 129 StackVector<AlignedData<16>, 1> aligned16; | 129 StackVector<AlignedData<16>, 1> aligned16; |
| 130 aligned16->push_back(AlignedData<16>()); | 130 aligned16->push_back(AlignedData<16>()); |
| 131 EXPECT_ALIGNED(&aligned16[0], 16); | 131 EXPECT_ALIGNED(&aligned16[0], 16); |
| 132 | 132 |
| 133 #if !defined(__GNUC__) || defined(ARCH_CPU_X86_FAMILY) | 133 #if !defined(__GNUC__) || defined(ARCH_CPU_X86_FAMILY) |
| 134 // It seems that non-X86 gcc doesn't respect greater than 16 byte alignment. | 134 // It seems that non-X86 gcc doesn't respect greater than 16 byte alignment. |
| 135 // See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33721 for details. | 135 // See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33721 for details. |
| 136 // TODO(sbc):re-enable this if GCC starts respecting higher alignments. | 136 // TODO(sbc):re-enable this if GCC starts respecting higher alignments. |
| 137 StackVector<AlignedData<256>, 1> aligned256; | 137 StackVector<AlignedData<256>, 1> aligned256; |
| 138 aligned256->push_back(AlignedData<256>()); | 138 aligned256->push_back(AlignedData<256>()); |
| 139 EXPECT_ALIGNED(&aligned256[0], 256); | 139 EXPECT_ALIGNED(&aligned256[0], 256); |
| 140 #endif | 140 #endif |
| 141 } | 141 } |
| 142 | 142 |
| 143 template class StackVector<int, 2>; | 143 template class StackVector<int, 2>; |
| 144 template class StackVector<scoped_refptr<Dummy>, 2>; | 144 template class StackVector<scoped_refptr<Dummy>, 2>; |
| 145 | 145 |
| 146 } // namespace base | 146 } // namespace base |
| OLD | NEW |