Title: [156304] trunk/Source/WTF
Revision
156304
Author
[email protected]
Date
2013-09-23 15:39:35 -0700 (Mon, 23 Sep 2013)

Log Message

Add hash traits for std::unique_ptr
https://bugs.webkit.org/show_bug.cgi?id=121807

Reviewed by Antti Koivisto.

Also, convert the thread map over to using std::unique_ptr instead of OwnPtr.

* wtf/HashMap.h:
Remove unnecessary typedefs and add missing calls to std::forward.

* wtf/HashTraits.h:
Add hash trait for std::unique_ptr.

* wtf/RefPtrHashMap.h:
Use std::add_lvalue_reference.

* wtf/ThreadingPthreads.cpp:
(WTF::establishIdentifierForPthreadHandle):
Change ThreadMap to be a hash map from ThreadIdentifier to std::unique_ptr<PthreadState>.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (156303 => 156304)


--- trunk/Source/WTF/ChangeLog	2013-09-23 22:35:46 UTC (rev 156303)
+++ trunk/Source/WTF/ChangeLog	2013-09-23 22:39:35 UTC (rev 156304)
@@ -1,3 +1,25 @@
+2013-09-23  Anders Carlsson  <[email protected]>
+
+        Add hash traits for std::unique_ptr
+        https://bugs.webkit.org/show_bug.cgi?id=121807
+
+        Reviewed by Antti Koivisto.
+
+        Also, convert the thread map over to using std::unique_ptr instead of OwnPtr.
+
+        * wtf/HashMap.h:
+        Remove unnecessary typedefs and add missing calls to std::forward.
+
+        * wtf/HashTraits.h:
+        Add hash trait for std::unique_ptr.
+        
+        * wtf/RefPtrHashMap.h:
+        Use std::add_lvalue_reference.
+
+        * wtf/ThreadingPthreads.cpp:
+        (WTF::establishIdentifierForPthreadHandle):
+        Change ThreadMap to be a hash map from ThreadIdentifier to std::unique_ptr<PthreadState>.
+
 2013-09-23  Patrick Gansterer  <[email protected]>
 
         use NOMINMAX instead of #define min min

Modified: trunk/Source/WTF/wtf/HashMap.h (156303 => 156304)


--- trunk/Source/WTF/wtf/HashMap.h	2013-09-23 22:35:46 UTC (rev 156303)
+++ trunk/Source/WTF/wtf/HashMap.h	2013-09-23 22:39:35 UTC (rev 156304)
@@ -27,13 +27,6 @@
 
     template<typename KeyTraits, typename MappedTraits> struct HashMapValueTraits;
 
-    template<typename T> struct ReferenceTypeMaker {
-        typedef T& ReferenceType;
-    };
-    template<typename T> struct ReferenceTypeMaker<T&> {
-        typedef T& ReferenceType;
-    };
-
     template<typename T> struct KeyValuePairKeyExtractor {
         static const typename T::KeyType& extract(const T& p) { return p.key; }
     };
@@ -53,12 +46,8 @@
         typedef typename ValueTraits::TraitType ValueType;
 
     private:
-        typedef typename MappedTraits::PassInType MappedPassInType;
-        typedef typename MappedTraits::PassOutType MappedPassOutType;
         typedef typename MappedTraits::PeekType MappedPeekType;
 
-        typedef typename ReferenceTypeMaker<MappedPassInType>::ReferenceType MappedPassInReferenceType;
-
         typedef HashArg HashFunctions;
 
         typedef HashTable<KeyType, ValueType, KeyValuePairKeyExtractor<ValueType>,
@@ -383,14 +372,14 @@
     template<typename T>
     auto HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::add(const KeyType& key, T&& mapped) -> AddResult
     {
-        return inlineAdd(key, mapped);
+        return inlineAdd(key, std::forward<T>(mapped));
     }
 
     template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
     template<typename T>
     auto HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::add(KeyType&& key, T&& mapped) -> AddResult
     {
-        return inlineAdd(std::move(key), mapped);
+        return inlineAdd(std::move(key), std::forward<T>(mapped));
     }
 
     template<typename T, typename U, typename V, typename W, typename MappedTraits>

Modified: trunk/Source/WTF/wtf/HashTraits.h (156303 => 156304)


--- trunk/Source/WTF/wtf/HashTraits.h	2013-09-23 22:35:46 UTC (rev 156303)
+++ trunk/Source/WTF/wtf/HashTraits.h	2013-09-23 22:39:35 UTC (rev 156304)
@@ -121,24 +121,25 @@
         static bool isDeletedValue(const T& value) { return value.isHashTableDeletedValue(); }
     };
 
-    template<typename P> struct HashTraits<OwnPtr<P> > : SimpleClassHashTraits<OwnPtr<P> > {
+    template<typename T, typename Deleter> struct HashTraits<std::unique_ptr<T, Deleter>> : SimpleClassHashTraits<std::unique_ptr<T>> {
         typedef std::nullptr_t EmptyValueType;
-
         static EmptyValueType emptyValue() { return nullptr; }
 
-        typedef PassOwnPtr<P> PassInType;
-        static void store(PassOwnPtr<P> value, OwnPtr<P>& storage) { storage = value; }
+        typedef T* PeekType;
+        static T* peek(const std::unique_ptr<T, Deleter>& value) { return value.get(); }
+        static T* peek(std::nullptr_t) { return nullptr; }
+    };
 
-        typedef PassOwnPtr<P> PassOutType;
-        static PassOwnPtr<P> passOut(OwnPtr<P>& value) { return value.release(); }
-        static PassOwnPtr<P> passOut(std::nullptr_t) { return nullptr; }
+    template<typename T> struct HashTraits<OwnPtr<T>> : SimpleClassHashTraits<OwnPtr<T>> {
+        typedef std::nullptr_t EmptyValueType;
+        static EmptyValueType emptyValue() { return nullptr; }
 
-        typedef typename OwnPtr<P>::PtrType PeekType;
-        static PeekType peek(const OwnPtr<P>& value) { return value.get(); }
-        static PeekType peek(std::nullptr_t) { return 0; }
+        typedef T* PeekType;
+        static T* peek(const OwnPtr<T>& value) { return value.get(); }
+        static T* peek(std::nullptr_t) { return nullptr; }
     };
 
-    template<typename P> struct HashTraits<RefPtr<P> > : SimpleClassHashTraits<RefPtr<P> > {
+    template<typename P> struct HashTraits<RefPtr<P>> : SimpleClassHashTraits<RefPtr<P>> {
         static P* emptyValue() { return 0; }
 
         typedef PassRefPtr<P> PassInType;
@@ -173,7 +174,7 @@
     }
 
     template<typename FirstTraitsArg, typename SecondTraitsArg>
-    struct PairHashTraits : GenericHashTraits<std::pair<typename FirstTraitsArg::TraitType, typename SecondTraitsArg::TraitType> > {
+    struct PairHashTraits : GenericHashTraits<std::pair<typename FirstTraitsArg::TraitType, typename SecondTraitsArg::TraitType>> {
         typedef FirstTraitsArg FirstTraits;
         typedef SecondTraitsArg SecondTraits;
         typedef std::pair<typename FirstTraits::TraitType, typename SecondTraits::TraitType> TraitType;
@@ -191,7 +192,7 @@
     };
 
     template<typename First, typename Second>
-    struct HashTraits<std::pair<First, Second> > : public PairHashTraits<HashTraits<First>, HashTraits<Second> > { };
+    struct HashTraits<std::pair<First, Second>> : public PairHashTraits<HashTraits<First>, HashTraits<Second>> { };
 
     template<typename KeyTypeArg, typename ValueTypeArg>
     struct KeyValuePair {
@@ -220,7 +221,7 @@
     };
 
     template<typename KeyTraitsArg, typename ValueTraitsArg>
-    struct KeyValuePairHashTraits : GenericHashTraits<KeyValuePair<typename KeyTraitsArg::TraitType, typename ValueTraitsArg::TraitType> > {
+    struct KeyValuePairHashTraits : GenericHashTraits<KeyValuePair<typename KeyTraitsArg::TraitType, typename ValueTraitsArg::TraitType>> {
         typedef KeyTraitsArg KeyTraits;
         typedef ValueTraitsArg ValueTraits;
         typedef KeyValuePair<typename KeyTraits::TraitType, typename ValueTraits::TraitType> TraitType;
@@ -238,7 +239,7 @@
     };
 
     template<typename Key, typename Value>
-    struct HashTraits<KeyValuePair<Key, Value> > : public KeyValuePairHashTraits<HashTraits<Key>, HashTraits<Value> > { };
+    struct HashTraits<KeyValuePair<Key, Value>> : public KeyValuePairHashTraits<HashTraits<Key>, HashTraits<Value>> { };
 
     template<typename T>
     struct NullableHashTraits : public HashTraits<T> {

Modified: trunk/Source/WTF/wtf/RefPtrHashMap.h (156303 => 156304)


--- trunk/Source/WTF/wtf/RefPtrHashMap.h	2013-09-23 22:35:46 UTC (rev 156303)
+++ trunk/Source/WTF/wtf/RefPtrHashMap.h	2013-09-23 22:39:35 UTC (rev 156304)
@@ -47,7 +47,7 @@
         typedef typename MappedTraits::PassOutType MappedPassOutType;
         typedef typename MappedTraits::PeekType MappedPeekType;
 
-        typedef typename ReferenceTypeMaker<MappedPassInType>::ReferenceType MappedPassInReferenceType;
+        typedef typename std::add_lvalue_reference<MappedPassInType>::type MappedPassInReferenceType;
         
         typedef HashArg HashFunctions;
 

Modified: trunk/Source/WTF/wtf/ThreadingPthreads.cpp (156303 => 156304)


--- trunk/Source/WTF/wtf/ThreadingPthreads.cpp	2013-09-23 22:35:46 UTC (rev 156303)
+++ trunk/Source/WTF/wtf/ThreadingPthreads.cpp	2013-09-23 22:39:35 UTC (rev 156304)
@@ -96,7 +96,7 @@
     pthread_t m_pthreadHandle;
 };
 
-typedef HashMap<ThreadIdentifier, OwnPtr<PthreadState> > ThreadMap;
+typedef HashMap<ThreadIdentifier, std::unique_ptr<PthreadState>> ThreadMap;
 
 static Mutex* atomicallyInitializedStaticMutex;
 
@@ -179,7 +179,7 @@
     ASSERT(!identifierByPthreadHandle(pthreadHandle));
     MutexLocker locker(threadMapMutex());
     static ThreadIdentifier identifierCount = 1;
-    threadMap().add(identifierCount, createOwned<PthreadState>(pthreadHandle).release());
+    threadMap().add(identifierCount, std::make_unique<PthreadState>(pthreadHandle));
     return identifierCount++;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to