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

Unified Diff: Source/wtf/VectorTraits.h

Issue 594023002: Expanding Type Traits to make Vector use mem ops more. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/wtf/TypeTraits.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/VectorTraits.h
diff --git a/Source/wtf/VectorTraits.h b/Source/wtf/VectorTraits.h
index 2b6544ce35239b8d755ebc3a534c09f5d994d73e..50f41a1f30d4358932126744712aa7311d9000fb 100644
--- a/Source/wtf/VectorTraits.h
+++ b/Source/wtf/VectorTraits.h
@@ -35,12 +35,12 @@ namespace WTF {
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;
@@ -69,7 +69,18 @@ namespace WTF {
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> >
@@ -94,12 +105,14 @@ namespace WTF {
#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> \
{ \
@@ -110,6 +123,7 @@ namespace WTF { \
#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> \
{ \
« no previous file with comments | « Source/wtf/TypeTraits.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698