template<typename T>
struct VectorTraitsBase
{
- static const bool needsDestruction = !IsPod<T>::value;
- static const bool canInitializeWithMemset = IsPod<T>::value;
- static const bool canMoveWithMemcpy = IsPod<T>::value;
- static const bool canCopyWithMemcpy = IsPod<T>::value;
- static const bool canFillWithMemset = IsPod<T>::value && (sizeof(T) == sizeof(char));
- static const bool canCompareWithMemcmp = IsPod<T>::value;
+ static const bool needsDestruction = !IsTriviallyDestructible<T>::value;
+ static const bool canInitializeWithMemset = IsTriviallyDefaultConstructible<T>::value;
+ static const bool canMoveWithMemcpy = IsTriviallyMoveAssignable<T>::value;
+ static const bool canCopyWithMemcpy = IsTriviallyCopyAssignable<T>::value;
+ static const bool canFillWithMemset = IsTriviallyDefaultConstructible<T>::value && (sizeof(T) == sizeof(char));
+ static const bool canCompareWithMemcmp = IsScalar<T>::value; // Types without padding.
template<typename U = void>
struct NeedsTracingLazily {
static const bool value = NeedsTracing<T>::value;
struct VectorTraits<RefPtr<P> > : SimpleClassVectorTraits<RefPtr<P> > { };
template<typename P>
- struct VectorTraits<OwnPtr<P> > : SimpleClassVectorTraits<OwnPtr<P> > { };
+ struct VectorTraits<OwnPtr<P> > : SimpleClassVectorTraits<OwnPtr<P> > {
+ // OwnPtr -> PassOwnPtr has a very particular structure that
+ // tricks the normal type traits into thinking that the class
+ // is "trivially copyable".
+ static const bool canCopyWithMemcpy = false;
+ };
+ COMPILE_ASSERT(VectorTraits<RefPtr<int> >::canInitializeWithMemset, inefficientRefPtrVector);
+ COMPILE_ASSERT(VectorTraits<RefPtr<int> >::canMoveWithMemcpy, inefficientRefPtrVector);
+ COMPILE_ASSERT(VectorTraits<RefPtr<int> >::canCompareWithMemcmp, inefficientRefPtrVector);
+ COMPILE_ASSERT(VectorTraits<OwnPtr<int> >::canInitializeWithMemset, inefficientOwnPtrVector);
+ COMPILE_ASSERT(VectorTraits<OwnPtr<int> >::canMoveWithMemcpy, inefficientOwnPtrVector);
+ COMPILE_ASSERT(VectorTraits<OwnPtr<int> >::canCompareWithMemcmp, inefficientOwnPtrVector);
template<typename First, typename Second>
struct VectorTraits<pair<First, Second> >
#define WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(ClassName) \
namespace WTF { \
+COMPILE_ASSERT(!IsTriviallyDefaultConstructible<ClassName>::value || !IsTriviallyCopyAssignable<ClassName>::value, macro_not_needed); \
template<> \
struct VectorTraits<ClassName> : SimpleClassVectorTraits<ClassName> { }; \
}
#define WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(ClassName) \
namespace WTF { \
+COMPILE_ASSERT(!WTF::IsTriviallyDefaultConstructible<ClassName>::value || !IsTriviallyCopyAssignable<ClassName>::value, macro_not_needed); \
template<> \
struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> \
{ \
#define WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(ClassName) \
namespace WTF { \
+COMPILE_ASSERT(!WTF::IsTriviallyDefaultConstructible<ClassName>::value, macro_not_needed); \
template<> \
struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> \
{ \