[WTF] Set canInitializeWithMemset = true if T is an integral type
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Mar 2018 06:44:42 +0000 (06:44 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Mar 2018 06:44:42 +0000 (06:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=183357

Reviewed by Darin Adler.

This patch set `canInitializeWithMemset = true` if T is an integral type.
This can offer a chance to use memset if we use UniqueArray<T> where T is
an integral type. We also rename VectorTypeOperations::initialize to
VectorTypeOperations::initializeIfNonPOD, VectorTypeOperations::forceInitialize
to VectorTypeOperations::initialize respectively.

* wtf/RefCountedArray.h:
(WTF::RefCountedArray::RefCountedArray):
* wtf/UniqueArray.h:
* wtf/Vector.h:
(WTF::VectorTypeOperations::initializeIfNonPOD):
(WTF::VectorTypeOperations::initialize):
(WTF::Vector::Vector):
(WTF::Malloc>::resize):
(WTF::Malloc>::grow):
(WTF::VectorTypeOperations::forceInitialize): Deleted.
* wtf/VectorTraits.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229397 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/RefCountedArray.h
Source/WTF/wtf/UniqueArray.h
Source/WTF/wtf/Vector.h
Source/WTF/wtf/VectorTraits.h

index 6600b79..ca4d56b 100644 (file)
@@ -1,3 +1,28 @@
+2018-03-06  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [WTF] Set canInitializeWithMemset = true if T is an integral type
+        https://bugs.webkit.org/show_bug.cgi?id=183357
+
+        Reviewed by Darin Adler.
+
+        This patch set `canInitializeWithMemset = true` if T is an integral type.
+        This can offer a chance to use memset if we use UniqueArray<T> where T is
+        an integral type. We also rename VectorTypeOperations::initialize to
+        VectorTypeOperations::initializeIfNonPOD, VectorTypeOperations::forceInitialize
+        to VectorTypeOperations::initialize respectively.
+
+        * wtf/RefCountedArray.h:
+        (WTF::RefCountedArray::RefCountedArray):
+        * wtf/UniqueArray.h:
+        * wtf/Vector.h:
+        (WTF::VectorTypeOperations::initializeIfNonPOD):
+        (WTF::VectorTypeOperations::initialize):
+        (WTF::Vector::Vector):
+        (WTF::Malloc>::resize):
+        (WTF::Malloc>::grow):
+        (WTF::VectorTypeOperations::forceInitialize): Deleted.
+        * wtf/VectorTraits.h:
+
 2018-03-07  Keith Miller  <keith_miller@apple.com>
 
         Meta-program setupArguments and callOperation
index 6132f53..cf7cc56 100644 (file)
@@ -72,7 +72,7 @@ public:
         Header::fromPayload(data)->refCount = 1;
         Header::fromPayload(data)->length = size;
         ASSERT(Header::fromPayload(data)->length == size);
-        VectorTypeOperations<T>::initialize(begin(), end());
+        VectorTypeOperations<T>::initializeIfNonPOD(begin(), end());
     }
 
     template<typename OtherTraits = PtrTraits>
index 201ad43..a2b8585 100644 (file)
@@ -50,7 +50,7 @@ struct UniqueArrayMaker<true, T> {
         // larger storage than the `sizeof(T) * size` storage since it want to store `size`
         // to somewhere.
         T* storage = static_cast<T*>(fastMalloc((Checked<size_t>(sizeof(T)) * size).unsafeGet()));
-        VectorTypeOperations<T>::forceInitialize(storage, storage + size);
+        VectorTypeOperations<T>::initialize(storage, storage + size);
         return ResultType(storage);
     }
 };
index 1c88164..3367559 100644 (file)
@@ -68,40 +68,40 @@ struct VectorInitializer;
 template<bool canInitializeWithMemset, typename T>
 struct VectorInitializer<false, canInitializeWithMemset, T>
 {
-    static void initialize(T*, T*) {}
+    static void initializeIfNonPOD(T*, T*) { }
 
-    static void forceInitialize(T* begin, T* end)
+    static void initialize(T* begin, T* end)
     {
-        VectorInitializer<true, canInitializeWithMemset, T>::forceInitialize(begin, end);
+        VectorInitializer<true, canInitializeWithMemset, T>::initialize(begin, end);
     }
 };
 
 template<typename T>
 struct VectorInitializer<true, false, T>
 {
-    static void initialize(T* begin, T* end) 
+    static void initializeIfNonPOD(T* begin, T* end)
     {
         for (T* cur = begin; cur != end; ++cur)
             new (NotNull, cur) T();
     }
 
-    static void forceInitialize(T* begin, T* end)
+    static void initialize(T* begin, T* end)
     {
-        initialize(begin, end);
+        initializeIfNonPOD(begin, end);
     }
 };
 
 template<typename T>
 struct VectorInitializer<true, true, T>
 {
-    static void initialize(T* begin, T* end) 
+    static void initializeIfNonPOD(T* begin, T* end)
     {
         memset(begin, 0, reinterpret_cast<char*>(end) - reinterpret_cast<char*>(begin));
     }
 
-    static void forceInitialize(T* begin, T* end)
+    static void initialize(T* begin, T* end)
     {
-        initialize(begin, end);
+        initializeIfNonPOD(begin, end);
     }
 };
 
@@ -240,14 +240,14 @@ struct VectorTypeOperations
         VectorDestructor<!std::is_trivially_destructible<T>::value, T>::destruct(begin, end);
     }
 
-    static void initialize(T* begin, T* end)
+    static void initializeIfNonPOD(T* begin, T* end)
     {
-        VectorInitializer<VectorTraits<T>::needsInitialization, VectorTraits<T>::canInitializeWithMemset, T>::initialize(begin, end);
+        VectorInitializer<VectorTraits<T>::needsInitialization, VectorTraits<T>::canInitializeWithMemset, T>::initializeIfNonPOD(begin, end);
     }
 
-    static void forceInitialize(T* begin, T* end)
+    static void initialize(T* begin, T* end)
     {
-        VectorInitializer<VectorTraits<T>::needsInitialization, VectorTraits<T>::canInitializeWithMemset, T>::forceInitialize(begin, end);
+        VectorInitializer<VectorTraits<T>::needsInitialization, VectorTraits<T>::canInitializeWithMemset, T>::initialize(begin, end);
     }
 
     static void move(T* src, T* srcEnd, T* dst)
@@ -649,7 +649,7 @@ public:
         asanSetInitialBufferSizeTo(size);
 
         if (begin())
-            TypeOperations::initialize(begin(), end());
+            TypeOperations::initializeIfNonPOD(begin(), end());
     }
 
     Vector(size_t size, const T& val)
@@ -1107,7 +1107,7 @@ inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::res
             expandCapacity(size);
         asanBufferSizeWillChangeTo(size);
         if (begin())
-            TypeOperations::initialize(end(), begin() + size);
+            TypeOperations::initializeIfNonPOD(end(), begin() + size);
     }
     
     m_size = size;
@@ -1137,7 +1137,7 @@ void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::grow(size_
         expandCapacity(size);
     asanBufferSizeWillChangeTo(size);
     if (begin())
-        TypeOperations::initialize(end(), begin() + size);
+        TypeOperations::initializeIfNonPOD(end(), begin() + size);
     m_size = size;
 }
 
index b3fb077..4967e9f 100644 (file)
@@ -49,7 +49,7 @@ namespace WTF {
     struct VectorTraitsBase<true, T>
     {
         static const bool needsInitialization = false;
-        static const bool canInitializeWithMemset = false;
+        static const bool canInitializeWithMemset = true;
         static const bool canMoveWithMemcpy = true;
         static const bool canCopyWithMemcpy = true;
         static const bool canFillWithMemset = sizeof(T) == sizeof(char) && std::is_integral<T>::value;