Title: [167592] trunk
Revision
167592
Author
[email protected]
Date
2014-04-21 08:52:27 -0700 (Mon, 21 Apr 2014)

Log Message

Add HashSet::takeAny
https://bugs.webkit.org/show_bug.cgi?id=131928

Reviewed by Benjamin Poulain.

Source/WebCore:
* dom/Document.cpp:
(WebCore::Document::takeAnyMediaCanStartListener): Use HashSet::takeAny.
* dom/ScriptExecutionContext.cpp:
(WebCore::takeAny): Deleted.
(WebCore::ScriptExecutionContext::~ScriptExecutionContext): Use HashSet::takeAny.

Source/WTF:
* wtf/HashSet.h: Added an overload of take that takes an iterator,
and used it to implement both the existing take and new takeAny functions.

Tools:
* TestWebKitAPI/Tests/WTF/HashSet.cpp: Added a test for takeAny.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (167591 => 167592)


--- trunk/Source/WTF/ChangeLog	2014-04-21 15:11:33 UTC (rev 167591)
+++ trunk/Source/WTF/ChangeLog	2014-04-21 15:52:27 UTC (rev 167592)
@@ -1,3 +1,13 @@
+2014-04-21  Darin Adler  <[email protected]>
+
+        Add HashSet::takeAny
+        https://bugs.webkit.org/show_bug.cgi?id=131928
+
+        Reviewed by Benjamin Poulain.
+
+        * wtf/HashSet.h: Added an overload of take that takes an iterator,
+        and used it to implement both the existing take and new takeAny functions.
+
 2014-04-20  Andreas Kling  <[email protected]>
 
         Speed up jsStringWithCache() through WeakGCMap inlining.

Modified: trunk/Source/WTF/wtf/HashSet.h (167591 => 167592)


--- trunk/Source/WTF/wtf/HashSet.h	2014-04-21 15:11:33 UTC (rev 167591)
+++ trunk/Source/WTF/wtf/HashSet.h	2014-04-21 15:52:27 UTC (rev 167592)
@@ -103,6 +103,8 @@
         void clear();
 
         ValueType take(const ValueType&);
+        ValueType take(iterator);
+        ValueType takeAny();
 
         static bool isValidValue(const ValueType&);
         
@@ -240,9 +242,8 @@
     }
 
     template<typename T, typename U, typename V>
-    auto HashSet<T, U, V>::take(const ValueType& value) -> ValueType
+    inline auto HashSet<T, U, V>::take(iterator it) -> ValueType
     {
-        auto it = find(value);
         if (it == end())
             return ValueTraits::emptyValue();
 
@@ -252,6 +253,18 @@
     }
 
     template<typename T, typename U, typename V>
+    inline auto HashSet<T, U, V>::take(const ValueType& value) -> ValueType
+    {
+        return take(find(value));
+    }
+
+    template<typename T, typename U, typename V>
+    inline auto HashSet<T, U, V>::takeAny() -> ValueType
+    {
+        return take(begin());
+    }
+
+    template<typename T, typename U, typename V>
     inline bool HashSet<T, U, V>::isValidValue(const ValueType& value)
     {
         if (ValueTraits::isDeletedValue(value))

Modified: trunk/Source/WebCore/ChangeLog (167591 => 167592)


--- trunk/Source/WebCore/ChangeLog	2014-04-21 15:11:33 UTC (rev 167591)
+++ trunk/Source/WebCore/ChangeLog	2014-04-21 15:52:27 UTC (rev 167592)
@@ -1,3 +1,16 @@
+2014-04-21  Darin Adler  <[email protected]>
+
+        Add HashSet::takeAny
+        https://bugs.webkit.org/show_bug.cgi?id=131928
+
+        Reviewed by Benjamin Poulain.
+
+        * dom/Document.cpp:
+        (WebCore::Document::takeAnyMediaCanStartListener): Use HashSet::takeAny.
+        * dom/ScriptExecutionContext.cpp:
+        (WebCore::takeAny): Deleted.
+        (WebCore::ScriptExecutionContext::~ScriptExecutionContext): Use HashSet::takeAny.
+
 2014-04-21  Zan Dobersek  <[email protected]>
 
         iOS and non-iOS RemoteCommandListener::create() functions should use std::make_unique<>()

Modified: trunk/Source/WebCore/dom/Document.cpp (167591 => 167592)


--- trunk/Source/WebCore/dom/Document.cpp	2014-04-21 15:11:33 UTC (rev 167591)
+++ trunk/Source/WebCore/dom/Document.cpp	2014-04-21 15:52:27 UTC (rev 167592)
@@ -5085,12 +5085,7 @@
 
 MediaCanStartListener* Document::takeAnyMediaCanStartListener()
 {
-    HashSet<MediaCanStartListener*>::iterator slot = m_mediaCanStartListeners.begin();
-    if (slot == m_mediaCanStartListeners.end())
-        return nullptr;
-    MediaCanStartListener* listener = *slot;
-    m_mediaCanStartListeners.remove(slot);
-    return listener;
+    return m_mediaCanStartListeners.takeAny();
 }
 
 #if ENABLE(DEVICE_ORIENTATION) && PLATFORM(IOS)

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.cpp (167591 => 167592)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2014-04-21 15:11:33 UTC (rev 167591)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2014-04-21 15:52:27 UTC (rev 167592)
@@ -105,16 +105,6 @@
 {
 }
 
-// FIXME: We should make this a member function of HashSet.
-template<typename T> inline T takeAny(HashSet<T>& set)
-{
-    ASSERT(!set.isEmpty());
-    auto iterator = set.begin();
-    T result = std::move(*iterator);
-    set.remove(iterator);
-    return result;
-}
-
 #if ASSERT_DISABLED
 
 inline void ScriptExecutionContext::checkConsistency() const
@@ -147,8 +137,8 @@
     m_inScriptExecutionContextDestructor = true;
 #endif
 
-    while (!m_destructionObservers.isEmpty())
-        takeAny(m_destructionObservers)->contextDestroyed();
+    while (auto* destructionObserver = m_destructionObservers.takeAny())
+        destructionObserver->contextDestroyed();
 
     for (auto* messagePort : m_messagePorts)
         messagePort->contextDestroyed();

Modified: trunk/Tools/ChangeLog (167591 => 167592)


--- trunk/Tools/ChangeLog	2014-04-21 15:11:33 UTC (rev 167591)
+++ trunk/Tools/ChangeLog	2014-04-21 15:52:27 UTC (rev 167592)
@@ -1,3 +1,12 @@
+2014-04-21  Darin Adler  <[email protected]>
+
+        Add HashSet::takeAny
+        https://bugs.webkit.org/show_bug.cgi?id=131928
+
+        Reviewed by Benjamin Poulain.
+
+        * TestWebKitAPI/Tests/WTF/HashSet.cpp: Added a test for takeAny.
+
 2014-04-20  Dan Bernstein  <[email protected]>
 
         Fixed a test timing out after r167572.

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/HashSet.cpp (167591 => 167592)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/HashSet.cpp	2014-04-21 15:11:33 UTC (rev 167591)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/HashSet.cpp	2014-04-21 15:52:27 UTC (rev 167592)
@@ -101,6 +101,20 @@
     for (size_t i = 0; i < 100; ++i)
         EXPECT_TRUE(hashSet.take(MoveOnly(i + 1)) == MoveOnly(i + 1));
 
+    EXPECT_TRUE(hashSet.isEmpty());
+
+    for (size_t i = 0; i < 100; ++i)
+        hashSet.add(std::move(MoveOnly(i + 1)));
+
+    HashSet<MoveOnly> secondSet;
+
+    for (size_t i = 0; i < 100; ++i)
+        secondSet.add(hashSet.takeAny());
+
+    EXPECT_TRUE(hashSet.isEmpty());
+
+    for (size_t i = 0; i < 100; ++i)
+        EXPECT_TRUE(secondSet.contains(MoveOnly(i + 1)));
 }
 
 } // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to