Title: [208600] trunk
Revision
208600
Author
[email protected]
Date
2016-11-11 11:11:28 -0800 (Fri, 11 Nov 2016)

Log Message

Allow mutable lambdas in HashMap::ensure
https://bugs.webkit.org/show_bug.cgi?id=164642

Reviewed by Sam Weinig.

Source/WTF:

* wtf/HashMap.h:
(WTF::HashMapEnsureTranslator::translate):
(WTF::X>::removeIf):

Tools:

* TestWebKitAPI/Tests/WTF/HashMap.cpp:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (208599 => 208600)


--- trunk/Source/WTF/ChangeLog	2016-11-11 19:09:01 UTC (rev 208599)
+++ trunk/Source/WTF/ChangeLog	2016-11-11 19:11:28 UTC (rev 208600)
@@ -1,3 +1,14 @@
+2016-11-11  Alex Christensen  <[email protected]>
+
+        Allow mutable lambdas in HashMap::ensure
+        https://bugs.webkit.org/show_bug.cgi?id=164642
+
+        Reviewed by Sam Weinig.
+
+        * wtf/HashMap.h:
+        (WTF::HashMapEnsureTranslator::translate):
+        (WTF::X>::removeIf):
+
 2016-11-11  Beth Dakin  <[email protected]>
 
         Get touch bar code building for open source builds

Modified: trunk/Source/WTF/wtf/HashMap.h (208599 => 208600)


--- trunk/Source/WTF/wtf/HashMap.h	2016-11-11 19:09:01 UTC (rev 208599)
+++ trunk/Source/WTF/wtf/HashMap.h	2016-11-11 19:11:28 UTC (rev 208600)
@@ -122,13 +122,13 @@
     template<typename V> AddResult fastAdd(const KeyType&, V&&);
     template<typename V> AddResult fastAdd(KeyType&&, V&&);
 
-    template<typename Functor> AddResult ensure(const KeyType&, const Functor&);
-    template<typename Functor> AddResult ensure(KeyType&&, const Functor&);
+    template<typename Functor> AddResult ensure(const KeyType&, Functor&&);
+    template<typename Functor> AddResult ensure(KeyType&&, Functor&&);
 
     bool remove(const KeyType&);
     bool remove(iterator);
     template<typename Functor>
-    void removeIf(const Functor& functor);
+    void removeIf(Functor&&);
     void clear();
 
     MappedTakeType take(const KeyType&); // efficient combination of get with remove
@@ -171,7 +171,7 @@
     AddResult inlineAdd(K&&, V&&);
 
     template<typename K, typename F>
-    AddResult inlineEnsure(K&&, const F&);
+    AddResult inlineEnsure(K&&, F&&);
 
     HashTableType m_impl;
 };
@@ -191,7 +191,7 @@
 struct HashMapEnsureTranslator {
     template<typename T> static unsigned hash(const T& key) { return HashFunctions::hash(key); }
     template<typename T, typename U> static bool equal(const T& a, const U& b) { return HashFunctions::equal(a, b); }
-    template<typename T, typename U, typename Functor> static void translate(T& location, U&& key, const Functor& functor)
+    template<typename T, typename U, typename Functor> static void translate(T& location, U&& key, Functor&& functor)
     {
         ValueTraits::KeyTraits::assignToEmpty(location.key, std::forward<U>(key));
         ValueTraits::ValueTraits::assignToEmpty(location.value, functor());
@@ -319,9 +319,9 @@
 
 template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
 template<typename K, typename F>
-ALWAYS_INLINE auto HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::inlineEnsure(K&& key, const F& functor) -> AddResult
+ALWAYS_INLINE auto HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::inlineEnsure(K&& key, F&& functor) -> AddResult
 {
-    return m_impl.template add<HashMapEnsureTranslator<KeyValuePairTraits, HashFunctions>>(std::forward<K>(key), functor);
+    return m_impl.template add<HashMapEnsureTranslator<KeyValuePairTraits, HashFunctions>>(std::forward<K>(key), std::forward<F>(functor));
 }
 
 template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
@@ -375,16 +375,16 @@
 
 template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
 template<typename Functor>
-auto HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::ensure(const KeyType& key, const Functor& functor) -> AddResult
+auto HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::ensure(const KeyType& key, Functor&& functor) -> AddResult
 {
-    return inlineEnsure(key, functor);
+    return inlineEnsure(key, std::forward<Functor>(functor));
 }
 
 template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
 template<typename Functor>
-auto HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::ensure(KeyType&& key, const Functor& functor) -> AddResult
+auto HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::ensure(KeyType&& key, Functor&& functor) -> AddResult
 {
-    return inlineEnsure(WTFMove(key), functor);
+    return inlineEnsure(std::forward<KeyType>(key), std::forward<Functor>(functor));
 }
     
 template<typename T, typename U, typename V, typename W, typename MappedTraits>
@@ -417,9 +417,9 @@
 
 template<typename T, typename U, typename V, typename W, typename X>
 template<typename Functor>
-inline void HashMap<T, U, V, W, X>::removeIf(const Functor& functor)
+inline void HashMap<T, U, V, W, X>::removeIf(Functor&& functor)
 {
-    m_impl.removeIf(functor);
+    m_impl.removeIf(std::forward<Functor>(functor));
 }
 
 template<typename T, typename U, typename V, typename W, typename X>

Modified: trunk/Tools/ChangeLog (208599 => 208600)


--- trunk/Tools/ChangeLog	2016-11-11 19:09:01 UTC (rev 208599)
+++ trunk/Tools/ChangeLog	2016-11-11 19:11:28 UTC (rev 208600)
@@ -1,3 +1,13 @@
+2016-11-11  Alex Christensen  <[email protected]>
+
+        Allow mutable lambdas in HashMap::ensure
+        https://bugs.webkit.org/show_bug.cgi?id=164642
+
+        Reviewed by Sam Weinig.
+
+        * TestWebKitAPI/Tests/WTF/HashMap.cpp:
+        (TestWebKitAPI::TEST):
+
 2016-11-11  Wenson Hsieh  <[email protected]>
 
         Composition state should be cleared when changing focus to a non-editable element

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp (208599 => 208600)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp	2016-11-11 19:09:01 UTC (rev 208599)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp	2016-11-11 19:11:28 UTC (rev 208600)
@@ -895,7 +895,7 @@
         HashMap<int, Ref<RefLogger>> map;
 
         RefLogger a("a");
-        map.ensure(1, [&]() { 
+        map.ensure(1, [&]() mutable {
             Ref<RefLogger> ref(a);
             return ref; 
         });
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to