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 17 matching lines...) Expand all Loading... |
28 | 28 |
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 = !IsPod<T>::value; |
39 static const bool canInitializeWithMemset = IsTriviallyDefaultConstructi
ble<T>::value; | 39 static const bool canInitializeWithMemset = IsPod<T>::value; |
40 static const bool canMoveWithMemcpy = IsTriviallyMoveAssignable<T>::valu
e; | 40 static const bool canMoveWithMemcpy = IsPod<T>::value; |
41 static const bool canCopyWithMemcpy = IsTriviallyCopyAssignable<T>::valu
e; | 41 static const bool canCopyWithMemcpy = IsPod<T>::value; |
42 static const bool canFillWithMemset = IsTriviallyDefaultConstructible<T>
::value && (sizeof(T) == sizeof(char)); | 42 static const bool canFillWithMemset = IsPod<T>::value && (sizeof(T) == s
izeof(char)); |
43 static const bool canCompareWithMemcmp = IsScalar<T>::value; // Types wi
thout padding. | 43 static const bool canCompareWithMemcmp = IsPod<T>::value; |
44 template<typename U = void> | 44 template<typename U = void> |
45 struct NeedsTracingLazily { | 45 struct NeedsTracingLazily { |
46 static const bool value = NeedsTracing<T>::value; | 46 static const bool value = NeedsTracing<T>::value; |
47 }; | 47 }; |
48 static const WeakHandlingFlag weakHandlingFlag = NoWeakHandlingInCollect
ions; // We don't support weak handling in vectors. | 48 static const WeakHandlingFlag weakHandlingFlag = NoWeakHandlingInCollect
ions; // We don't support weak handling in vectors. |
49 }; | 49 }; |
50 | 50 |
51 template<typename T> | 51 template<typename T> |
52 struct VectorTraits : VectorTraitsBase<T> { }; | 52 struct VectorTraits : VectorTraitsBase<T> { }; |
53 | 53 |
54 // Classes marked with SimpleVectorTraits will use memmov, memcpy, memcmp | 54 // Classes marked with SimpleVectorTraits will use memmov, memcpy, memcmp |
55 // instead of constructors, copy operators, etc for initialization, move | 55 // instead of constructors, copy operators, etc for initialization, move |
56 // and comparison. | 56 // and comparison. |
57 template<typename T> | 57 template<typename T> |
58 struct SimpleClassVectorTraits : VectorTraitsBase<T> | 58 struct SimpleClassVectorTraits : VectorTraitsBase<T> |
59 { | 59 { |
60 static const bool canInitializeWithMemset = true; | 60 static const bool canInitializeWithMemset = true; |
61 static const bool canMoveWithMemcpy = true; | 61 static const bool canMoveWithMemcpy = true; |
62 static const bool canCompareWithMemcmp = true; | 62 static const bool canCompareWithMemcmp = true; |
63 }; | 63 }; |
64 | 64 |
65 // We know OwnPtr and RefPtr are simple enough that initializing to 0 and | 65 // 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 | 66 // moving with memcpy (and then not destructing the original) will totally |
67 // work. | 67 // work. |
68 template<typename P> | 68 template<typename P> |
69 struct VectorTraits<RefPtr<P> > : SimpleClassVectorTraits<RefPtr<P> > { }; | 69 struct VectorTraits<RefPtr<P> > : SimpleClassVectorTraits<RefPtr<P> > { }; |
70 | 70 |
71 template<typename P> | 71 template<typename P> |
72 struct VectorTraits<OwnPtr<P> > : SimpleClassVectorTraits<OwnPtr<P> > { | 72 struct VectorTraits<OwnPtr<P> > : SimpleClassVectorTraits<OwnPtr<P> > { }; |
73 // OwnPtr -> PassOwnPtr has a very particular structure that | |
74 // tricks the normal type traits into thinking that the class | |
75 // is "trivially copyable". | |
76 static const bool canCopyWithMemcpy = false; | |
77 }; | |
78 COMPILE_ASSERT(VectorTraits<RefPtr<int> >::canInitializeWithMemset, ineffici
entRefPtrVector); | |
79 COMPILE_ASSERT(VectorTraits<RefPtr<int> >::canMoveWithMemcpy, inefficientRef
PtrVector); | |
80 COMPILE_ASSERT(VectorTraits<RefPtr<int> >::canCompareWithMemcmp, inefficient
RefPtrVector); | |
81 COMPILE_ASSERT(VectorTraits<OwnPtr<int> >::canInitializeWithMemset, ineffici
entOwnPtrVector); | |
82 COMPILE_ASSERT(VectorTraits<OwnPtr<int> >::canMoveWithMemcpy, inefficientOwn
PtrVector); | |
83 COMPILE_ASSERT(VectorTraits<OwnPtr<int> >::canCompareWithMemcmp, inefficient
OwnPtrVector); | |
84 | 73 |
85 template<typename First, typename Second> | 74 template<typename First, typename Second> |
86 struct VectorTraits<pair<First, Second> > | 75 struct VectorTraits<pair<First, Second> > |
87 { | 76 { |
88 typedef VectorTraits<First> FirstTraits; | 77 typedef VectorTraits<First> FirstTraits; |
89 typedef VectorTraits<Second> SecondTraits; | 78 typedef VectorTraits<Second> SecondTraits; |
90 | 79 |
91 static const bool needsDestruction = FirstTraits::needsDestruction || Se
condTraits::needsDestruction; | 80 static const bool needsDestruction = FirstTraits::needsDestruction || Se
condTraits::needsDestruction; |
92 static const bool canInitializeWithMemset = FirstTraits::canInitializeWi
thMemset && SecondTraits::canInitializeWithMemset; | 81 static const bool canInitializeWithMemset = FirstTraits::canInitializeWi
thMemset && SecondTraits::canInitializeWithMemset; |
93 static const bool canMoveWithMemcpy = FirstTraits::canMoveWithMemcpy &&
SecondTraits::canMoveWithMemcpy; | 82 static const bool canMoveWithMemcpy = FirstTraits::canMoveWithMemcpy &&
SecondTraits::canMoveWithMemcpy; |
94 static const bool canCopyWithMemcpy = FirstTraits::canCopyWithMemcpy &&
SecondTraits::canCopyWithMemcpy; | 83 static const bool canCopyWithMemcpy = FirstTraits::canCopyWithMemcpy &&
SecondTraits::canCopyWithMemcpy; |
95 static const bool canFillWithMemset = false; | 84 static const bool canFillWithMemset = false; |
96 static const bool canCompareWithMemcmp = FirstTraits::canCompareWithMemc
mp && SecondTraits::canCompareWithMemcmp; | 85 static const bool canCompareWithMemcmp = FirstTraits::canCompareWithMemc
mp && SecondTraits::canCompareWithMemcmp; |
97 template <typename U = void> | 86 template <typename U = void> |
98 struct NeedsTracingLazily { | 87 struct NeedsTracingLazily { |
99 static const bool value = ShouldBeTraced<FirstTraits>::value || Shou
ldBeTraced<SecondTraits>::value; | 88 static const bool value = ShouldBeTraced<FirstTraits>::value || Shou
ldBeTraced<SecondTraits>::value; |
100 }; | 89 }; |
101 static const WeakHandlingFlag weakHandlingFlag = NoWeakHandlingInCollect
ions; // We don't support weak handling in vectors. | 90 static const WeakHandlingFlag weakHandlingFlag = NoWeakHandlingInCollect
ions; // We don't support weak handling in vectors. |
102 }; | 91 }; |
103 | 92 |
104 } // namespace WTF | 93 } // namespace WTF |
105 | 94 |
106 #define WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(ClassName) \ | 95 #define WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(ClassName) \ |
107 namespace WTF { \ | 96 namespace WTF { \ |
108 COMPILE_ASSERT(!IsTriviallyDefaultConstructible<ClassName>::value || !IsTriviall
yCopyAssignable<ClassName>::value, macro_not_needed); \ | |
109 template<> \ | 97 template<> \ |
110 struct VectorTraits<ClassName> : SimpleClassVectorTraits<ClassName> { }; \ | 98 struct VectorTraits<ClassName> : SimpleClassVectorTraits<ClassName> { }; \ |
111 } | 99 } |
112 | 100 |
113 #define WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(ClassName) \ | 101 #define WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(ClassName) \ |
114 namespace WTF { \ | 102 namespace WTF { \ |
115 COMPILE_ASSERT(!WTF::IsTriviallyDefaultConstructible<ClassName>::value || !IsTri
viallyCopyAssignable<ClassName>::value, macro_not_needed); \ | |
116 template<> \ | 103 template<> \ |
117 struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> \ | 104 struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> \ |
118 { \ | 105 { \ |
119 static const bool canInitializeWithMemset = true; \ | 106 static const bool canInitializeWithMemset = true; \ |
120 static const bool canMoveWithMemcpy = true; \ | 107 static const bool canMoveWithMemcpy = true; \ |
121 }; \ | 108 }; \ |
122 } | 109 } |
123 | 110 |
124 #define WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(ClassName) \ | 111 #define WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(ClassName) \ |
125 namespace WTF { \ | 112 namespace WTF { \ |
126 COMPILE_ASSERT(!WTF::IsTriviallyDefaultConstructible<ClassName>::value, macro_no
t_needed); \ | |
127 template<> \ | 113 template<> \ |
128 struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> \ | 114 struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> \ |
129 { \ | 115 { \ |
130 static const bool canInitializeWithMemset = true; \ | 116 static const bool canInitializeWithMemset = true; \ |
131 }; \ | 117 }; \ |
132 } | 118 } |
133 | 119 |
134 using WTF::VectorTraits; | 120 using WTF::VectorTraits; |
135 using WTF::SimpleClassVectorTraits; | 121 using WTF::SimpleClassVectorTraits; |
136 | 122 |
137 #endif // WTF_VectorTraits_h | 123 #endif // WTF_VectorTraits_h |
OLD | NEW |