| OLD | NEW |
| 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 18 matching lines...) Expand all Loading... |
| 29 using std::pair; | 29 using std::pair; |
| 30 | 30 |
| 31 namespace WTF { | 31 namespace WTF { |
| 32 | 32 |
| 33 class AtomicString; | 33 class AtomicString; |
| 34 | 34 |
| 35 template<typename T> | 35 template<typename T> |
| 36 struct VectorTraitsBase | 36 struct VectorTraitsBase |
| 37 { | 37 { |
| 38 static const bool needsDestruction = !IsTriviallyDestructible<T>::value; | 38 static const bool needsDestruction = !IsTriviallyDestructible<T>::value; |
| 39 |
| 39 static const bool canInitializeWithMemset = IsTriviallyDefaultConstructi
ble<T>::value; | 40 static const bool canInitializeWithMemset = IsTriviallyDefaultConstructi
ble<T>::value; |
| 41 // true iff memset(slot, 0, size) constructs an unused slot value that i
s valid for |
| 42 // Oilpan to trace and if the value needs destruction, its destructor ca
n be invoked |
| 43 // over. The zero'ed value representing an unused slot in the vector's b
acking storage; |
| 44 // it does not have to be equal to what its constructor(s) would create,
only be |
| 45 // valid for those two uses. |
| 46 static const bool canClearUnusedSlotsWithMemset = IsTriviallyDefaultCons
tructible<T>::value; |
| 47 |
| 40 static const bool canMoveWithMemcpy = IsTriviallyMoveAssignable<T>::valu
e; | 48 static const bool canMoveWithMemcpy = IsTriviallyMoveAssignable<T>::valu
e; |
| 41 static const bool canCopyWithMemcpy = IsTriviallyCopyAssignable<T>::valu
e; | 49 static const bool canCopyWithMemcpy = IsTriviallyCopyAssignable<T>::valu
e; |
| 42 static const bool canFillWithMemset = IsTriviallyDefaultConstructible<T>
::value && (sizeof(T) == sizeof(char)); | 50 static const bool canFillWithMemset = IsTriviallyDefaultConstructible<T>
::value && (sizeof(T) == sizeof(char)); |
| 43 static const bool canCompareWithMemcmp = IsScalar<T>::value; // Types wi
thout padding. | 51 static const bool canCompareWithMemcmp = IsScalar<T>::value; // Types wi
thout padding. |
| 44 template<typename U = void> | 52 template<typename U = void> |
| 45 struct NeedsTracingLazily { | 53 struct NeedsTracingLazily { |
| 46 static const bool value = NeedsTracing<T>::value; | 54 static const bool value = NeedsTracing<T>::value; |
| 47 }; | 55 }; |
| 48 static const WeakHandlingFlag weakHandlingFlag = NoWeakHandlingInCollect
ions; // We don't support weak handling in vectors. | 56 static const WeakHandlingFlag weakHandlingFlag = NoWeakHandlingInCollect
ions; // We don't support weak handling in vectors. |
| 49 }; | 57 }; |
| 50 | 58 |
| 51 template<typename T> | 59 template<typename T> |
| 52 struct VectorTraits : VectorTraitsBase<T> { }; | 60 struct VectorTraits : VectorTraitsBase<T> { }; |
| 53 | 61 |
| 54 // Classes marked with SimpleVectorTraits will use memmov, memcpy, memcmp | 62 // Classes marked with SimpleVectorTraits will use memmov, memcpy, memcmp |
| 55 // instead of constructors, copy operators, etc for initialization, move | 63 // instead of constructors, copy operators, etc for initialization, move |
| 56 // and comparison. | 64 // and comparison. |
| 57 template<typename T> | 65 template<typename T> |
| 58 struct SimpleClassVectorTraits : VectorTraitsBase<T> | 66 struct SimpleClassVectorTraits : VectorTraitsBase<T> |
| 59 { | 67 { |
| 60 static const bool canInitializeWithMemset = true; | 68 static const bool canInitializeWithMemset = true; |
| 69 static const bool canClearUnusedSlotsWithMemset = true; |
| 61 static const bool canMoveWithMemcpy = true; | 70 static const bool canMoveWithMemcpy = true; |
| 62 static const bool canCompareWithMemcmp = true; | 71 static const bool canCompareWithMemcmp = true; |
| 63 }; | 72 }; |
| 64 | 73 |
| 65 // We know OwnPtr and RefPtr are simple enough that initializing to 0 and | 74 // We know OwnPtr and RefPtr are simple enough that initializing to 0 and |
| 66 // moving with memcpy (and then not destructing the original) will totally | 75 // moving with memcpy (and then not destructing the original) will totally |
| 67 // work. | 76 // work. |
| 68 template<typename P> | 77 template<typename P> |
| 69 struct VectorTraits<RefPtr<P>> : SimpleClassVectorTraits<RefPtr<P>> { }; | 78 struct VectorTraits<RefPtr<P>> : SimpleClassVectorTraits<RefPtr<P>> { }; |
| 70 | 79 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 87 { | 96 { |
| 88 typedef VectorTraits<First> FirstTraits; | 97 typedef VectorTraits<First> FirstTraits; |
| 89 typedef VectorTraits<Second> SecondTraits; | 98 typedef VectorTraits<Second> SecondTraits; |
| 90 | 99 |
| 91 static const bool needsDestruction = FirstTraits::needsDestruction || Se
condTraits::needsDestruction; | 100 static const bool needsDestruction = FirstTraits::needsDestruction || Se
condTraits::needsDestruction; |
| 92 static const bool canInitializeWithMemset = FirstTraits::canInitializeWi
thMemset && SecondTraits::canInitializeWithMemset; | 101 static const bool canInitializeWithMemset = FirstTraits::canInitializeWi
thMemset && SecondTraits::canInitializeWithMemset; |
| 93 static const bool canMoveWithMemcpy = FirstTraits::canMoveWithMemcpy &&
SecondTraits::canMoveWithMemcpy; | 102 static const bool canMoveWithMemcpy = FirstTraits::canMoveWithMemcpy &&
SecondTraits::canMoveWithMemcpy; |
| 94 static const bool canCopyWithMemcpy = FirstTraits::canCopyWithMemcpy &&
SecondTraits::canCopyWithMemcpy; | 103 static const bool canCopyWithMemcpy = FirstTraits::canCopyWithMemcpy &&
SecondTraits::canCopyWithMemcpy; |
| 95 static const bool canFillWithMemset = false; | 104 static const bool canFillWithMemset = false; |
| 96 static const bool canCompareWithMemcmp = FirstTraits::canCompareWithMemc
mp && SecondTraits::canCompareWithMemcmp; | 105 static const bool canCompareWithMemcmp = FirstTraits::canCompareWithMemc
mp && SecondTraits::canCompareWithMemcmp; |
| 106 static const bool canClearUnusedSlotsWithMemset = FirstTraits::canClearU
nusedSlotsWithMemset && SecondTraits::canClearUnusedSlotsWithMemset; |
| 97 template <typename U = void> | 107 template <typename U = void> |
| 98 struct NeedsTracingLazily { | 108 struct NeedsTracingLazily { |
| 99 static const bool value = ShouldBeTraced<FirstTraits>::value || Shou
ldBeTraced<SecondTraits>::value; | 109 static const bool value = ShouldBeTraced<FirstTraits>::value || Shou
ldBeTraced<SecondTraits>::value; |
| 100 }; | 110 }; |
| 101 static const WeakHandlingFlag weakHandlingFlag = NoWeakHandlingInCollect
ions; // We don't support weak handling in vectors. | 111 static const WeakHandlingFlag weakHandlingFlag = NoWeakHandlingInCollect
ions; // We don't support weak handling in vectors. |
| 102 }; | 112 }; |
| 103 | 113 |
| 104 } // namespace WTF | 114 } // namespace WTF |
| 105 | 115 |
| 106 #define WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(ClassName) \ | 116 #define WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(ClassName) \ |
| 107 namespace WTF { \ | 117 namespace WTF { \ |
| 108 static_assert(!IsTriviallyDefaultConstructible<ClassName>::value || !IsTrivially
MoveAssignable<ClassName>::value || !IsScalar<ClassName>::value, "macro not need
ed"); \ | 118 static_assert(!IsTriviallyDefaultConstructible<ClassName>::value || !IsTrivially
MoveAssignable<ClassName>::value || !IsScalar<ClassName>::value, "macro not need
ed"); \ |
| 109 template<> \ | 119 template<> \ |
| 110 struct VectorTraits<ClassName> : SimpleClassVectorTraits<ClassName> { }; \ | 120 struct VectorTraits<ClassName> : SimpleClassVectorTraits<ClassName> { }; \ |
| 111 } | 121 } |
| 112 | 122 |
| 113 #define WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(ClassName) \ | 123 #define WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(ClassName) \ |
| 114 namespace WTF { \ | 124 namespace WTF { \ |
| 115 static_assert(!IsTriviallyDefaultConstructible<ClassName>::value || !IsTrivially
MoveAssignable<ClassName>::value, "macro not needed"); \ | 125 static_assert(!IsTriviallyDefaultConstructible<ClassName>::value || !IsTrivially
MoveAssignable<ClassName>::value, "macro not needed"); \ |
| 116 template<> \ | 126 template<> \ |
| 117 struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> \ | 127 struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> \ |
| 118 { \ | 128 { \ |
| 119 static const bool canInitializeWithMemset = true; \ | 129 static const bool canInitializeWithMemset = true; \ |
| 130 static const bool canClearUnusedSlotsWithMemset = true; \ |
| 120 static const bool canMoveWithMemcpy = true; \ | 131 static const bool canMoveWithMemcpy = true; \ |
| 121 }; \ | 132 }; \ |
| 122 } | 133 } |
| 123 | 134 |
| 124 #define WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(ClassName) \ | 135 #define WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(ClassName) \ |
| 125 namespace WTF { \ | 136 namespace WTF { \ |
| 126 static_assert(!IsTriviallyDefaultConstructible<ClassName>::value, "macro not nee
ded"); \ | 137 static_assert(!IsTriviallyDefaultConstructible<ClassName>::value, "macro not nee
ded"); \ |
| 127 template<> \ | 138 template<> \ |
| 128 struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> \ | 139 struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> \ |
| 129 { \ | 140 { \ |
| 130 static const bool canInitializeWithMemset = true; \ | 141 static const bool canInitializeWithMemset = true; \ |
| 142 static const bool canClearUnusedSlotsWithMemset = true; \ |
| 131 }; \ | 143 }; \ |
| 132 } | 144 } |
| 133 | 145 |
| 146 #define WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS(ClassName) \ |
| 147 namespace WTF { \ |
| 148 static_assert(!IsTriviallyDefaultConstructible<ClassName>::value, "macro not nee
ded"); \ |
| 149 template<> \ |
| 150 struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> \ |
| 151 { \ |
| 152 static const bool canClearUnusedSlotsWithMemset = true; \ |
| 153 }; \ |
| 154 } |
| 155 |
| 134 using WTF::VectorTraits; | 156 using WTF::VectorTraits; |
| 135 using WTF::SimpleClassVectorTraits; | 157 using WTF::SimpleClassVectorTraits; |
| 136 | 158 |
| 137 #endif // WTF_VectorTraits_h | 159 #endif // WTF_VectorTraits_h |
| OLD | NEW |