Changeset 154967 in webkit


Ignore:
Timestamp:
Sep 2, 2013 11:00:45 PM (11 years ago)
Author:
Darin Adler
Message:

Cut down on double hashing and code needlessly using hash table iterators
https://bugs.webkit.org/show_bug.cgi?id=120611

Reviewed by Andreas Kling.

Source/WebCore:

Some of these changes are primarily code cleanup, but others could provide
a small code size and speed improvement by avoiding extra hashing.

  • Modules/geolocation/Geolocation.cpp:

(WebCore::Geolocation::Watchers::find): Use get instead of find.
(WebCore::Geolocation::Watchers::remove): Use take instead of find.
(WebCore::Geolocation::makeCachedPositionCallbacks): Use the return
value from remove to avoid hashing twice.

  • Modules/webaudio/AudioContext.cpp:

(WebCore::AudioContext::addAutomaticPullNode): Use the return value from
add to avoid hashing twice.
(WebCore::AudioContext::removeAutomaticPullNode): Use the return value
from remove to avoid hashing twice.

  • Modules/webaudio/AudioNodeInput.cpp:

(WebCore::AudioNodeInput::connect): Use the return value from add to avoid
hashing twice.
(WebCore::AudioNodeInput::disconnect): Use the return value from remove
to avoid hashing twice.

  • Modules/webaudio/AudioParam.cpp:

(WebCore::AudioParam::connect): Use the return value from add to avoid
hashing twice.
(WebCore::AudioParam::disconnect): Use the return value from remove to
avoid hashing twice.

  • bridge/NP_jsobject.cpp:

(ObjectMap::remove): Use remove instead of find/remove.

  • dom/Node.cpp:

(WebCore::Node::~Node): Use the return value from remove instead of
find/remove.

  • inspector/InspectorProfilerAgent.cpp:

(WebCore::InspectorProfilerAgent::removeProfile): Remove needless
calls to contains.

  • loader/DocumentLoader.cpp:

(WebCore::DocumentLoader::removeSubresourceLoader): Use the return
value from remove instead of find/remove.

  • loader/ResourceLoadScheduler.cpp:

(WebCore::ResourceLoadScheduler::HostInformation::remove): Use the
return value from remove to avoid hashing twice.

  • loader/appcache/ApplicationCacheGroup.cpp:

(WebCore::ApplicationCacheGroup::disassociateDocumentLoader): Use
remove instead of find/remove.
(WebCore::ApplicationCacheGroup::cacheDestroyed): Removed a needless
call to contains to avoid hashing twice. It's fine to do the check
for an empty hash table unconditionally.

  • page/DOMWindow.cpp:

(WebCore::addUnloadEventListener): Eliminated a local variable for clarity.
(WebCore::removeUnloadEventListener): Ditto. Also use remove instead
of find/remove.
(WebCore::removeAllUnloadEventListeners): Ditto. Also use removeAll instead
of find/removeAll.
(WebCore::addBeforeUnloadEventListener): Ditto.
(WebCore::removeBeforeUnloadEventListener): Ditto.
(WebCore::removeAllBeforeUnloadEventListeners): Ditto.

  • page/FrameView.cpp:

(WebCore::FrameView::removeViewportConstrainedObject): Use the return
value from remove to avoid hashing twice.
(WebCore::FrameView::removeScrollableArea): Use the return value from
remove instead of find/remove.
(WebCore::FrameView::containsScrollableArea): Use && instead of an if
statement in a way that is idiomatic for this kind of function.

  • page/Page.cpp:

(WebCore::Page::addRelevantRepaintedObject): Use the return value from
remove instead of find/remove.

  • page/PageGroup.cpp:

(WebCore::PageGroup::removeUserScriptsFromWorld): Use remove instead
of find/remove.
(WebCore::PageGroup::removeUserStyleSheetsFromWorld): Use the return
value from remove instead of find/remove.

  • page/PerformanceUserTiming.cpp:

(WebCore::clearPeformanceEntries): Removed a needless call to contains.

  • platform/graphics/DisplayRefreshMonitor.cpp:

(WebCore::DisplayRefreshMonitor::removeClient): Use the return value
from remove instead of find/remove.
(WebCore::DisplayRefreshMonitorManager::displayDidRefresh): Use remove
instead of find/remove.

  • platform/graphics/blackberry/LayerRenderer.cpp:

(WebCore::LayerRenderer::removeLayer): Use the return value from remove
instead of find/remove.

  • platform/win/WindowMessageBroadcaster.cpp:

(WebCore::WindowMessageBroadcaster::removeListener): Use remove instead
of find/remove. It's fine to do the check for an empty hash table unconditionally.

  • plugins/PluginDatabase.cpp:

(WebCore::PluginDatabase::removeDisabledPluginFile): Use the return value
from remove instead of find/remove.

  • rendering/style/StyleCustomFilterProgramCache.cpp:

(WebCore::StyleCustomFilterProgramCache::lookup): Use get instead of find.
(WebCore::StyleCustomFilterProgramCache::add): Use contains instead of find
in an assertion.
(WebCore::StyleCustomFilterProgramCache::remove): Use remove instead of
find/remove.

  • svg/SVGCursorElement.cpp:

(WebCore::SVGCursorElement::removeClient): Use the return value from remove
instead of find/remove.

  • svg/SVGDocumentExtensions.cpp:

(WebCore::SVGDocumentExtensions::removeResource): Removed an unneeded call
to contains.
(WebCore::SVGDocumentExtensions::removeAllTargetReferencesForElement): Use
remove instead of find/remove. It's fine to do the check for an empty hash
table unconditionally.
(WebCore::SVGDocumentExtensions::removeAllElementReferencesForTarget): Use
remove instead of find/remove. Also removed unhelpful assertions. One is
already done by HashMap, and the other is just checking a basic invariant
of every HashMap that doesn't need to be checked.

  • svg/graphics/SVGImageCache.cpp:

(WebCore::SVGImageCache::removeClientFromCache): Removed an unneeded call
to contains.

  • svg/properties/SVGAnimatedProperty.cpp:

(WebCore::SVGAnimatedProperty::~SVGAnimatedProperty): Use the version of
remove that takes an iterator rather than the one that takes a key, so
we don't need to redo the hashing.

Source/WebKit2:

  • Platform/CoreIPC/Connection.cpp:

(CoreIPC::Connection::waitForMessage): Use take instead of find/remove.

  • UIProcess/WebPreferences.cpp:

(WebKit::WebPreferences::removePageGroup): Use the return value from remove
instead of find/remove.

  • WebProcess/Geolocation/GeolocationPermissionRequestManager.cpp:

(WebKit::GeolocationPermissionRequestManager::cancelRequestForGeolocation):
(WebKit::GeolocationPermissionRequestManager::didReceiveGeolocationPermissionDecision):
Use take instead of find/remove.

  • WebProcess/Plugins/Netscape/NetscapePlugin.cpp:

(WebKit::NetscapePlugin::frameDidFinishLoading): Use take instead of find/remove.
(WebKit::NetscapePlugin::frameDidFail): Use take instead of find/remove.

  • WebProcess/WebPage/WebBackForwardListProxy.cpp:

(WebKit::WebBackForwardListProxy::removeItem): Use take instead of find/remove.

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::didFinishCheckingText): Use take instead of get/remove so we
hash only once.
(WebKit::WebPage::didCancelCheckingText): Ditto.
(WebKit::WebPage::stopExtendingIncrementalRenderingSuppression): Use the return
value from remove instead of contains/remove so we hash only once.

Source/WTF:

Double hashing is common in code that needs to combine a remove with some
action to only be done if the code is removed. The only way to avoid it is
to write code using find and a hash table iterator. To help with this, add
a boolean return value to remove functions to indicate if anything was removed.

Double hashing also happens in code that does a get followed by a remove.
The take function is helpful in this case. To help with this, add a takeFirst
funciton to ListHashSet.

  • wtf/HashCountedSet.h:

(WTF::HashCountedSet::removeAll): Added a boolean return value, analogous to the one
that the HashCountedSet::remove function already has.

  • wtf/HashMap.h:

(WTF::HashMap::remove): Added a boolean return value, true if something was removed.

  • wtf/HashSet.h:

(WTF::HashSet::remove): Ditto.

  • wtf/RefPtrHashMap.h:

(WTF::RefPtrHashMap::remove): Ditto.

  • wtf/ListHashSet.h:

(WTF::ListHashSet::takeFirst): Added.
(WTF::ListHashSet::takeLast): Added.
(WTF::ListHashSet::remove): Added a boolean return value, true if something was removed.

  • wtf/WTFThreadData.h:

(JSC::IdentifierTable::remove): Use the new remove return value to get rid of most of
the code in this function.

Location:
trunk/Source
Files:
39 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r154966 r154967  
     12013-09-02  Darin Adler  <darin@apple.com>
     2
     3        Cut down on double hashing and code needlessly using hash table iterators
     4        https://bugs.webkit.org/show_bug.cgi?id=120611
     5
     6        Reviewed by Andreas Kling.
     7
     8        Double hashing is common in code that needs to combine a remove with some
     9        action to only be done if the code is removed. The only way to avoid it is
     10        to write code using find and a hash table iterator. To help with this, add
     11        a boolean return value to remove functions to indicate if anything was removed.
     12
     13        Double hashing also happens in code that does a get followed by a remove.
     14        The take function is helpful in this case. To help with this, add a takeFirst
     15        funciton to ListHashSet.
     16
     17        * wtf/HashCountedSet.h:
     18        (WTF::HashCountedSet::removeAll): Added a boolean return value, analogous to the one
     19        that the HashCountedSet::remove function already has.
     20
     21        * wtf/HashMap.h:
     22        (WTF::HashMap::remove): Added a boolean return value, true if something was removed.
     23        * wtf/HashSet.h:
     24        (WTF::HashSet::remove): Ditto.
     25        * wtf/RefPtrHashMap.h:
     26        (WTF::RefPtrHashMap::remove): Ditto.
     27
     28        * wtf/ListHashSet.h:
     29        (WTF::ListHashSet::takeFirst): Added.
     30        (WTF::ListHashSet::takeLast): Added.
     31        (WTF::ListHashSet::remove): Added a boolean return value, true if something was removed.
     32
     33        * wtf/WTFThreadData.h:
     34        (JSC::IdentifierTable::remove): Use the new remove return value to get rid of most of
     35        the code in this function.
     36
    1372013-09-02  David Kilzer  <ddkilzer@apple.com>
    238
  • trunk/Source/WTF/wtf/HashCountedSet.h

    r130612 r154967  
    11/*
    2  * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved.
     2 * Copyright (C) 2005, 2006, 2008, 2013 Apple Inc. All rights reserved.
    33 *
    44 * This library is free software; you can redistribute it and/or
     
    6969 
    7070        // Removes the value, regardless of its count.
    71         void removeAll(iterator);
    72         void removeAll(const ValueType&);
     71        bool removeAll(iterator);
     72        bool removeAll(const ValueType&);
    7373
    7474        // Clears the whole set.
     
    184184   
    185185    template<typename Value, typename HashFunctions, typename Traits>
    186     inline void HashCountedSet<Value, HashFunctions, Traits>::removeAll(const ValueType& value)
    187     {
    188         removeAll(find(value));
    189     }
    190    
    191     template<typename Value, typename HashFunctions, typename Traits>
    192     inline void HashCountedSet<Value, HashFunctions, Traits>::removeAll(iterator it)
     186    inline bool HashCountedSet<Value, HashFunctions, Traits>::removeAll(const ValueType& value)
     187    {
     188        return removeAll(find(value));
     189    }
     190   
     191    template<typename Value, typename HashFunctions, typename Traits>
     192    inline bool HashCountedSet<Value, HashFunctions, Traits>::removeAll(iterator it)
    193193    {
    194194        if (it == end())
    195             return;
     195            return false;
    196196
    197197        m_impl.remove(it);
     198        return true;
    198199    }
    199200   
  • trunk/Source/WTF/wtf/HashMap.h

    r151920 r154967  
    11/*
    2  * Copyright (C) 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2013 Apple Inc. All rights reserved.
    33 *
    44 * This library is free software; you can redistribute it and/or
     
    107107        AddResult add(const KeyType&, MappedPassInType);
    108108
    109         void remove(const KeyType&);
    110         void remove(iterator);
     109        bool remove(const KeyType&);
     110        bool remove(iterator);
    111111        void clear();
    112112
     
    381381
    382382    template<typename T, typename U, typename V, typename W, typename X>
    383     inline void HashMap<T, U, V, W, X>::remove(iterator it)
     383    inline bool HashMap<T, U, V, W, X>::remove(iterator it)
    384384    {
    385385        if (it.m_impl == m_impl.end())
    386             return;
     386            return false;
    387387        m_impl.internalCheckTableConsistency();
    388388        m_impl.removeWithoutEntryConsistencyCheck(it.m_impl);
    389     }
    390 
    391     template<typename T, typename U, typename V, typename W, typename X>
    392     inline void HashMap<T, U, V, W, X>::remove(const KeyType& key)
    393     {
    394         remove(find(key));
     389        return true;
     390    }
     391
     392    template<typename T, typename U, typename V, typename W, typename X>
     393    inline bool HashMap<T, U, V, W, X>::remove(const KeyType& key)
     394    {
     395        return remove(find(key));
    395396    }
    396397
  • trunk/Source/WTF/wtf/HashSet.h

    r153274 r154967  
    11/*
    2  * Copyright (C) 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2013 Apple Inc. All rights reserved.
    33 *
    44 * This library is free software; you can redistribute it and/or
     
    8989        bool add(IteratorType begin, IteratorType end);
    9090
    91         void remove(const ValueType&);
    92         void remove(iterator);
     91        bool remove(const ValueType&);
     92        bool remove(iterator);
    9393        void clear();
    9494
     
    205205
    206206    template<typename T, typename U, typename V>
    207     inline void HashSet<T, U, V>::remove(iterator it)
     207    inline bool HashSet<T, U, V>::remove(iterator it)
    208208    {
    209209        if (it.m_impl == m_impl.end())
    210             return;
     210            return false;
    211211        m_impl.internalCheckTableConsistency();
    212212        m_impl.removeWithoutEntryConsistencyCheck(it.m_impl);
    213     }
    214 
    215     template<typename T, typename U, typename V>
    216     inline void HashSet<T, U, V>::remove(const ValueType& value)
    217     {
    218         remove(find(value));
     213        return true;
     214    }
     215
     216    template<typename T, typename U, typename V>
     217    inline bool HashSet<T, U, V>::remove(const ValueType& value)
     218    {
     219        return remove(find(value));
    219220    }
    220221
  • trunk/Source/WTF/wtf/ListHashSet.h

    r148921 r154967  
    11/*
    2  * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012, 2013 Apple Inc. All rights reserved.
    33 * Copyright (C) 2011, Benjamin Poulain <ikipou@gmail.com>
    44 *
     
    108108        const ValueType& first() const;
    109109        void removeFirst();
     110        ValueType takeFirst();
    110111
    111112        ValueType& last();
    112113        const ValueType& last() const;
    113114        void removeLast();
     115        ValueType takeLast();
    114116
    115117        iterator find(const ValueType&);
     
    141143        AddResult insertBefore(iterator, const ValueType&);
    142144
    143         void remove(const ValueType&);
    144         void remove(iterator);
     145        bool remove(const ValueType&);
     146        bool remove(iterator);
    145147        void clear();
    146148
     
    630632
    631633    template<typename T, size_t inlineCapacity, typename U>
     634    inline T ListHashSet<T, inlineCapacity, U>::takeFirst()
     635    {
     636        T result = first();
     637        removeFirst();
     638        return result;
     639    }
     640
     641    template<typename T, size_t inlineCapacity, typename U>
    632642    inline const T& ListHashSet<T, inlineCapacity, U>::first() const
    633643    {
     
    656666        m_impl.remove(m_tail);
    657667        unlinkAndDelete(m_tail);
     668    }
     669
     670    template<typename T, size_t inlineCapacity, typename U>
     671    inline T ListHashSet<T, inlineCapacity, U>::takeLast()
     672    {
     673        T result = last();
     674        removeLast();
     675        return result;
    658676    }
    659677
     
    762780
    763781    template<typename T, size_t inlineCapacity, typename U>
    764     inline void ListHashSet<T, inlineCapacity, U>::remove(iterator it)
     782    inline bool ListHashSet<T, inlineCapacity, U>::remove(iterator it)
    765783    {
    766784        if (it == end())
    767             return;
     785            return false;
    768786        m_impl.remove(it.node());
    769787        unlinkAndDelete(it.node());
    770     }
    771 
    772     template<typename T, size_t inlineCapacity, typename U>
    773     inline void ListHashSet<T, inlineCapacity, U>::remove(const ValueType& value)
    774     {
    775         remove(find(value));
     788        return true;
     789    }
     790
     791    template<typename T, size_t inlineCapacity, typename U>
     792    inline bool ListHashSet<T, inlineCapacity, U>::remove(const ValueType& value)
     793    {
     794        return remove(find(value));
    776795    }
    777796
  • trunk/Source/WTF/wtf/RefPtrHashMap.h

    r130612 r154967  
    11/*
    2  * Copyright (C) 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2013 Apple Inc. All rights reserved.
    33 *
    44 * This library is free software; you can redistribute it and/or
     
    9797        AddResult add(RawKeyType, MappedPassInType);
    9898
    99         void remove(const KeyType&);
    100         void remove(RawKeyType);
    101         void remove(iterator);
     99        bool remove(const KeyType&);
     100        bool remove(RawKeyType);
     101        bool remove(iterator);
    102102        void clear();
    103103
     
    276276
    277277    template<typename T, typename U, typename V, typename W, typename X>
    278     inline void HashMap<RefPtr<T>, U, V, W, X>::remove(iterator it)
     278    inline bool HashMap<RefPtr<T>, U, V, W, X>::remove(iterator it)
    279279    {
    280280        if (it.m_impl == m_impl.end())
    281             return;
     281            return false;
    282282        m_impl.internalCheckTableConsistency();
    283283        m_impl.removeWithoutEntryConsistencyCheck(it.m_impl);
    284     }
    285 
    286     template<typename T, typename U, typename V, typename W, typename X>
    287     inline void HashMap<RefPtr<T>, U, V, W, X>::remove(const KeyType& key)
    288     {
    289         remove(find(key));
    290     }
    291 
    292     template<typename T, typename U, typename V, typename W, typename X>
    293     inline void HashMap<RefPtr<T>, U, V, W, X>::remove(RawKeyType key)
    294     {
    295         remove(find(key));
     284        return true;
     285    }
     286
     287    template<typename T, typename U, typename V, typename W, typename X>
     288    inline bool HashMap<RefPtr<T>, U, V, W, X>::remove(const KeyType& key)
     289    {
     290        return remove(find(key));
     291    }
     292
     293    template<typename T, typename U, typename V, typename W, typename X>
     294    inline bool HashMap<RefPtr<T>, U, V, W, X>::remove(RawKeyType key)
     295    {
     296        return remove(find(key));
    296297    }
    297298
  • trunk/Source/WTF/wtf/WTFThreadData.h

    r151578 r154967  
    3737#include <wtf/Threading.h>
    3838
    39 // FIXME: This is a temporary layering violation while we move more string code to WTF.
     39// FIXME: This is a temporary layering violation until we move more of the string code from JavaScriptCore to WTF.
    4040namespace JSC {
    4141
     
    4545    WTF_EXPORT_PRIVATE ~IdentifierTable();
    4646
    47     WTF_EXPORT_PRIVATE HashSet<StringImpl*>::AddResult add(StringImpl* value);
    48     template<typename U, typename V>
    49     HashSet<StringImpl*>::AddResult add(U value);
     47    WTF_EXPORT_PRIVATE HashSet<StringImpl*>::AddResult add(StringImpl*);
     48    template<typename U, typename V> HashSet<StringImpl*>::AddResult add(U);
    5049
    51     bool remove(StringImpl* r)
    52     {
    53         HashSet<StringImpl*>::iterator iter = m_table.find(r);
    54         if (iter == m_table.end())
    55             return false;
    56         m_table.remove(iter);
    57         return true;
    58     }
     50    bool remove(StringImpl* identifier) { return m_table.remove(identifier); }
    5951
    6052private:
  • trunk/Source/WebCore/ChangeLog

    r154965 r154967  
     12013-09-02  Darin Adler  <darin@apple.com>
     2
     3        Cut down on double hashing and code needlessly using hash table iterators
     4        https://bugs.webkit.org/show_bug.cgi?id=120611
     5
     6        Reviewed by Andreas Kling.
     7
     8        Some of these changes are primarily code cleanup, but others could provide
     9        a small code size and speed improvement by avoiding extra hashing.
     10
     11        * Modules/geolocation/Geolocation.cpp:
     12        (WebCore::Geolocation::Watchers::find): Use get instead of find.
     13        (WebCore::Geolocation::Watchers::remove): Use take instead of find.
     14        (WebCore::Geolocation::makeCachedPositionCallbacks): Use the return
     15        value from remove to avoid hashing twice.
     16
     17        * Modules/webaudio/AudioContext.cpp:
     18        (WebCore::AudioContext::addAutomaticPullNode): Use the return value from
     19        add to avoid hashing twice.
     20        (WebCore::AudioContext::removeAutomaticPullNode): Use the return value
     21        from remove to avoid hashing twice.
     22
     23        * Modules/webaudio/AudioNodeInput.cpp:
     24        (WebCore::AudioNodeInput::connect): Use the return value from add to avoid
     25        hashing twice.
     26        (WebCore::AudioNodeInput::disconnect): Use the return value from remove
     27        to avoid hashing twice.
     28
     29        * Modules/webaudio/AudioParam.cpp:
     30        (WebCore::AudioParam::connect): Use the return value from add to avoid
     31        hashing twice.
     32        (WebCore::AudioParam::disconnect): Use the return value from remove to
     33        avoid hashing twice.
     34
     35        * bridge/NP_jsobject.cpp:
     36        (ObjectMap::remove): Use remove instead of find/remove.
     37
     38        * dom/Node.cpp:
     39        (WebCore::Node::~Node): Use the return value from remove instead of
     40        find/remove.
     41
     42        * inspector/InspectorProfilerAgent.cpp:
     43        (WebCore::InspectorProfilerAgent::removeProfile): Remove needless
     44        calls to contains.
     45
     46        * loader/DocumentLoader.cpp:
     47        (WebCore::DocumentLoader::removeSubresourceLoader): Use the return
     48        value from remove instead of find/remove.
     49
     50        * loader/ResourceLoadScheduler.cpp:
     51        (WebCore::ResourceLoadScheduler::HostInformation::remove): Use the
     52        return value from remove to avoid hashing twice.
     53
     54        * loader/appcache/ApplicationCacheGroup.cpp:
     55        (WebCore::ApplicationCacheGroup::disassociateDocumentLoader): Use
     56        remove instead of find/remove.
     57        (WebCore::ApplicationCacheGroup::cacheDestroyed): Removed a needless
     58        call to contains to avoid hashing twice. It's fine to do the check
     59        for an empty hash table unconditionally.
     60
     61        * page/DOMWindow.cpp:
     62        (WebCore::addUnloadEventListener): Eliminated a local variable for clarity.
     63        (WebCore::removeUnloadEventListener): Ditto. Also use remove instead
     64        of find/remove.
     65        (WebCore::removeAllUnloadEventListeners): Ditto. Also use removeAll instead
     66        of find/removeAll.
     67        (WebCore::addBeforeUnloadEventListener): Ditto.
     68        (WebCore::removeBeforeUnloadEventListener): Ditto.
     69        (WebCore::removeAllBeforeUnloadEventListeners): Ditto.
     70
     71        * page/FrameView.cpp:
     72        (WebCore::FrameView::removeViewportConstrainedObject): Use the return
     73        value from remove to avoid hashing twice.
     74        (WebCore::FrameView::removeScrollableArea): Use the return value from
     75        remove instead of find/remove.
     76        (WebCore::FrameView::containsScrollableArea): Use && instead of an if
     77        statement in a way that is idiomatic for this kind of function.
     78
     79        * page/Page.cpp:
     80        (WebCore::Page::addRelevantRepaintedObject): Use the return value from
     81        remove instead of find/remove.
     82
     83        * page/PageGroup.cpp:
     84        (WebCore::PageGroup::removeUserScriptsFromWorld): Use remove instead
     85        of find/remove.
     86        (WebCore::PageGroup::removeUserStyleSheetsFromWorld): Use the return
     87        value from remove instead of find/remove.
     88
     89        * page/PerformanceUserTiming.cpp:
     90        (WebCore::clearPeformanceEntries): Removed a needless call to contains.
     91
     92        * platform/graphics/DisplayRefreshMonitor.cpp:
     93        (WebCore::DisplayRefreshMonitor::removeClient): Use the return value
     94        from remove instead of find/remove.
     95        (WebCore::DisplayRefreshMonitorManager::displayDidRefresh): Use remove
     96        instead of find/remove.
     97
     98        * platform/graphics/blackberry/LayerRenderer.cpp:
     99        (WebCore::LayerRenderer::removeLayer): Use the return value from remove
     100        instead of find/remove.
     101
     102        * platform/win/WindowMessageBroadcaster.cpp:
     103        (WebCore::WindowMessageBroadcaster::removeListener): Use remove instead
     104        of find/remove. It's fine to do the check for an empty hash table unconditionally.
     105
     106        * plugins/PluginDatabase.cpp:
     107        (WebCore::PluginDatabase::removeDisabledPluginFile): Use the return value
     108        from remove instead of find/remove.
     109
     110        * rendering/style/StyleCustomFilterProgramCache.cpp:
     111        (WebCore::StyleCustomFilterProgramCache::lookup): Use get instead of find.
     112        (WebCore::StyleCustomFilterProgramCache::add): Use contains instead of find
     113        in an assertion.
     114        (WebCore::StyleCustomFilterProgramCache::remove): Use remove instead of
     115        find/remove.
     116
     117        * svg/SVGCursorElement.cpp:
     118        (WebCore::SVGCursorElement::removeClient): Use the return value from remove
     119        instead of find/remove.
     120
     121        * svg/SVGDocumentExtensions.cpp:
     122        (WebCore::SVGDocumentExtensions::removeResource): Removed an unneeded call
     123        to contains.
     124        (WebCore::SVGDocumentExtensions::removeAllTargetReferencesForElement): Use
     125        remove instead of find/remove. It's fine to do the check for an empty hash
     126        table unconditionally.
     127        (WebCore::SVGDocumentExtensions::removeAllElementReferencesForTarget): Use
     128        remove instead of find/remove. Also removed unhelpful assertions. One is
     129        already done by HashMap, and the other is just checking a basic invariant
     130        of every HashMap that doesn't need to be checked.
     131
     132        * svg/graphics/SVGImageCache.cpp:
     133        (WebCore::SVGImageCache::removeClientFromCache): Removed an unneeded call
     134        to contains.
     135
     136        * svg/properties/SVGAnimatedProperty.cpp:
     137        (WebCore::SVGAnimatedProperty::~SVGAnimatedProperty): Use the version of
     138        remove that takes an iterator rather than the one that takes a key, so
     139        we don't need to redo the hashing.
     140
    11412013-09-02  Andreas Kling  <akling@apple.com>
    2142
  • trunk/Source/WebCore/Modules/geolocation/Geolocation.cpp

    r154962 r154967  
    189189{
    190190    ASSERT(id > 0);
    191     IdToNotifierMap::iterator iter = m_idToNotifierMap.find(id);
    192     if (iter == m_idToNotifierMap.end())
    193         return 0;
    194     return iter->value.get();
     191    return m_idToNotifierMap.get(id);
    195192}
    196193
     
    198195{
    199196    ASSERT(id > 0);
    200     IdToNotifierMap::iterator iter = m_idToNotifierMap.find(id);
    201     if (iter == m_idToNotifierMap.end())
    202         return;
    203     m_notifierToIdMap.remove(iter->value);
    204     m_idToNotifierMap.remove(iter);
     197    if (auto notifier = m_idToNotifierMap.take(id))
     198        m_notifierToIdMap.remove(notifier);
    205199}
    206200
    207201void Geolocation::Watchers::remove(GeoNotifier* notifier)
    208202{
    209     NotifierToIdMap::iterator iter = m_notifierToIdMap.find(notifier);
    210     if (iter == m_notifierToIdMap.end())
    211         return;
    212     m_idToNotifierMap.remove(iter->value);
    213     m_notifierToIdMap.remove(iter);
     203    if (auto identifier = m_notifierToIdMap.take(notifier))
     204        m_idToNotifierMap.remove(identifier);
    214205}
    215206
     
    381372        // If this is a one-shot request, stop it. Otherwise, if the watch still
    382373        // exists, start the service to get updates.
    383         if (m_oneShots.contains(notifier))
    384             m_oneShots.remove(notifier);
    385         else if (m_watchers.contains(notifier)) {
     374        if (!m_oneShots.remove(notifier) && m_watchers.contains(notifier)) {
    386375            if (notifier->hasZeroTimeout() || startUpdating(notifier))
    387376                notifier->startTimerIfNeeded();
  • trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp

    r154962 r154967  
    913913    ASSERT(isGraphOwner());
    914914
    915     if (!m_automaticPullNodes.contains(node)) {
    916         m_automaticPullNodes.add(node);
     915    if (m_automaticPullNodes.add(node).isNewEntry)
    917916        m_automaticPullNodesNeedUpdating = true;
    918     }
    919917}
    920918
     
    923921    ASSERT(isGraphOwner());
    924922
    925     if (m_automaticPullNodes.contains(node)) {
    926         m_automaticPullNodes.remove(node);
     923    if (m_automaticPullNodes.remove(node))
    927924        m_automaticPullNodesNeedUpdating = true;
    928     }
    929925}
    930926
  • trunk/Source/WebCore/Modules/webaudio/AudioNodeInput.cpp

    r149817 r154967  
    5555
    5656    // Check if we're already connected to this output.
    57     if (m_outputs.contains(output))
     57    if (!m_outputs.add(output).isNewEntry)
    5858        return;
    5959       
    6060    output->addInput(this);
    61     m_outputs.add(output);
    6261    changedOutputs();
    6362
     
    7574
    7675    // First try to disconnect from "active" connections.
    77     if (m_outputs.contains(output)) {
    78         m_outputs.remove(output);
     76    if (m_outputs.remove(output)) {
    7977        changedOutputs();
    8078        output->removeInput(this);
     
    8482   
    8583    // Otherwise, try to disconnect from disabled connections.
    86     if (m_disabledOutputs.contains(output)) {
    87         m_disabledOutputs.remove(output);
     84    if (m_disabledOutputs.remove(output)) {
    8885        output->removeInput(this);
    8986        node()->deref(AudioNode::RefTypeConnection); // Note: it's important to return immediately after all deref() calls since the node may be deleted.
  • trunk/Source/WebCore/Modules/webaudio/AudioParam.cpp

    r149817 r154967  
    173173        return;
    174174
    175     if (m_outputs.contains(output))
     175    if (!m_outputs.add(output).isNewEntry)
    176176        return;
    177177
    178178    output->addParam(this);
    179     m_outputs.add(output);
    180179    changedOutputs();
    181180}
     
    189188        return;
    190189
    191     if (m_outputs.contains(output)) {
    192         m_outputs.remove(output);
     190    if (m_outputs.remove(output)) {
    193191        changedOutputs();
    194192        output->removeParam(this);
  • trunk/Source/WebCore/bridge/NP_jsobject.cpp

    r153145 r154967  
    7171    void remove(RootObject* rootObject)
    7272    {
    73         HashMap<RootObject*, JSToNPObjectMap>::iterator iter = m_map.find(rootObject);
    74         ASSERT(iter != m_map.end());
    75         m_map.remove(iter);
     73        ASSERT(m_map.contains(rootObject));
     74        m_map.remove(rootObject);
    7675    }
    7776
  • trunk/Source/WebCore/dom/Node.cpp

    r154962 r154967  
    337337{
    338338#ifndef NDEBUG
    339     HashSet<Node*>::iterator it = ignoreSet.find(this);
    340     if (it != ignoreSet.end())
    341         ignoreSet.remove(it);
    342     else
     339    if (ignoreSet.remove(this))
    343340        nodeCounter.decrement();
    344341#endif
  • trunk/Source/WebCore/inspector/InspectorProfilerAgent.cpp

    r154201 r154967  
    313313    unsigned uid = static_cast<unsigned>(rawUid);
    314314    if (type == CPUProfileType) {
    315         if (m_profiles.contains(uid))
    316             m_profiles.remove(uid);
     315        m_profiles.remove(uid);
    317316    } else if (type == HeapProfileType) {
    318         if (m_snapshots.contains(uid))
    319             m_snapshots.remove(uid);
     317        m_snapshots.remove(uid);
    320318    }
    321319}
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r154962 r154967  
    13121312void DocumentLoader::removeSubresourceLoader(ResourceLoader* loader)
    13131313{
    1314     ResourceLoaderSet::iterator it = m_subresourceLoaders.find(loader);
    1315     if (it == m_subresourceLoaders.end())
    1316         return;
    1317     m_subresourceLoaders.remove(it);
     1314    if (!m_subresourceLoaders.remove(loader))
     1315        return;
    13181316    checkLoadComplete();
    13191317    if (Frame* frame = m_frame)
  • trunk/Source/WebCore/loader/ResourceLoadScheduler.cpp

    r154449 r154967  
    279279void ResourceLoadScheduler::HostInformation::remove(ResourceLoader* resourceLoader)
    280280{
    281     if (m_requestsLoading.contains(resourceLoader)) {
    282         m_requestsLoading.remove(resourceLoader);
    283         return;
    284     }
     281    if (m_requestsLoading.remove(resourceLoader))
     282        return;
    285283   
    286284    for (int priority = ResourceLoadPriorityHighest; priority >= ResourceLoadPriorityLowest; --priority) { 
  • trunk/Source/WebCore/loader/appcache/ApplicationCacheGroup.cpp

    r154558 r154967  
    363363void ApplicationCacheGroup::disassociateDocumentLoader(DocumentLoader* loader)
    364364{
    365     HashSet<DocumentLoader*>::iterator it = m_associatedDocumentLoaders.find(loader);
    366     if (it != m_associatedDocumentLoaders.end())
    367         m_associatedDocumentLoaders.remove(it);
    368 
     365    m_associatedDocumentLoaders.remove(loader);
    369366    m_pendingMasterResourceLoaders.remove(loader);
    370367
     
    391388void ApplicationCacheGroup::cacheDestroyed(ApplicationCache* cache)
    392389{
    393     if (!m_caches.contains(cache))
    394         return;
    395    
    396390    m_caches.remove(cache);
    397 
    398391    if (m_caches.isEmpty()) {
    399392        ASSERT(m_associatedDocumentLoaders.isEmpty());
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r154962 r154967  
    176176static void addUnloadEventListener(DOMWindow* domWindow)
    177177{
    178     DOMWindowSet& set = windowsWithUnloadEventListeners();
    179     if (set.add(domWindow).isNewEntry)
     178    if (windowsWithUnloadEventListeners().add(domWindow).isNewEntry)
    180179        domWindow->disableSuddenTermination();
    181180}
     
    183182static void removeUnloadEventListener(DOMWindow* domWindow)
    184183{
    185     DOMWindowSet& set = windowsWithUnloadEventListeners();
    186     DOMWindowSet::iterator it = set.find(domWindow);
    187     if (set.remove(it))
     184    if (windowsWithUnloadEventListeners().remove(domWindow))
    188185        domWindow->enableSuddenTermination();
    189186}
     
    191188static void removeAllUnloadEventListeners(DOMWindow* domWindow)
    192189{
    193     DOMWindowSet& set = windowsWithUnloadEventListeners();
    194     DOMWindowSet::iterator it = set.find(domWindow);
    195     if (it == set.end())
    196         return;
    197     set.removeAll(it);
    198     domWindow->enableSuddenTermination();
     190    if (windowsWithUnloadEventListeners().removeAll(domWindow))
     191        domWindow->enableSuddenTermination();
    199192}
    200193
    201194static void addBeforeUnloadEventListener(DOMWindow* domWindow)
    202195{
    203     DOMWindowSet& set = windowsWithBeforeUnloadEventListeners();
    204     if (set.add(domWindow).isNewEntry)
     196    if (windowsWithBeforeUnloadEventListeners().add(domWindow).isNewEntry)
    205197        domWindow->disableSuddenTermination();
    206198}
     
    208200static void removeBeforeUnloadEventListener(DOMWindow* domWindow)
    209201{
    210     DOMWindowSet& set = windowsWithBeforeUnloadEventListeners();
    211     DOMWindowSet::iterator it = set.find(domWindow);
    212     if (set.remove(it))
     202    if (windowsWithBeforeUnloadEventListeners().remove(domWindow))
    213203        domWindow->enableSuddenTermination();
    214204}
     
    216206static void removeAllBeforeUnloadEventListeners(DOMWindow* domWindow)
    217207{
    218     DOMWindowSet& set = windowsWithBeforeUnloadEventListeners();
    219     DOMWindowSet::iterator it = set.find(domWindow);
    220     if (it == set.end())
    221         return;
    222     set.removeAll(it);
    223     domWindow->enableSuddenTermination();
     208    if (windowsWithBeforeUnloadEventListeners().removeAll(domWindow))
     209        domWindow->enableSuddenTermination();
    224210}
    225211
  • trunk/Source/WebCore/page/FrameView.cpp

    r154962 r154967  
    15631563void FrameView::removeViewportConstrainedObject(RenderObject* object)
    15641564{
    1565     if (m_viewportConstrainedObjects && m_viewportConstrainedObjects->contains(object)) {
    1566         m_viewportConstrainedObjects->remove(object);
     1565    if (m_viewportConstrainedObjects && m_viewportConstrainedObjects->remove(object)) {
    15671566        if (Page* page = frame().page()) {
    15681567            if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator())
     
    40614060bool FrameView::removeScrollableArea(ScrollableArea* scrollableArea)
    40624061{
    4063     if (!m_scrollableAreas)
    4064         return false;
    4065 
    4066     ScrollableAreaSet::iterator it = m_scrollableAreas->find(scrollableArea);
    4067     if (it == m_scrollableAreas->end())
    4068         return false;
    4069 
    4070     m_scrollableAreas->remove(it);
    4071     return true;
     4062    return m_scrollableAreas && m_scrollableAreas->remove(scrollableArea);
    40724063}
    40734064
    40744065bool FrameView::containsScrollableArea(ScrollableArea* scrollableArea) const
    40754066{
    4076     if (!m_scrollableAreas)
    4077         return false;
    4078     return m_scrollableAreas->contains(scrollableArea);
     4067    return m_scrollableAreas && m_scrollableAreas->contains(scrollableArea);
    40794068}
    40804069
  • trunk/Source/WebCore/page/Page.cpp

    r154795 r154967  
    14111411    // If this object was previously counted as an unpainted object, remove it from that HashSet
    14121412    // and corresponding Region. FIXME: This doesn't do the right thing if the objects overlap.
    1413     HashSet<RenderObject*>::iterator it = m_relevantUnpaintedRenderObjects.find(object);
    1414     if (it != m_relevantUnpaintedRenderObjects.end()) {
    1415         m_relevantUnpaintedRenderObjects.remove(it);
     1413    if (m_relevantUnpaintedRenderObjects.remove(object))
    14161414        m_relevantUnpaintedRegion.subtract(snappedPaintRect);
    1417     }
    14181415
    14191416    // Split the relevantRect into a top half and a bottom half. Making sure we have coverage in
  • trunk/Source/WebCore/page/PageGroup.cpp

    r154658 r154967  
    366366        return;
    367367
    368     UserScriptMap::iterator it = m_userScripts->find(world);
    369     if (it == m_userScripts->end())
    370         return;
    371        
    372     m_userScripts->remove(it);
     368    m_userScripts->remove(world);
    373369}
    374370
     
    379375    if (!m_userStyleSheets)
    380376        return;
    381    
    382     UserStyleSheetMap::iterator it = m_userStyleSheets->find(world);
    383     if (it == m_userStyleSheets->end())
    384         return;
    385    
    386     m_userStyleSheets->remove(it);
     377
     378    if (!m_userStyleSheets->remove(world))
     379        return;
    387380
    388381    invalidateInjectedStyleSheetCacheInAllFrames();
  • trunk/Source/WebCore/page/PerformanceUserTiming.cpp

    r149579 r154967  
    9696    }
    9797
    98     if (performanceEntryMap.contains(name))
    99         performanceEntryMap.remove(name);
     98    performanceEntryMap.remove(name);
    10099}
    101100
  • trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitor.cpp

    r154962 r154967  
    8383bool DisplayRefreshMonitor::removeClient(DisplayRefreshMonitorClient* client)
    8484{
    85     DisplayRefreshMonitorClientSet::iterator it = m_clients.find(client);
    86     if (it != m_clients.end()) {
    87         m_clients.remove(it);
    88         return true;
    89     }
    90     return false;
     85    return m_clients.remove(client);
    9186}
    9287
     
    180175{
    181176    if (monitor->shouldBeTerminated()) {
    182         DisplayRefreshMonitorMap::iterator it = m_monitors.find(monitor->displayID());
    183         ASSERT(it != m_monitors.end());
    184         m_monitors.remove(it);
     177        ASSERT(m_monitors.contains(monitor->displayID()));
     178        m_monitors.remove(monitor->displayID());
    185179    }
    186180}
  • trunk/Source/WebCore/platform/graphics/blackberry/LayerRenderer.cpp

    r154701 r154967  
    511511bool LayerRenderer::removeLayer(LayerCompositingThread* layer)
    512512{
    513     LayerSet::iterator iter = m_layers.find(layer);
    514     if (iter == m_layers.end())
    515         return false;
    516     m_layers.remove(layer);
    517     return true;
     513    return m_layers.remove(layer);
    518514}
    519515
  • trunk/Source/WebCore/platform/win/WindowMessageBroadcaster.cpp

    r34640 r154967  
    8686void WindowMessageBroadcaster::removeListener(WindowMessageListener* listener)
    8787{
    88     ListenerSet::iterator found = m_listeners.find(listener);
    89     if (found == m_listeners.end())
    90         return;
    91 
    92     m_listeners.remove(found);
    93 
     88    m_listeners.remove(listener);
    9489    if (m_listeners.isEmpty())
    9590        destroy();
  • trunk/Source/WebCore/plugins/PluginDatabase.cpp

    r149812 r154967  
    372372bool PluginDatabase::removeDisabledPluginFile(const String& fileName)
    373373{
    374     if (!m_disabledPluginFiles.contains(fileName))
    375         return false;
    376 
    377     m_disabledPluginFiles.remove(fileName);
    378     return true;
     374    return m_disabledPluginFiles.remove(fileName);
    379375}
    380376
  • trunk/Source/WebCore/rendering/style/StyleCustomFilterProgramCache.cpp

    r146529 r154967  
    5959StyleCustomFilterProgram* StyleCustomFilterProgramCache::lookup(const CustomFilterProgramInfo& programInfo) const
    6060{
    61     CacheMap::const_iterator iter = m_cache.find(programInfo);
    62     return iter != m_cache.end() ? iter->value : 0;
     61    return m_cache.get(programInfo);
    6362}
    6463
     
    7069void StyleCustomFilterProgramCache::add(StyleCustomFilterProgram* program)
    7170{
    72     CustomFilterProgramInfo key = programCacheKey(program);
    73     ASSERT(m_cache.find(key) == m_cache.end());
    74     m_cache.set(key, program);
     71    ASSERT(!m_cache.contains(programCacheKey(program)));
     72    m_cache.set(programCacheKey(program), program);
    7573    program->setCache(this);
    7674}
     
    7876void StyleCustomFilterProgramCache::remove(StyleCustomFilterProgram* program)
    7977{
    80     CacheMap::iterator iter = m_cache.find(programCacheKey(program));
    81     ASSERT(iter != m_cache.end());
    82     m_cache.remove(iter);
     78    ASSERT(m_cache.contains(programCacheKey(program)));
     79    m_cache.remove(programCacheKey(program));
    8380}
    84 
    8581
    8682} // namespace WebCore
    8783
    8884#endif // ENABLE(CSS_SHADERS)
    89 
  • trunk/Source/WebCore/svg/SVGCursorElement.cpp

    r154877 r154967  
    107107void SVGCursorElement::removeClient(SVGElement* element)
    108108{
    109     HashSet<SVGElement*>::iterator it = m_clients.find(element);
    110     if (it != m_clients.end()) {
    111         m_clients.remove(it);
     109    if (m_clients.remove(element))
    112110        element->cursorElementRemoved();
    113     }
    114111}
    115112
  • trunk/Source/WebCore/svg/SVGDocumentExtensions.cpp

    r145333 r154967  
    7676void SVGDocumentExtensions::removeResource(const AtomicString& id)
    7777{
    78     if (id.isEmpty() || !m_resources.contains(id))
     78    if (id.isEmpty())
    7979        return;
    8080
     
    323323    Vector<SVGElement*> toBeRemoved;
    324324
    325     HashMap<SVGElement*, OwnPtr<HashSet<SVGElement*> > >::iterator end = m_elementDependencies.end();
    326     for (HashMap<SVGElement*, OwnPtr<HashSet<SVGElement*> > >::iterator it = m_elementDependencies.begin(); it != end; ++it) {
     325    auto end = m_elementDependencies.end();
     326    for (auto it = m_elementDependencies.begin(); it != end; ++it) {
    327327        SVGElement* referencedElement = it->key;
    328         HashSet<SVGElement*>* referencingElements = it->value.get();
    329         HashSet<SVGElement*>::iterator setIt = referencingElements->find(referencingElement);
    330         if (setIt == referencingElements->end())
    331             continue;
    332 
    333         referencingElements->remove(setIt);
    334         if (referencingElements->isEmpty())
     328        HashSet<SVGElement*>& referencingElements = *it->value;
     329        referencingElements.remove(referencingElement);
     330        if (referencingElements.isEmpty())
    335331            toBeRemoved.append(referencedElement);
    336332    }
     
    368364void SVGDocumentExtensions::removeAllElementReferencesForTarget(SVGElement* referencedElement)
    369365{
    370     ASSERT(referencedElement);
    371     HashMap<SVGElement*, OwnPtr<HashSet<SVGElement*> > >::iterator it = m_elementDependencies.find(referencedElement);
    372     if (it == m_elementDependencies.end())
    373         return;
    374     ASSERT(it->key == referencedElement);
    375 
    376     m_elementDependencies.remove(it);
     366    m_elementDependencies.remove(referencedElement);
    377367}
    378368
  • trunk/Source/WebCore/svg/graphics/SVGImageCache.cpp

    r148175 r154967  
    4848    ASSERT(client);
    4949
    50     if (m_imageForContainerMap.contains(client))
    51         m_imageForContainerMap.remove(client);
     50    m_imageForContainerMap.remove(client);
    5251}
    5352
  • trunk/Source/WebCore/svg/properties/SVGAnimatedProperty.cpp

    r152553 r154967  
    4040{
    4141    // Remove wrapper from cache.
    42     Cache* cache = animatedPropertyCache();
    43     const Cache::const_iterator end = cache->end();
    44     for (Cache::const_iterator it = cache->begin(); it != end; ++it) {
     42    Cache& cache = *animatedPropertyCache();
     43    for (auto it = cache.begin(), end = cache.end(); it != end; ++it) {
    4544        if (it->value == this) {
    46             cache->remove(it->key);
     45            cache.remove(it);
    4746            break;
    4847        }
  • trunk/Source/WebKit2/ChangeLog

    r154963 r154967  
     12013-09-02  Darin Adler  <darin@apple.com>
     2
     3        Cut down on double hashing and code needlessly using hash table iterators
     4        https://bugs.webkit.org/show_bug.cgi?id=120611
     5
     6        Reviewed by Andreas Kling.
     7
     8        * Platform/CoreIPC/Connection.cpp:
     9        (CoreIPC::Connection::waitForMessage): Use take instead of find/remove.
     10
     11        * UIProcess/WebPreferences.cpp:
     12        (WebKit::WebPreferences::removePageGroup): Use the return value from remove
     13        instead of find/remove.
     14
     15        * WebProcess/Geolocation/GeolocationPermissionRequestManager.cpp:
     16        (WebKit::GeolocationPermissionRequestManager::cancelRequestForGeolocation):
     17        (WebKit::GeolocationPermissionRequestManager::didReceiveGeolocationPermissionDecision):
     18        Use take instead of find/remove.
     19
     20        * WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
     21        (WebKit::NetscapePlugin::frameDidFinishLoading): Use take instead of find/remove.
     22        (WebKit::NetscapePlugin::frameDidFail): Use take instead of find/remove.
     23
     24        * WebProcess/WebPage/WebBackForwardListProxy.cpp:
     25        (WebKit::WebBackForwardListProxy::removeItem): Use take instead of find/remove.
     26
     27        * WebProcess/WebPage/WebPage.cpp:
     28        (WebKit::WebPage::didFinishCheckingText): Use take instead of get/remove so we
     29        hash only once.
     30        (WebKit::WebPage::didCancelCheckingText): Ditto.
     31        (WebKit::WebPage::stopExtendingIncrementalRenderingSuppression): Use the return
     32        value from remove instead of contains/remove so we hash only once.
     33
    1342013-09-02  Darin Adler  <darin@apple.com>
    235
  • trunk/Source/WebKit2/Platform/CoreIPC/Connection.cpp

    r154073 r154967  
    418418        MutexLocker locker(m_waitForMessageMutex);
    419419
    420         HashMap<std::pair<std::pair<StringReference, StringReference>, uint64_t>, OwnPtr<MessageDecoder>>::iterator it = m_waitForMessageMap.find(messageAndDestination);
    421         if (it->value) {
    422             OwnPtr<MessageDecoder> decoder = it->value.release();
    423             m_waitForMessageMap.remove(it);
    424 
     420        if (OwnPtr<MessageDecoder> decoder = m_waitForMessageMap.take(messageAndDestination))
    425421            return decoder.release();
    426         }
    427422       
    428423        // Now we wait.
  • trunk/Source/WebKit2/UIProcess/WebPreferences.cpp

    r152273 r154967  
    7171void WebPreferences::removePageGroup(WebPageGroup* pageGroup)
    7272{
    73     HashSet<WebPageGroup*>::iterator iter = m_pageGroups.find(pageGroup);
    74     if (iter == m_pageGroups.end())
    75         return;
    76 
    77     m_pageGroups.remove(iter);
    78 
    79     if (privateBrowsingEnabled()) {
     73    bool didRemovePageGroup = m_pageGroups.remove(pageGroup);
     74    if (didRemovePageGroup && privateBrowsingEnabled()) {
    8075        --privateBrowsingPageGroupCount;
    8176        if (!privateBrowsingPageGroupCount)
  • trunk/Source/WebKit2/WebProcess/Geolocation/GeolocationPermissionRequestManager.cpp

    r154142 r154967  
    6060    m_idToGeolocationMap.set(geolocationID, geolocation);
    6161
    62 
    6362    Frame* frame = geolocation->frame();
    6463
     
    7473void GeolocationPermissionRequestManager::cancelRequestForGeolocation(Geolocation* geolocation)
    7574{
    76     GeolocationToIDMap::iterator it = m_geolocationToIDMap.find(geolocation);
    77     if (it == m_geolocationToIDMap.end())
     75    uint64_t geolocationID = m_geolocationToIDMap.take(geolocation);
     76    if (!geolocationID)
    7877        return;
    79 
    80     uint64_t geolocationID = it->value;
    81     m_geolocationToIDMap.remove(it);
    8278    m_idToGeolocationMap.remove(geolocationID);
    8379}
     
    8581void GeolocationPermissionRequestManager::didReceiveGeolocationPermissionDecision(uint64_t geolocationID, bool allowed)
    8682{
    87     IDToGeolocationMap::iterator it = m_idToGeolocationMap.find(geolocationID);
    88     if (it == m_idToGeolocationMap.end())
     83    Geolocation* geolocation = m_idToGeolocationMap.take(geolocationID);
     84    if (!geolocation)
    8985        return;
     86    m_geolocationToIDMap.remove(geolocation);
    9087
    91     Geolocation* geolocation = it->value;
    9288    geolocation->setIsAllowed(allowed);
    93 
    94     m_idToGeolocationMap.remove(it);
    95     m_geolocationToIDMap.remove(geolocation);
    9689}
    9790
  • trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp

    r149848 r154967  
    765765    ASSERT(m_isStarted);
    766766   
    767     PendingURLNotifyMap::iterator it = m_pendingURLNotifications.find(requestID);
    768     if (it == m_pendingURLNotifications.end())
     767    auto notification = m_pendingURLNotifications.take(requestID);
     768    if (notification.first.isEmpty())
    769769        return;
    770770
    771     String url = it->value.first;
    772     void* notificationData = it->value.second;
    773 
    774     m_pendingURLNotifications.remove(it);
    775    
    776     NPP_URLNotify(url.utf8().data(), NPRES_DONE, notificationData);
     771    NPP_URLNotify(notification.first.utf8().data(), NPRES_DONE, notification.second);
    777772}
    778773
     
    781776    ASSERT(m_isStarted);
    782777   
    783     PendingURLNotifyMap::iterator it = m_pendingURLNotifications.find(requestID);
    784     if (it == m_pendingURLNotifications.end())
     778    auto notification = m_pendingURLNotifications.take(requestID);
     779    if (notification.first.isNull())
    785780        return;
    786 
    787     String url = it->value.first;
    788     void* notificationData = it->value.second;
    789 
    790     m_pendingURLNotifications.remove(it);
    791    
    792     NPP_URLNotify(url.utf8().data(), wasCancelled ? NPRES_USER_BREAK : NPRES_NETWORK_ERR, notificationData);
     781   
     782    NPP_URLNotify(notification.first.utf8().data(), wasCancelled ? NPRES_USER_BREAK : NPRES_NETWORK_ERR, notification.second);
    793783}
    794784
  • trunk/Source/WebKit2/WebProcess/WebPage/WebBackForwardListProxy.cpp

    r150669 r154967  
    127127void WebBackForwardListProxy::removeItem(uint64_t itemID)
    128128{
    129     IDToHistoryItemMap::iterator it = idToHistoryItemMap().find(itemID);
    130     if (it == idToHistoryItemMap().end())
     129    RefPtr<HistoryItem> item = idToHistoryItemMap().take(itemID);
     130    if (!item)
    131131        return;
    132132       
    133     WebCore::pageCache()->remove(it->value.get());
    134 
    135     historyItemToIDMap().remove(it->value);
    136     idToHistoryItemMap().remove(it);
     133    pageCache()->remove(item.get());
     134    historyItemToIDMap().remove(item);
    137135}
    138136
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r154877 r154967  
    39583958void WebPage::didFinishCheckingText(uint64_t requestID, const Vector<TextCheckingResult>& result)
    39593959{
    3960     TextCheckingRequest* request = m_pendingTextCheckingRequestMap.get(requestID);
     3960    RefPtr<TextCheckingRequest> request = m_pendingTextCheckingRequestMap.take(requestID);
    39613961    if (!request)
    39623962        return;
    39633963
    39643964    request->didSucceed(result);
    3965     m_pendingTextCheckingRequestMap.remove(requestID);
    39663965}
    39673966
    39683967void WebPage::didCancelCheckingText(uint64_t requestID)
    39693968{
    3970     TextCheckingRequest* request = m_pendingTextCheckingRequestMap.get(requestID);
     3969    RefPtr<TextCheckingRequest> request = m_pendingTextCheckingRequestMap.take(requestID);
    39713970    if (!request)
    39723971        return;
    39733972
    39743973    request->didCancel();
    3975     m_pendingTextCheckingRequestMap.remove(requestID);
    39763974}
    39773975
     
    41834181void WebPage::stopExtendingIncrementalRenderingSuppression(unsigned token)
    41844182{
    4185     if (!m_activeRenderingSuppressionTokens.contains(token))
    4186         return;
    4187 
    4188     m_activeRenderingSuppressionTokens.remove(token);
     4183    if (!m_activeRenderingSuppressionTokens.remove(token))
     4184        return;
     4185
    41894186    m_page->mainFrame().view()->setVisualUpdatesAllowedByClient(!shouldExtendIncrementalRenderingSuppression());
    41904187}
Note: See TracChangeset for help on using the changeset viewer.