Ignore:
Timestamp:
Nov 30, 2017, 5:02:47 PM (7 years ago)
Author:
Yusuke Suzuki
Message:

[JSC] Remove easy toRemove & map.remove() use in OAS phase
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.

One thing we should care is that predicate of removeIf should not touch the
removing set itself. In this patch, we apply this change to (1) apparently
correct one and (2) things in DFG OAS phase since it is very slow.

  • b3/B3MoveConstants.cpp:
  • dfg/DFGObjectAllocationSinkingPhase.cpp:

Source/WTF:

  • wtf/HashMap.h:

(WTF::X>::removeIf):

  • wtf/HashSet.h:

(WTF::V>::removeIf):

  • wtf/HashTable.h:

(WTF::KeyTraits>::removeIf):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/dfg/DFGObjectAllocationSinkingPhase.cpp

    r225368 r225375  
    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;
Note: See TracChangeset for help on using the changeset viewer.