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

Side by Side Diff: third_party/WebKit/Source/wtf/TerminatedArray.h

Issue 2610113002: Enforce canCopyWithMemcpy constraint over TerminatedArray<T>. (Closed)
Patch Set: formatted Created 3 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef TerminatedArray_h 4 #ifndef TerminatedArray_h
5 #define TerminatedArray_h 5 #define TerminatedArray_h
6 6
7 #include "wtf/Allocator.h" 7 #include "wtf/Allocator.h"
8 #include "wtf/PtrUtil.h" 8 #include "wtf/PtrUtil.h"
9 #include "wtf/VectorTraits.h"
9 #include "wtf/allocator/Partitions.h" 10 #include "wtf/allocator/Partitions.h"
10 #include <memory> 11 #include <memory>
11 12
12 namespace WTF { 13 namespace WTF {
13 14
14 // TerminatedArray<T> represents a sequence of elements of type T in which each 15 // TerminatedArray<T> represents a sequence of elements of type T in which each
15 // element knows whether it is the last element in the sequence or not. For this 16 // element knows whether it is the last element in the sequence or not. For this
16 // check type T must provide isLastInArray method. 17 // check type T must provide isLastInArray method.
17 // TerminatedArray<T> can only be constructed by TerminatedArrayBuilder<T>. 18 // TerminatedArray<T> can only be constructed by TerminatedArrayBuilder<T>.
18 template <typename T> 19 template <typename T>
19 class TerminatedArray { 20 class TerminatedArray {
20 DISALLOW_NEW(); 21 DISALLOW_NEW();
21 WTF_MAKE_NONCOPYABLE(TerminatedArray); 22 WTF_MAKE_NONCOPYABLE(TerminatedArray);
22 23
23 public: 24 public:
25 // When TerminatedArray::Allocator implementations grow the backing
26 // store, old is copied into the new and larger block.
27 static_assert(VectorTraits<T>::canCopyWithMemcpy,
28 "Array elements must be memory copyable");
29
24 T& at(size_t index) { return reinterpret_cast<T*>(this)[index]; } 30 T& at(size_t index) { return reinterpret_cast<T*>(this)[index]; }
25 const T& at(size_t index) const { 31 const T& at(size_t index) const {
26 return reinterpret_cast<const T*>(this)[index]; 32 return reinterpret_cast<const T*>(this)[index];
27 } 33 }
28 34
29 template <typename U> 35 template <typename U>
30 class iterator_base final { 36 class iterator_base final {
31 STACK_ALLOCATED(); 37 STACK_ALLOCATED();
32 38
33 public: 39 public:
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 114
109 template <typename, template <typename> class> 115 template <typename, template <typename> class>
110 friend class TerminatedArrayBuilder; 116 friend class TerminatedArrayBuilder;
111 }; 117 };
112 118
113 } // namespace WTF 119 } // namespace WTF
114 120
115 using WTF::TerminatedArray; 121 using WTF::TerminatedArray;
116 122
117 #endif // TerminatedArray_h 123 #endif // TerminatedArray_h
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698