| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 static const bool canMoveWithMemcpy = IsTriviallyMoveAssignable<T>::value; | 48 static const bool canMoveWithMemcpy = IsTriviallyMoveAssignable<T>::value; |
| 49 static const bool canCopyWithMemcpy = IsTriviallyCopyAssignable<T>::value; | 49 static const bool canCopyWithMemcpy = IsTriviallyCopyAssignable<T>::value; |
| 50 static const bool canFillWithMemset = | 50 static const bool canFillWithMemset = |
| 51 IsTriviallyDefaultConstructible<T>::value && (sizeof(T) == sizeof(char)); | 51 IsTriviallyDefaultConstructible<T>::value && (sizeof(T) == sizeof(char)); |
| 52 static const bool canCompareWithMemcmp = | 52 static const bool canCompareWithMemcmp = |
| 53 std::is_scalar<T>::value; // Types without padding. | 53 std::is_scalar<T>::value; // Types without padding. |
| 54 template <typename U = void> | 54 template <typename U = void> |
| 55 struct IsTraceableInCollection { | 55 struct IsTraceableInCollection { |
| 56 static const bool value = IsTraceable<T>::value; | 56 static const bool value = IsTraceable<T>::value; |
| 57 }; | 57 }; |
| 58 static const WeakHandlingFlag weakHandlingFlag = | 58 // We don't support weak handling in vectors. |
| 59 NoWeakHandlingInCollections; // We don't support weak handling in vectors
. | 59 static const WeakHandlingFlag weakHandlingFlag = NoWeakHandlingInCollections; |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 template <typename T> | 62 template <typename T> |
| 63 struct VectorTraits : VectorTraitsBase<T> {}; | 63 struct VectorTraits : VectorTraitsBase<T> {}; |
| 64 | 64 |
| 65 // Classes marked with SimpleVectorTraits will use memmov, memcpy, memcmp | 65 // Classes marked with SimpleVectorTraits will use memmov, memcpy, memcmp |
| 66 // instead of constructors, copy operators, etc for initialization, move and | 66 // instead of constructors, copy operators, etc for initialization, move and |
| 67 // comparison. | 67 // comparison. |
| 68 template <typename T> | 68 template <typename T> |
| 69 struct SimpleClassVectorTraits : VectorTraitsBase<T> { | 69 struct SimpleClassVectorTraits : VectorTraitsBase<T> { |
| 70 static const bool canInitializeWithMemset = true; | 70 static const bool canInitializeWithMemset = true; |
| 71 static const bool canClearUnusedSlotsWithMemset = true; | 71 static const bool canClearUnusedSlotsWithMemset = true; |
| 72 static const bool canMoveWithMemcpy = true; | 72 static const bool canMoveWithMemcpy = true; |
| 73 static const bool canCompareWithMemcmp = true; | 73 static const bool canCompareWithMemcmp = true; |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 // We know std::unique_ptr and RefPtr are simple enough that initializing to 0 a
nd moving | 76 // We know std::unique_ptr and RefPtr are simple enough that initializing to 0 |
| 77 // with memcpy (and then not destructing the original) will totally work. | 77 // and moving with memcpy (and then not destructing the original) will totally |
| 78 // work. |
| 78 template <typename P> | 79 template <typename P> |
| 79 struct VectorTraits<RefPtr<P>> : SimpleClassVectorTraits<RefPtr<P>> {}; | 80 struct VectorTraits<RefPtr<P>> : SimpleClassVectorTraits<RefPtr<P>> {}; |
| 80 | 81 |
| 81 template <typename P> | 82 template <typename P> |
| 82 struct VectorTraits<std::unique_ptr<P>> | 83 struct VectorTraits<std::unique_ptr<P>> |
| 83 : SimpleClassVectorTraits<std::unique_ptr<P>> { | 84 : SimpleClassVectorTraits<std::unique_ptr<P>> { |
| 84 // std::unique_ptr -> std::unique_ptr has a very particular structure that tri
cks the | 85 // std::unique_ptr -> std::unique_ptr has a very particular structure that |
| 85 // normal type traits into thinking that the class is "trivially copyable". | 86 // tricks the normal type traits into thinking that the class is "trivially |
| 87 // copyable". |
| 86 static const bool canCopyWithMemcpy = false; | 88 static const bool canCopyWithMemcpy = false; |
| 87 }; | 89 }; |
| 88 static_assert(VectorTraits<RefPtr<int>>::canInitializeWithMemset, | 90 static_assert(VectorTraits<RefPtr<int>>::canInitializeWithMemset, |
| 89 "inefficient RefPtr Vector"); | 91 "inefficient RefPtr Vector"); |
| 90 static_assert(VectorTraits<RefPtr<int>>::canMoveWithMemcpy, | 92 static_assert(VectorTraits<RefPtr<int>>::canMoveWithMemcpy, |
| 91 "inefficient RefPtr Vector"); | 93 "inefficient RefPtr Vector"); |
| 92 static_assert(VectorTraits<RefPtr<int>>::canCompareWithMemcmp, | 94 static_assert(VectorTraits<RefPtr<int>>::canCompareWithMemcmp, |
| 93 "inefficient RefPtr Vector"); | 95 "inefficient RefPtr Vector"); |
| 94 static_assert(VectorTraits<std::unique_ptr<int>>::canInitializeWithMemset, | 96 static_assert(VectorTraits<std::unique_ptr<int>>::canInitializeWithMemset, |
| 95 "inefficient std::unique_ptr Vector"); | 97 "inefficient std::unique_ptr Vector"); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 117 FirstTraits::canCompareWithMemcmp && SecondTraits::canCompareWithMemcmp; | 119 FirstTraits::canCompareWithMemcmp && SecondTraits::canCompareWithMemcmp; |
| 118 static const bool canClearUnusedSlotsWithMemset = | 120 static const bool canClearUnusedSlotsWithMemset = |
| 119 FirstTraits::canClearUnusedSlotsWithMemset && | 121 FirstTraits::canClearUnusedSlotsWithMemset && |
| 120 SecondTraits::canClearUnusedSlotsWithMemset; | 122 SecondTraits::canClearUnusedSlotsWithMemset; |
| 121 template <typename U = void> | 123 template <typename U = void> |
| 122 struct IsTraceableInCollection { | 124 struct IsTraceableInCollection { |
| 123 static const bool value = | 125 static const bool value = |
| 124 IsTraceableInCollectionTrait<FirstTraits>::value || | 126 IsTraceableInCollectionTrait<FirstTraits>::value || |
| 125 IsTraceableInCollectionTrait<SecondTraits>::value; | 127 IsTraceableInCollectionTrait<SecondTraits>::value; |
| 126 }; | 128 }; |
| 127 static const WeakHandlingFlag weakHandlingFlag = | 129 // We don't support weak handling in vectors. |
| 128 NoWeakHandlingInCollections; // We don't support weak handling in vectors
. | 130 static const WeakHandlingFlag weakHandlingFlag = NoWeakHandlingInCollections; |
| 129 }; | 131 }; |
| 130 | 132 |
| 131 } // namespace WTF | 133 } // namespace WTF |
| 132 | 134 |
| 133 #define WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(ClassName) \ | 135 #define WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(ClassName) \ |
| 134 namespace WTF { \ | 136 namespace WTF { \ |
| 135 static_assert(!IsTriviallyDefaultConstructible<ClassName>::value || \ | 137 static_assert(!IsTriviallyDefaultConstructible<ClassName>::value || \ |
| 136 !IsTriviallyMoveAssignable<ClassName>::value || \ | 138 !IsTriviallyMoveAssignable<ClassName>::value || \ |
| 137 !std::is_scalar<ClassName>::value, \ | 139 !std::is_scalar<ClassName>::value, \ |
| 138 "macro not needed"); \ | 140 "macro not needed"); \ |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 template <> \ | 173 template <> \ |
| 172 struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> { \ | 174 struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> { \ |
| 173 static const bool canClearUnusedSlotsWithMemset = true; \ | 175 static const bool canClearUnusedSlotsWithMemset = true; \ |
| 174 }; \ | 176 }; \ |
| 175 } | 177 } |
| 176 | 178 |
| 177 using WTF::VectorTraits; | 179 using WTF::VectorTraits; |
| 178 using WTF::SimpleClassVectorTraits; | 180 using WTF::SimpleClassVectorTraits; |
| 179 | 181 |
| 180 #endif // WTF_VectorTraits_h | 182 #endif // WTF_VectorTraits_h |
| OLD | NEW |