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

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

Issue 1436153002: Apply clang-format with Chromium-style without column limit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 | « third_party/WebKit/Source/wtf/VectorTest.cpp ('k') | third_party/WebKit/Source/wtf/WTF.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 14 matching lines...) Expand all
25 #include "wtf/RefPtr.h" 25 #include "wtf/RefPtr.h"
26 #include "wtf/TypeTraits.h" 26 #include "wtf/TypeTraits.h"
27 #include <utility> 27 #include <utility>
28 28
29 namespace WTF { 29 namespace WTF {
30 30
31 class AtomicString; 31 class AtomicString;
32 32
33 template <typename T> 33 template <typename T>
34 struct VectorTraitsBase { 34 struct VectorTraitsBase {
35 static const bool needsDestruction = !IsTriviallyDestructible<T>::value; 35 static const bool needsDestruction = !IsTriviallyDestructible<T>::value;
36 36
37 static const bool canInitializeWithMemset = IsTriviallyDefaultConstructible< T>::value; 37 static const bool canInitializeWithMemset = IsTriviallyDefaultConstructible<T> ::value;
38 // true iff memset(slot, 0, size) constructs an unused slot value that is 38 // true iff memset(slot, 0, size) constructs an unused slot value that is
39 // valid for Oilpan to trace and if the value needs destruction, its 39 // valid for Oilpan to trace and if the value needs destruction, its
40 // destructor can be invoked over. The zero'ed value representing an unused 40 // destructor can be invoked over. The zero'ed value representing an unused
41 // slot in the vector's backing storage; it does not have to be equal to 41 // slot in the vector's backing storage; it does not have to be equal to
42 // what its constructor(s) would create, only be valid for those two uses. 42 // what its constructor(s) would create, only be valid for those two uses.
43 static const bool canClearUnusedSlotsWithMemset = IsTriviallyDefaultConstruc tible<T>::value; 43 static const bool canClearUnusedSlotsWithMemset = IsTriviallyDefaultConstructi ble<T>::value;
44 44
45 static const bool canMoveWithMemcpy = IsTriviallyMoveAssignable<T>::value; 45 static const bool canMoveWithMemcpy = IsTriviallyMoveAssignable<T>::value;
46 static const bool canCopyWithMemcpy = IsTriviallyCopyAssignable<T>::value; 46 static const bool canCopyWithMemcpy = IsTriviallyCopyAssignable<T>::value;
47 static const bool canFillWithMemset = IsTriviallyDefaultConstructible<T>::va lue && (sizeof(T) == sizeof(char)); 47 static const bool canFillWithMemset = IsTriviallyDefaultConstructible<T>::valu e && (sizeof(T) == sizeof(char));
48 static const bool canCompareWithMemcmp = IsScalar<T>::value; // Types withou t padding. 48 static const bool canCompareWithMemcmp = IsScalar<T>::value; // Types without padding.
49 template <typename U = void> 49 template <typename U = void>
50 struct NeedsTracingLazily { 50 struct NeedsTracingLazily {
51 static const bool value = NeedsTracing<T>::value; 51 static const bool value = NeedsTracing<T>::value;
52 }; 52 };
53 static const WeakHandlingFlag weakHandlingFlag = NoWeakHandlingInCollections ; // We don't support weak handling in vectors. 53 static const WeakHandlingFlag weakHandlingFlag = NoWeakHandlingInCollections; // We don't support weak handling in vectors.
54 }; 54 };
55 55
56 template <typename T> 56 template <typename T>
57 struct VectorTraits : VectorTraitsBase<T> {}; 57 struct VectorTraits : VectorTraitsBase<T> {};
58 58
59 // Classes marked with SimpleVectorTraits will use memmov, memcpy, memcmp 59 // Classes marked with SimpleVectorTraits will use memmov, memcpy, memcmp
60 // instead of constructors, copy operators, etc for initialization, move and 60 // instead of constructors, copy operators, etc for initialization, move and
61 // comparison. 61 // comparison.
62 template <typename T> 62 template <typename T>
63 struct SimpleClassVectorTraits : VectorTraitsBase<T> { 63 struct SimpleClassVectorTraits : VectorTraitsBase<T> {
64 static const bool canInitializeWithMemset = true; 64 static const bool canInitializeWithMemset = true;
65 static const bool canClearUnusedSlotsWithMemset = true; 65 static const bool canClearUnusedSlotsWithMemset = true;
66 static const bool canMoveWithMemcpy = true; 66 static const bool canMoveWithMemcpy = true;
67 static const bool canCompareWithMemcmp = true; 67 static const bool canCompareWithMemcmp = true;
68 }; 68 };
69 69
70 // We know OwnPtr and RefPtr are simple enough that initializing to 0 and moving 70 // We know OwnPtr and RefPtr are simple enough that initializing to 0 and moving
71 // with memcpy (and then not destructing the original) will totally work. 71 // with memcpy (and then not destructing the original) will totally work.
72 template <typename P> 72 template <typename P>
73 struct VectorTraits<RefPtr<P>> : SimpleClassVectorTraits<RefPtr<P>> {}; 73 struct VectorTraits<RefPtr<P>> : SimpleClassVectorTraits<RefPtr<P>> {};
74 74
75 template <typename P> 75 template <typename P>
76 struct VectorTraits<OwnPtr<P>> : SimpleClassVectorTraits<OwnPtr<P>> { 76 struct VectorTraits<OwnPtr<P>> : SimpleClassVectorTraits<OwnPtr<P>> {
77 // OwnPtr -> PassOwnPtr has a very particular structure that tricks the 77 // OwnPtr -> PassOwnPtr has a very particular structure that tricks the
78 // normal type traits into thinking that the class is "trivially copyable". 78 // normal type traits into thinking that the class is "trivially copyable".
79 static const bool canCopyWithMemcpy = false; 79 static const bool canCopyWithMemcpy = false;
80 }; 80 };
81 static_assert(VectorTraits<RefPtr<int>>::canInitializeWithMemset, "inefficient R efPtr Vector"); 81 static_assert(VectorTraits<RefPtr<int>>::canInitializeWithMemset, "inefficient R efPtr Vector");
82 static_assert(VectorTraits<RefPtr<int>>::canMoveWithMemcpy, "inefficient RefPtr Vector"); 82 static_assert(VectorTraits<RefPtr<int>>::canMoveWithMemcpy, "inefficient RefPtr Vector");
83 static_assert(VectorTraits<RefPtr<int>>::canCompareWithMemcmp, "inefficient RefP tr Vector"); 83 static_assert(VectorTraits<RefPtr<int>>::canCompareWithMemcmp, "inefficient RefP tr Vector");
84 static_assert(VectorTraits<OwnPtr<int>>::canInitializeWithMemset, "inefficient O wnPtr Vector"); 84 static_assert(VectorTraits<OwnPtr<int>>::canInitializeWithMemset, "inefficient O wnPtr Vector");
85 static_assert(VectorTraits<OwnPtr<int>>::canMoveWithMemcpy, "inefficient OwnPtr Vector"); 85 static_assert(VectorTraits<OwnPtr<int>>::canMoveWithMemcpy, "inefficient OwnPtr Vector");
86 static_assert(VectorTraits<OwnPtr<int>>::canCompareWithMemcmp, "inefficient OwnP tr Vector"); 86 static_assert(VectorTraits<OwnPtr<int>>::canCompareWithMemcmp, "inefficient OwnP tr Vector");
87 87
88 template <typename First, typename Second> 88 template <typename First, typename Second>
89 struct VectorTraits<std::pair<First, Second>> { 89 struct VectorTraits<std::pair<First, Second>> {
90 typedef VectorTraits<First> FirstTraits; 90 typedef VectorTraits<First> FirstTraits;
91 typedef VectorTraits<Second> SecondTraits; 91 typedef VectorTraits<Second> SecondTraits;
92 92
93 static const bool needsDestruction = FirstTraits::needsDestruction || Second Traits::needsDestruction; 93 static const bool needsDestruction = FirstTraits::needsDestruction || SecondTr aits::needsDestruction;
94 static const bool canInitializeWithMemset = FirstTraits::canInitializeWithMe mset && SecondTraits::canInitializeWithMemset; 94 static const bool canInitializeWithMemset = FirstTraits::canInitializeWithMems et && SecondTraits::canInitializeWithMemset;
95 static const bool canMoveWithMemcpy = FirstTraits::canMoveWithMemcpy && Seco ndTraits::canMoveWithMemcpy; 95 static const bool canMoveWithMemcpy = FirstTraits::canMoveWithMemcpy && Second Traits::canMoveWithMemcpy;
96 static const bool canCopyWithMemcpy = FirstTraits::canCopyWithMemcpy && Seco ndTraits::canCopyWithMemcpy; 96 static const bool canCopyWithMemcpy = FirstTraits::canCopyWithMemcpy && Second Traits::canCopyWithMemcpy;
97 static const bool canFillWithMemset = false; 97 static const bool canFillWithMemset = false;
98 static const bool canCompareWithMemcmp = FirstTraits::canCompareWithMemcmp & & SecondTraits::canCompareWithMemcmp; 98 static const bool canCompareWithMemcmp = FirstTraits::canCompareWithMemcmp && SecondTraits::canCompareWithMemcmp;
99 static const bool canClearUnusedSlotsWithMemset = FirstTraits::canClearUnuse dSlotsWithMemset && SecondTraits::canClearUnusedSlotsWithMemset; 99 static const bool canClearUnusedSlotsWithMemset = FirstTraits::canClearUnusedS lotsWithMemset && SecondTraits::canClearUnusedSlotsWithMemset;
100 template <typename U = void> 100 template <typename U = void>
101 struct NeedsTracingLazily { 101 struct NeedsTracingLazily {
102 static const bool value = NeedsTracingTrait<FirstTraits>::value || Needs TracingTrait<SecondTraits>::value; 102 static const bool value = NeedsTracingTrait<FirstTraits>::value || NeedsTrac ingTrait<SecondTraits>::value;
103 }; 103 };
104 static const WeakHandlingFlag weakHandlingFlag = NoWeakHandlingInCollections ; // We don't support weak handling in vectors. 104 static const WeakHandlingFlag weakHandlingFlag = NoWeakHandlingInCollections; // We don't support weak handling in vectors.
105 }; 105 };
106 106
107 } // namespace WTF 107 } // namespace WTF
108 108
109 #define WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(ClassName) \ 109 #define WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(ClassName) \
110 namespace WTF { \ 110 namespace WTF { \
111 static_assert(!IsTriviallyDefaultConstructible<ClassName>::value || !IsTrivially MoveAssignable<ClassName>::value || !IsScalar<ClassName>::value, "macro not need ed"); \ 111 static_assert(!IsTriviallyDefaultConstructible<ClassName>::value || !IsTrivial lyMoveAssignable<ClassName>::value || !IsScalar<ClassName>::value, "macro not ne eded"); \
112 template <> \ 112 template <> \
113 struct VectorTraits<ClassName> : SimpleClassVectorTraits<ClassName> {}; \ 113 struct VectorTraits<ClassName> : SimpleClassVectorTraits<ClassName> {}; \
114 } 114 }
115 115
116 #define WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(ClassName) \ 116 #define WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(ClassName) \
117 namespace WTF { \ 117 namespace WTF { \
118 static_assert(!IsTriviallyDefaultConstructible<ClassName>::value || !IsTrivially MoveAssignable<ClassName>::value, "macro not needed"); \ 118 static_assert(!IsTriviallyDefaultConstructible<ClassName>::value || !IsTrivial lyMoveAssignable<ClassName>::value, "macro not needed"); \
119 template <> \ 119 template <> \
120 struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> \ 120 struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> { \
121 { \ 121 static const bool canInitializeWithMemset = true; \
122 static const bool canInitializeWithMemset = true; \ 122 static const bool canClearUnusedSlotsWithMemset = true; \
123 static const bool canClearUnusedSlotsWithMemset = true; \ 123 static const bool canMoveWithMemcpy = true; \
124 static const bool canMoveWithMemcpy = true; \ 124 }; \
125 }; \ 125 }
126 }
127 126
128 #define WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(ClassName) \ 127 #define WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(ClassName) \
129 namespace WTF { \ 128 namespace WTF { \
130 static_assert(!IsTriviallyDefaultConstructible<ClassName>::value, "macro not nee ded"); \ 129 static_assert(!IsTriviallyDefaultConstructible<ClassName>::value, "macro not n eeded"); \
131 template <> \ 130 template <> \
132 struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> \ 131 struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> { \
133 { \ 132 static const bool canInitializeWithMemset = true; \
134 static const bool canInitializeWithMemset = true; \ 133 static const bool canClearUnusedSlotsWithMemset = true; \
135 static const bool canClearUnusedSlotsWithMemset = true; \ 134 }; \
136 }; \ 135 }
137 }
138 136
139 #define WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS(ClassName) \ 137 #define WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS(ClassName) \
140 namespace WTF { \ 138 namespace WTF { \
141 static_assert(!IsTriviallyDefaultConstructible<ClassName>::value, "macro not nee ded"); \ 139 static_assert(!IsTriviallyDefaultConstructible<ClassName>::value, "macro not n eeded"); \
142 template <> \ 140 template <> \
143 struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> \ 141 struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> { \
144 { \ 142 static const bool canClearUnusedSlotsWithMemset = true; \
145 static const bool canClearUnusedSlotsWithMemset = true; \ 143 }; \
146 }; \ 144 }
147 }
148 145
149 using WTF::VectorTraits; 146 using WTF::VectorTraits;
150 using WTF::SimpleClassVectorTraits; 147 using WTF::SimpleClassVectorTraits;
151 148
152 #endif // WTF_VectorTraits_h 149 #endif // WTF_VectorTraits_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/VectorTest.cpp ('k') | third_party/WebKit/Source/wtf/WTF.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698