Changeset 225362 in webkit


Ignore:
Timestamp:
Nov 30, 2017, 3:44:24 PM (8 years ago)
Author:
Yusuke Suzuki
Message:

[JSC] Remove easy toRemove & map.remove() use
https://bugs.webkit.org/show_bug.cgi?id=180208

Reviewed by Mark Lam.

Source/JavaScriptCore:

In this patch, we replace Vector<> toRemove & map.remove loop with removeIf,
to optimize this common pattern. This patch only modifies apparent ones.
But we can apply this refactoring further to OAS phase in the future.

  • b3/B3MoveConstants.cpp:
  • dfg/DFGArgumentsEliminationPhase.cpp:
  • dfg/DFGObjectAllocationSinkingPhase.cpp:
  • wasm/WasmSignature.cpp:

(JSC::Wasm::SignatureInformation::tryCleanup):

Source/WTF:

Return bool from removeIf. It is true if removeIf removes at least one entry.
This interface is similar to existing HashSet::remove, which returns true
if it actually removes entry.

  • wtf/HashMap.h:

(WTF::X>::removeIf):

  • wtf/HashSet.h:

(WTF::V>::removeIf):

  • wtf/HashTable.h:

(WTF::KeyTraits>::removeIf):

Location:
trunk/Source
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r225360 r225362  
     12017-11-30  Yusuke Suzuki  <[email protected]>
     2
     3        [JSC] Remove easy toRemove & map.remove() use
     4        https://bugs.webkit.org/show_bug.cgi?id=180208
     5
     6        Reviewed by Mark Lam.
     7
     8        In this patch, we replace Vector<> toRemove & map.remove loop with removeIf,
     9        to optimize this common pattern. This patch only modifies apparent ones.
     10        But we can apply this refactoring further to OAS phase in the future.
     11
     12        * b3/B3MoveConstants.cpp:
     13        * dfg/DFGArgumentsEliminationPhase.cpp:
     14        * dfg/DFGObjectAllocationSinkingPhase.cpp:
     15        * wasm/WasmSignature.cpp:
     16        (JSC::Wasm::SignatureInformation::tryCleanup):
     17
    1182017-11-29  Yusuke Suzuki  <[email protected]>
    219
  • trunk/Source/JavaScriptCore/b3/B3MoveConstants.cpp

    r219027 r225362  
    343343
    344344    Procedure& m_proc;
    345     Vector<Value*> m_toRemove;
    346345    HashMap<ValueKey, unsigned> m_constTable;
    347346    int64_t* m_dataSection;
    348     HashMap<ValueKey, Value*> m_constants;
    349347    InsertionSet m_insertionSet;
    350348};
  • trunk/Source/JavaScriptCore/dfg/DFGArgumentsEliminationPhase.cpp

    r225307 r225362  
    193193        bool changed;
    194194        do {
    195             changed = false;
    196             Vector<Node*, 1> toRemove;
    197 
    198             for (Node* candidate : m_candidates) {
    199                 if (!isStillValidCandidate(candidate))
    200                     toRemove.append(candidate);
    201             }
    202 
    203             if (toRemove.size()) {
    204                 changed = true;
    205                 for (Node* node : toRemove)
    206                     m_candidates.remove(node);
    207             }
    208 
     195            changed = m_candidates.removeIf(
     196                [&] (Node* candidate) {
     197                    return !isStillValidCandidate(candidate);
     198                });
    209199        } while (changed);
    210200    }
  • trunk/Source/JavaScriptCore/dfg/DFGObjectAllocationSinkingPhase.cpp

    r221954 r225362  
    508508    void pruneByLiveness(const NodeSet& live)
    509509    {
    510         Vector<Node*> toRemove;
    511         for (const auto& entry : m_pointers) {
    512             if (!live.contains(entry.key))
    513                 toRemove.append(entry.key);
    514         }
    515         for (Node* node : toRemove)
    516             m_pointers.remove(node);
    517 
     510        m_pointers.removeIf(
     511            [&] (const auto& entry) {
     512                return !live.contains(entry.key);
     513            });
    518514        prune();
    519515    }
     
    683679
    684680        // Remove unreachable allocations
    685         {
    686             Vector<Node*> toRemove;
    687             for (const auto& entry : m_allocations) {
    688                 if (!reachable.contains(entry.key))
    689                     toRemove.append(entry.key);
    690             }
    691             for (Node* identifier : toRemove)
    692                 m_allocations.remove(identifier);
    693         }
     681        m_allocations.removeIf(
     682            [&] (const auto& entry) {
     683                return !reachable.contains(entry.key);
     684            });
    694685    }
    695686
     
    12501241        // We don't create materializations if the escapee is not a
    12511242        // sink candidate
    1252         Vector<Node*> toRemove;
    1253         for (const auto& entry : escapees) {
    1254             if (!m_sinkCandidates.contains(entry.key))
    1255                 toRemove.append(entry.key);
    1256         }
    1257         for (Node* identifier : toRemove)
    1258             escapees.remove(identifier);
    1259 
     1243        escapees.removeIf(
     1244            [&] (const auto& entry) {
     1245                return !m_sinkCandidates.contains(entry.key);
     1246            });
    12601247        if (escapees.isEmpty())
    12611248            return;
  • trunk/Source/JavaScriptCore/wasm/WasmSignature.cpp

    r223738 r225362  
    145145    LockHolder lock(info.m_lock);
    146146
    147     Vector<std::pair<SignatureIndex, Signature*>> toRemove;
    148     for (const auto& pair : info.m_indexMap) {
    149         const Ref<Signature>& signature = pair.value;
    150         if (signature->refCount() == 1) {
    151             // We're the only owner.
    152             toRemove.append(std::make_pair(pair.key, signature.ptr()));
    153         }
    154     }
    155     for (const auto& pair : toRemove) {
    156         bool removed = info.m_signatureMap.remove(SignatureHash { pair.second });
    157         ASSERT_UNUSED(removed, removed);
    158         removed = info.m_indexMap.remove(pair.first);
    159         ASSERT_UNUSED(removed, removed);
    160     }
     147    info.m_indexMap.removeIf(
     148        [&] (const auto& pair) {
     149            const Ref<Signature>& signature = pair.value;
     150            if (signature->refCount() == 1) {
     151                // We're the only owner.
     152                bool removed = info.m_signatureMap.remove(SignatureHash { signature.ptr() });
     153                ASSERT_UNUSED(removed, removed);
     154                return true;
     155            }
     156            return false;
     157        });
     158
    161159    if (info.m_signatureMap.isEmpty()) {
    162160        ASSERT(info.m_indexMap.isEmpty());
  • trunk/Source/WTF/ChangeLog

    r225341 r225362  
     12017-11-30  Yusuke Suzuki  <[email protected]>
     2
     3        [JSC] Remove easy toRemove & map.remove() use
     4        https://bugs.webkit.org/show_bug.cgi?id=180208
     5
     6        Reviewed by Mark Lam.
     7
     8        Return bool from removeIf. It is true if removeIf removes at least one entry.
     9        This interface is similar to existing HashSet::remove, which returns true
     10        if it actually removes entry.
     11
     12        * wtf/HashMap.h:
     13        (WTF::X>::removeIf):
     14        * wtf/HashSet.h:
     15        (WTF::V>::removeIf):
     16        * wtf/HashTable.h:
     17        (WTF::KeyTraits>::removeIf):
     18
    1192017-11-30  Chris Dumez  <[email protected]>
    220
  • trunk/Source/WTF/wtf/HashMap.h

    r223617 r225362  
    136136    bool remove(iterator);
    137137    template<typename Functor>
    138     void removeIf(Functor&&);
     138    bool removeIf(Functor&&);
    139139    void clear();
    140140
     
    444444template<typename T, typename U, typename V, typename W, typename X>
    445445template<typename Functor>
    446 inline void HashMap<T, U, V, W, X>::removeIf(Functor&& functor)
    447 {
    448     m_impl.removeIf(std::forward<Functor>(functor));
     446inline bool HashMap<T, U, V, W, X>::removeIf(Functor&& functor)
     447{
     448    return m_impl.removeIf(std::forward<Functor>(functor));
    449449}
    450450
  • trunk/Source/WTF/wtf/HashSet.h

    r223617 r225362  
    106106    bool remove(iterator);
    107107    template<typename Functor>
    108     void removeIf(const Functor&);
     108    bool removeIf(const Functor&);
    109109    void clear();
    110110
     
    276276template<typename T, typename U, typename V>
    277277template<typename Functor>
    278 inline void HashSet<T, U, V>::removeIf(const Functor& functor)
    279 {
    280     m_impl.removeIf(functor);
     278inline bool HashSet<T, U, V>::removeIf(const Functor& functor)
     279{
     280    return m_impl.removeIf(functor);
    281281}
    282282
  • trunk/Source/WTF/wtf/HashTable.h

    r223617 r225362  
    406406        void removeWithoutEntryConsistencyCheck(const_iterator);
    407407        template<typename Functor>
    408         void removeIf(const Functor&);
     408        bool removeIf(const Functor&);
    409409        void clear();
    410410
     
    11091109    template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>
    11101110    template<typename Functor>
    1111     inline void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::removeIf(const Functor& functor)
     1111    inline bool HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::removeIf(const Functor& functor)
    11121112    {
    11131113        // We must use local copies in case "functor" or "deleteBucket"
     
    11351135       
    11361136        internalCheckTableConsistency();
     1137        return removedBucketCount;
    11371138    }
    11381139
Note: See TracChangeset for help on using the changeset viewer.