Title: [155380] trunk/Source/WebCore
Revision
155380
Author
[email protected]
Date
2013-09-09 14:04:24 -0700 (Mon, 09 Sep 2013)

Log Message

Stop using WTF type traits in WebCore
https://bugs.webkit.org/show_bug.cgi?id=121042

Reviewed by Andreas Kling.

Replace uses of WTF type traits in CrossThreadCopier with a simpler solution
that uses std::is_convertible_to and some helpers.

* dom/CrossThreadTask.h:
* platform/CrossThreadCopier.h:
* platform/MainThreadTask.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (155379 => 155380)


--- trunk/Source/WebCore/ChangeLog	2013-09-09 20:30:01 UTC (rev 155379)
+++ trunk/Source/WebCore/ChangeLog	2013-09-09 21:04:24 UTC (rev 155380)
@@ -1,3 +1,17 @@
+2013-09-09  Anders Carlsson  <[email protected]>
+
+        Stop using WTF type traits in WebCore
+        https://bugs.webkit.org/show_bug.cgi?id=121042
+
+        Reviewed by Andreas Kling.
+
+        Replace uses of WTF type traits in CrossThreadCopier with a simpler solution
+        that uses std::is_convertible_to and some helpers.
+
+        * dom/CrossThreadTask.h:
+        * platform/CrossThreadCopier.h:
+        * platform/MainThreadTask.h:
+
 2013-09-06  Ryosuke Niwa  <[email protected]>
 
         Internals should always cause a layout before calling into TextIterator

Modified: trunk/Source/WebCore/dom/CrossThreadTask.h (155379 => 155380)


--- trunk/Source/WebCore/dom/CrossThreadTask.h	2013-09-09 20:30:01 UTC (rev 155379)
+++ trunk/Source/WebCore/dom/CrossThreadTask.h	2013-09-09 21:04:24 UTC (rev 155380)
@@ -36,7 +36,6 @@
 #include <memory>
 #include <wtf/PassOwnPtr.h>
 #include <wtf/PassRefPtr.h>
-#include <wtf/TypeTraits.h>
 
 namespace WebCore {
 

Modified: trunk/Source/WebCore/platform/CrossThreadCopier.h (155379 => 155380)


--- trunk/Source/WebCore/platform/CrossThreadCopier.h	2013-09-09 20:30:01 UTC (rev 155379)
+++ trunk/Source/WebCore/platform/CrossThreadCopier.h	2013-09-09 21:04:24 UTC (rev 155380)
@@ -37,7 +37,6 @@
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
 #include <wtf/Threading.h>
-#include <wtf/TypeTraits.h>
 
 namespace WebCore {
 
@@ -51,6 +50,31 @@
     struct CrossThreadResourceRequestData;
     struct ThreadableLoaderOptions;
 
+    struct CrossThreadCopierBaseHelper {
+        template<typename T> struct RemovePointer {
+            typedef T Type;
+        };
+        template<typename T> struct RemovePointer<T*> {
+            typedef T Type;
+        };
+
+        template<typename T> struct RemovePointer<RefPtr<T>> {
+            typedef T Type;
+        };
+
+        template<typename T> struct RemovePointer<PassRefPtr<T>> {
+            typedef T Type;
+        };
+
+        template<typename T> struct IsConvertibleToInteger {
+            static const bool value = std::is_integral<T>::value || std::is_convertible<T, long double>::value;
+        };
+
+        template<typename T> struct IsThreadSafeRefCountedPointer {
+            static const bool value = std::is_convertible<typename RemovePointer<T>::Type*, ThreadSafeRefCounted<typename RemovePointer<T>::Type>*>::value;
+        };
+    };
+
     template<typename T> struct CrossThreadCopierPassThrough {
         typedef T Type;
         static Type copy(const T& parameter)
@@ -78,16 +102,9 @@
 
     // Custom copy methods.
     template<typename T> struct CrossThreadCopierBase<false, true, T> {
-        typedef typename WTF::RemoveTemplate<T, RefPtr>::Type TypeWithoutRefPtr;
-        typedef typename WTF::RemoveTemplate<TypeWithoutRefPtr, PassRefPtr>::Type TypeWithoutPassRefPtr;
-        typedef typename WTF::RemovePointer<TypeWithoutPassRefPtr>::Type RefCountedType;
+        typedef typename CrossThreadCopierBaseHelper::RemovePointer<T>::Type RefCountedType;
+        static_assert(std::is_convertible<RefCountedType*, ThreadSafeRefCounted<RefCountedType>*>::value, "T is not convertible to ThreadSafeRefCounted!");
 
-        // Verify that only one of the above did a change.
-        COMPILE_ASSERT((WTF::IsSameType<RefPtr<RefCountedType>, T>::value
-                        || WTF::IsSameType<PassRefPtr<RefCountedType>, T>::value
-                        || WTF::IsSameType<RefCountedType*, T>::value),
-                       OnlyAllowOneTypeModification);
-
         typedef PassRefPtr<RefCountedType> Type;
         static Type copy(const T& refPtr)
         {
@@ -128,11 +145,8 @@
         static Type copy(const ResourceResponse&);
     };
 
-    template<typename T> struct CrossThreadCopier : public CrossThreadCopierBase<WTF::IsConvertibleToInteger<T>::value,
-                                                                                 WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type, ThreadSafeRefCounted>::value
-                                                                                     || WTF::IsSubclassOfTemplate<typename WTF::RemovePointer<T>::Type, ThreadSafeRefCounted>::value
-                                                                                     || WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, PassRefPtr>::Type, ThreadSafeRefCounted>::value,
-                                                                                 T> {
+    template<typename T>
+    struct CrossThreadCopier : public CrossThreadCopierBase<CrossThreadCopierBaseHelper::IsConvertibleToInteger<T>::value, CrossThreadCopierBaseHelper::IsThreadSafeRefCountedPointer<T>::value, T> {
     };
 
     template<typename T> struct AllowCrossThreadAccessWrapper {

Modified: trunk/Source/WebCore/platform/MainThreadTask.h (155379 => 155380)


--- trunk/Source/WebCore/platform/MainThreadTask.h	2013-09-09 20:30:01 UTC (rev 155379)
+++ trunk/Source/WebCore/platform/MainThreadTask.h	2013-09-09 21:04:24 UTC (rev 155380)
@@ -37,7 +37,6 @@
 #include <wtf/MainThread.h>
 #include <wtf/PassOwnPtr.h>
 #include <wtf/PassRefPtr.h>
-#include <wtf/TypeTraits.h>
 
 namespace WebCore {
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to