Changeset 167592 in webkit


Ignore:
Timestamp:
Apr 21, 2014 8:52:27 AM (10 years ago)
Author:
Darin Adler
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.
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r167577 r167592  
     12014-04-21  Darin Adler  <darin@apple.com>
     2
     3        Add HashSet::takeAny
     4        https://bugs.webkit.org/show_bug.cgi?id=131928
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        * wtf/HashSet.h: Added an overload of take that takes an iterator,
     9        and used it to implement both the existing take and new takeAny functions.
     10
    1112014-04-20  Andreas Kling  <akling@apple.com>
    212
  • trunk/Source/WTF/wtf/HashSet.h

    r161801 r167592  
    104104
    105105        ValueType take(const ValueType&);
     106        ValueType take(iterator);
     107        ValueType takeAny();
    106108
    107109        static bool isValidValue(const ValueType&);
     
    241243
    242244    template<typename T, typename U, typename V>
    243     auto HashSet<T, U, V>::take(const ValueType& value) -> ValueType
    244     {
    245         auto it = find(value);
     245    inline auto HashSet<T, U, V>::take(iterator it) -> ValueType
     246    {
    246247        if (it == end())
    247248            return ValueTraits::emptyValue();
     
    250251        remove(it);
    251252        return result;
     253    }
     254
     255    template<typename T, typename U, typename V>
     256    inline auto HashSet<T, U, V>::take(const ValueType& value) -> ValueType
     257    {
     258        return take(find(value));
     259    }
     260
     261    template<typename T, typename U, typename V>
     262    inline auto HashSet<T, U, V>::takeAny() -> ValueType
     263    {
     264        return take(begin());
    252265    }
    253266
  • trunk/Source/WebCore/ChangeLog

    r167590 r167592  
     12014-04-21  Darin Adler  <darin@apple.com>
     2
     3        Add HashSet::takeAny
     4        https://bugs.webkit.org/show_bug.cgi?id=131928
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        * dom/Document.cpp:
     9        (WebCore::Document::takeAnyMediaCanStartListener): Use HashSet::takeAny.
     10        * dom/ScriptExecutionContext.cpp:
     11        (WebCore::takeAny): Deleted.
     12        (WebCore::ScriptExecutionContext::~ScriptExecutionContext): Use HashSet::takeAny.
     13
    1142014-04-21  Zan Dobersek  <zdobersek@igalia.com>
    215
  • trunk/Source/WebCore/dom/Document.cpp

    r167497 r167592  
    50865086MediaCanStartListener* Document::takeAnyMediaCanStartListener()
    50875087{
    5088     HashSet<MediaCanStartListener*>::iterator slot = m_mediaCanStartListeners.begin();
    5089     if (slot == m_mediaCanStartListeners.end())
    5090         return nullptr;
    5091     MediaCanStartListener* listener = *slot;
    5092     m_mediaCanStartListeners.remove(slot);
    5093     return listener;
     5088    return m_mediaCanStartListeners.takeAny();
    50945089}
    50955090
  • trunk/Source/WebCore/dom/ScriptExecutionContext.cpp

    r167579 r167592  
    106106}
    107107
    108 // FIXME: We should make this a member function of HashSet.
    109 template<typename T> inline T takeAny(HashSet<T>& set)
    110 {
    111     ASSERT(!set.isEmpty());
    112     auto iterator = set.begin();
    113     T result = std::move(*iterator);
    114     set.remove(iterator);
    115     return result;
    116 }
    117 
    118108#if ASSERT_DISABLED
    119109
     
    148138#endif
    149139
    150     while (!m_destructionObservers.isEmpty())
    151         takeAny(m_destructionObservers)->contextDestroyed();
     140    while (auto* destructionObserver = m_destructionObservers.takeAny())
     141        destructionObserver->contextDestroyed();
    152142
    153143    for (auto* messagePort : m_messagePorts)
  • trunk/Tools/ChangeLog

    r167576 r167592  
     12014-04-21  Darin Adler  <darin@apple.com>
     2
     3        Add HashSet::takeAny
     4        https://bugs.webkit.org/show_bug.cgi?id=131928
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        * TestWebKitAPI/Tests/WTF/HashSet.cpp: Added a test for takeAny.
     9
    1102014-04-20  Dan Bernstein  <mitz@apple.com>
    211
  • trunk/Tools/TestWebKitAPI/Tests/WTF/HashSet.cpp

    r155580 r167592  
    102102        EXPECT_TRUE(hashSet.take(MoveOnly(i + 1)) == MoveOnly(i + 1));
    103103
     104    EXPECT_TRUE(hashSet.isEmpty());
     105
     106    for (size_t i = 0; i < 100; ++i)
     107        hashSet.add(std::move(MoveOnly(i + 1)));
     108
     109    HashSet<MoveOnly> secondSet;
     110
     111    for (size_t i = 0; i < 100; ++i)
     112        secondSet.add(hashSet.takeAny());
     113
     114    EXPECT_TRUE(hashSet.isEmpty());
     115
     116    for (size_t i = 0; i < 100; ++i)
     117        EXPECT_TRUE(secondSet.contains(MoveOnly(i + 1)));
    104118}
    105119
Note: See TracChangeset for help on using the changeset viewer.