Title: [229397] trunk/Source/WTF
Revision
229397
Author
utatane....@gmail.com
Date
2018-03-07 22:44:42 -0800 (Wed, 07 Mar 2018)

Log Message

[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:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (229396 => 229397)


--- trunk/Source/WTF/ChangeLog	2018-03-08 06:37:41 UTC (rev 229396)
+++ trunk/Source/WTF/ChangeLog	2018-03-08 06:44:42 UTC (rev 229397)
@@ -1,3 +1,28 @@
+2018-03-06  Yusuke Suzuki  <utatane....@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_mil...@apple.com>
 
         Meta-program setupArguments and callOperation

Modified: trunk/Source/WTF/wtf/RefCountedArray.h (229396 => 229397)


--- trunk/Source/WTF/wtf/RefCountedArray.h	2018-03-08 06:37:41 UTC (rev 229396)
+++ trunk/Source/WTF/wtf/RefCountedArray.h	2018-03-08 06:44:42 UTC (rev 229397)
@@ -72,7 +72,7 @@
         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>

Modified: trunk/Source/WTF/wtf/UniqueArray.h (229396 => 229397)


--- trunk/Source/WTF/wtf/UniqueArray.h	2018-03-08 06:37:41 UTC (rev 229396)
+++ trunk/Source/WTF/wtf/UniqueArray.h	2018-03-08 06:44:42 UTC (rev 229397)
@@ -50,7 +50,7 @@
         // 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);
     }
 };

Modified: trunk/Source/WTF/wtf/Vector.h (229396 => 229397)


--- trunk/Source/WTF/wtf/Vector.h	2018-03-08 06:37:41 UTC (rev 229396)
+++ trunk/Source/WTF/wtf/Vector.h	2018-03-08 06:44:42 UTC (rev 229397)
@@ -68,11 +68,11 @@
 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);
     }
 };
 
@@ -79,15 +79,15 @@
 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);
     }
 };
 
@@ -94,14 +94,14 @@
 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 @@
         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 @@
         asanSetInitialBufferSizeTo(size);
 
         if (begin())
-            TypeOperations::initialize(begin(), end());
+            TypeOperations::initializeIfNonPOD(begin(), end());
     }
 
     Vector(size_t size, const T& val)
@@ -1107,7 +1107,7 @@
             expandCapacity(size);
         asanBufferSizeWillChangeTo(size);
         if (begin())
-            TypeOperations::initialize(end(), begin() + size);
+            TypeOperations::initializeIfNonPOD(end(), begin() + size);
     }
     
     m_size = size;
@@ -1137,7 +1137,7 @@
         expandCapacity(size);
     asanBufferSizeWillChangeTo(size);
     if (begin())
-        TypeOperations::initialize(end(), begin() + size);
+        TypeOperations::initializeIfNonPOD(end(), begin() + size);
     m_size = size;
 }
 

Modified: trunk/Source/WTF/wtf/VectorTraits.h (229396 => 229397)


--- trunk/Source/WTF/wtf/VectorTraits.h	2018-03-08 06:37:41 UTC (rev 229396)
+++ trunk/Source/WTF/wtf/VectorTraits.h	2018-03-08 06:44:42 UTC (rev 229397)
@@ -49,7 +49,7 @@
     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;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to