<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[225362] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/225362">225362</a></dd>
<dt>Author</dt> <dd>utatane.tea@gmail.com</dd>
<dt>Date</dt> <dd>2017-11-30 15:44:24 -0800 (Thu, 30 Nov 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[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):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreb3B3MoveConstantscpp">trunk/Source/JavaScriptCore/b3/B3MoveConstants.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGArgumentsEliminationPhasecpp">trunk/Source/JavaScriptCore/dfg/DFGArgumentsEliminationPhase.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGObjectAllocationSinkingPhasecpp">trunk/Source/JavaScriptCore/dfg/DFGObjectAllocationSinkingPhase.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWasmSignaturecpp">trunk/Source/JavaScriptCore/wasm/WasmSignature.cpp</a></li>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfHashMaph">trunk/Source/WTF/wtf/HashMap.h</a></li>
<li><a href="#trunkSourceWTFwtfHashSeth">trunk/Source/WTF/wtf/HashSet.h</a></li>
<li><a href="#trunkSourceWTFwtfHashTableh">trunk/Source/WTF/wtf/HashTable.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (225361 => 225362)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog    2017-11-30 23:39:14 UTC (rev 225361)
+++ trunk/Source/JavaScriptCore/ChangeLog       2017-11-30 23:44:24 UTC (rev 225362)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2017-11-30  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [JSC] Remove easy toRemove & map.remove() use
+        https://bugs.webkit.org/show_bug.cgi?id=180208
+
+        Reviewed by Mark Lam.
+
+        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):
+
</ins><span class="cx"> 2017-11-29  Yusuke Suzuki  <utatane.tea@gmail.com>
</span><span class="cx"> 
</span><span class="cx">         [JSC] Use getEffectiveAddress more in JSC
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreb3B3MoveConstantscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/b3/B3MoveConstants.cpp (225361 => 225362)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/b3/B3MoveConstants.cpp       2017-11-30 23:39:14 UTC (rev 225361)
+++ trunk/Source/JavaScriptCore/b3/B3MoveConstants.cpp  2017-11-30 23:44:24 UTC (rev 225362)
</span><span class="lines">@@ -342,10 +342,8 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     Procedure& m_proc;
</span><del>-    Vector<Value*> m_toRemove;
</del><span class="cx">     HashMap<ValueKey, unsigned> m_constTable;
</span><span class="cx">     int64_t* m_dataSection;
</span><del>-    HashMap<ValueKey, Value*> m_constants;
</del><span class="cx">     InsertionSet m_insertionSet;
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGArgumentsEliminationPhasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGArgumentsEliminationPhase.cpp (225361 => 225362)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGArgumentsEliminationPhase.cpp 2017-11-30 23:39:14 UTC (rev 225361)
+++ trunk/Source/JavaScriptCore/dfg/DFGArgumentsEliminationPhase.cpp    2017-11-30 23:44:24 UTC (rev 225362)
</span><span class="lines">@@ -192,20 +192,10 @@
</span><span class="cx">     {
</span><span class="cx">         bool changed;
</span><span class="cx">         do {
</span><del>-            changed = false;
-            Vector<Node*, 1> toRemove;
-
-            for (Node* candidate : m_candidates) {
-                if (!isStillValidCandidate(candidate))
-                    toRemove.append(candidate);
-            }
-
-            if (toRemove.size()) {
-                changed = true;
-                for (Node* node : toRemove)
-                    m_candidates.remove(node);
-            }
-
</del><ins>+            changed = m_candidates.removeIf(
+                [&] (Node* candidate) {
+                    return !isStillValidCandidate(candidate);
+                });
</ins><span class="cx">         } while (changed);
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGObjectAllocationSinkingPhasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGObjectAllocationSinkingPhase.cpp (225361 => 225362)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGObjectAllocationSinkingPhase.cpp      2017-11-30 23:39:14 UTC (rev 225361)
+++ trunk/Source/JavaScriptCore/dfg/DFGObjectAllocationSinkingPhase.cpp 2017-11-30 23:44:24 UTC (rev 225362)
</span><span class="lines">@@ -507,14 +507,10 @@
</span><span class="cx"> 
</span><span class="cx">     void pruneByLiveness(const NodeSet& live)
</span><span class="cx">     {
</span><del>-        Vector<Node*> toRemove;
-        for (const auto& entry : m_pointers) {
-            if (!live.contains(entry.key))
-                toRemove.append(entry.key);
-        }
-        for (Node* node : toRemove)
-            m_pointers.remove(node);
-
</del><ins>+        m_pointers.removeIf(
+            [&] (const auto& entry) {
+                return !live.contains(entry.key);
+            });
</ins><span class="cx">         prune();
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -682,15 +678,10 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         // Remove unreachable allocations
</span><del>-        {
-            Vector<Node*> toRemove;
-            for (const auto& entry : m_allocations) {
-                if (!reachable.contains(entry.key))
-                    toRemove.append(entry.key);
-            }
-            for (Node* identifier : toRemove)
-                m_allocations.remove(identifier);
-        }
</del><ins>+        m_allocations.removeIf(
+            [&] (const auto& entry) {
+                return !reachable.contains(entry.key);
+            });
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     bool m_reached = false;
</span><span class="lines">@@ -1249,14 +1240,10 @@
</span><span class="cx">     {
</span><span class="cx">         // We don't create materializations if the escapee is not a
</span><span class="cx">         // sink candidate
</span><del>-        Vector<Node*> toRemove;
-        for (const auto& entry : escapees) {
-            if (!m_sinkCandidates.contains(entry.key))
-                toRemove.append(entry.key);
-        }
-        for (Node* identifier : toRemove)
-            escapees.remove(identifier);
-
</del><ins>+        escapees.removeIf(
+            [&] (const auto& entry) {
+                return !m_sinkCandidates.contains(entry.key);
+            });
</ins><span class="cx">         if (escapees.isEmpty())
</span><span class="cx">             return;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWasmSignaturecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WasmSignature.cpp (225361 => 225362)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WasmSignature.cpp       2017-11-30 23:39:14 UTC (rev 225361)
+++ trunk/Source/JavaScriptCore/wasm/WasmSignature.cpp  2017-11-30 23:44:24 UTC (rev 225362)
</span><span class="lines">@@ -144,20 +144,18 @@
</span><span class="cx">     SignatureInformation& info = singleton();
</span><span class="cx">     LockHolder lock(info.m_lock);
</span><span class="cx"> 
</span><del>-    Vector<std::pair<SignatureIndex, Signature*>> toRemove;
-    for (const auto& pair : info.m_indexMap) {
-        const Ref<Signature>& signature = pair.value;
-        if (signature->refCount() == 1) {
-            // We're the only owner.
-            toRemove.append(std::make_pair(pair.key, signature.ptr()));
-        }
-    }
-    for (const auto& pair : toRemove) {
-        bool removed = info.m_signatureMap.remove(SignatureHash { pair.second });
-        ASSERT_UNUSED(removed, removed);
-        removed = info.m_indexMap.remove(pair.first);
-        ASSERT_UNUSED(removed, removed);
-    }
</del><ins>+    info.m_indexMap.removeIf(
+        [&] (const auto& pair) {
+            const Ref<Signature>& signature = pair.value;
+            if (signature->refCount() == 1) {
+                // We're the only owner.
+                bool removed = info.m_signatureMap.remove(SignatureHash { signature.ptr() });
+                ASSERT_UNUSED(removed, removed);
+                return true;
+            }
+            return false;
+        });
+
</ins><span class="cx">     if (info.m_signatureMap.isEmpty()) {
</span><span class="cx">         ASSERT(info.m_indexMap.isEmpty());
</span><span class="cx">         info.m_nextIndex = Signature::firstValidIndex;
</span></span></pre></div>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (225361 => 225362)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog       2017-11-30 23:39:14 UTC (rev 225361)
+++ trunk/Source/WTF/ChangeLog  2017-11-30 23:44:24 UTC (rev 225362)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2017-11-30  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [JSC] Remove easy toRemove & map.remove() use
+        https://bugs.webkit.org/show_bug.cgi?id=180208
+
+        Reviewed by Mark Lam.
+
+        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):
+
</ins><span class="cx"> 2017-11-30  Chris Dumez  <cdumez@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Populate self.registration.installing/waiting/active inside service workers
</span></span></pre></div>
<a id="trunkSourceWTFwtfHashMaph"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/HashMap.h (225361 => 225362)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/HashMap.h   2017-11-30 23:39:14 UTC (rev 225361)
+++ trunk/Source/WTF/wtf/HashMap.h      2017-11-30 23:44:24 UTC (rev 225362)
</span><span class="lines">@@ -135,7 +135,7 @@
</span><span class="cx">     bool remove(const KeyType&);
</span><span class="cx">     bool remove(iterator);
</span><span class="cx">     template<typename Functor>
</span><del>-    void removeIf(Functor&&);
</del><ins>+    bool removeIf(Functor&&);
</ins><span class="cx">     void clear();
</span><span class="cx"> 
</span><span class="cx">     MappedTakeType take(const KeyType&); // efficient combination of get with remove
</span><span class="lines">@@ -443,9 +443,9 @@
</span><span class="cx"> 
</span><span class="cx"> template<typename T, typename U, typename V, typename W, typename X>
</span><span class="cx"> template<typename Functor>
</span><del>-inline void HashMap<T, U, V, W, X>::removeIf(Functor&& functor)
</del><ins>+inline bool HashMap<T, U, V, W, X>::removeIf(Functor&& functor)
</ins><span class="cx"> {
</span><del>-    m_impl.removeIf(std::forward<Functor>(functor));
</del><ins>+    return m_impl.removeIf(std::forward<Functor>(functor));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> template<typename T, typename U, typename V, typename W, typename X>
</span></span></pre></div>
<a id="trunkSourceWTFwtfHashSeth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/HashSet.h (225361 => 225362)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/HashSet.h   2017-11-30 23:39:14 UTC (rev 225361)
+++ trunk/Source/WTF/wtf/HashSet.h      2017-11-30 23:44:24 UTC (rev 225362)
</span><span class="lines">@@ -105,7 +105,7 @@
</span><span class="cx">     bool remove(const ValueType&);
</span><span class="cx">     bool remove(iterator);
</span><span class="cx">     template<typename Functor>
</span><del>-    void removeIf(const Functor&);
</del><ins>+    bool removeIf(const Functor&);
</ins><span class="cx">     void clear();
</span><span class="cx"> 
</span><span class="cx">     TakeType take(const ValueType&);
</span><span class="lines">@@ -275,9 +275,9 @@
</span><span class="cx"> 
</span><span class="cx"> template<typename T, typename U, typename V>
</span><span class="cx"> template<typename Functor>
</span><del>-inline void HashSet<T, U, V>::removeIf(const Functor& functor)
</del><ins>+inline bool HashSet<T, U, V>::removeIf(const Functor& functor)
</ins><span class="cx"> {
</span><del>-    m_impl.removeIf(functor);
</del><ins>+    return m_impl.removeIf(functor);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> template<typename T, typename U, typename V>
</span></span></pre></div>
<a id="trunkSourceWTFwtfHashTableh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/HashTable.h (225361 => 225362)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/HashTable.h 2017-11-30 23:39:14 UTC (rev 225361)
+++ trunk/Source/WTF/wtf/HashTable.h    2017-11-30 23:44:24 UTC (rev 225362)
</span><span class="lines">@@ -405,7 +405,7 @@
</span><span class="cx">         void removeWithoutEntryConsistencyCheck(iterator);
</span><span class="cx">         void removeWithoutEntryConsistencyCheck(const_iterator);
</span><span class="cx">         template<typename Functor>
</span><del>-        void removeIf(const Functor&);
</del><ins>+        bool removeIf(const Functor&);
</ins><span class="cx">         void clear();
</span><span class="cx"> 
</span><span class="cx">         static bool isEmptyBucket(const ValueType& value) { return isHashTraitsEmptyValue<KeyTraits>(Extractor::extract(value)); }
</span><span class="lines">@@ -1108,7 +1108,7 @@
</span><span class="cx"> 
</span><span class="cx">     template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>
</span><span class="cx">     template<typename Functor>
</span><del>-    inline void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::removeIf(const Functor& functor)
</del><ins>+    inline bool HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::removeIf(const Functor& functor)
</ins><span class="cx">     {
</span><span class="cx">         // We must use local copies in case "functor" or "deleteBucket"
</span><span class="cx">         // make a function call, which prevents the compiler from keeping
</span><span class="lines">@@ -1134,6 +1134,7 @@
</span><span class="cx">             shrink();
</span><span class="cx">         
</span><span class="cx">         internalCheckTableConsistency();
</span><ins>+        return removedBucketCount;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>
</span></span></pre>
</div>
</div>

</body>
</html>