Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (225361 => 225362)
--- trunk/Source/_javascript_Core/ChangeLog 2017-11-30 23:39:14 UTC (rev 225361)
+++ trunk/Source/_javascript_Core/ChangeLog 2017-11-30 23:44:24 UTC (rev 225362)
@@ -1,3 +1,20 @@
+2017-11-30 Yusuke Suzuki <[email protected]>
+
+ [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):
+
2017-11-29 Yusuke Suzuki <[email protected]>
[JSC] Use getEffectiveAddress more in JSC
Modified: trunk/Source/_javascript_Core/b3/B3MoveConstants.cpp (225361 => 225362)
--- trunk/Source/_javascript_Core/b3/B3MoveConstants.cpp 2017-11-30 23:39:14 UTC (rev 225361)
+++ trunk/Source/_javascript_Core/b3/B3MoveConstants.cpp 2017-11-30 23:44:24 UTC (rev 225362)
@@ -342,10 +342,8 @@
}
Procedure& m_proc;
- Vector<Value*> m_toRemove;
HashMap<ValueKey, unsigned> m_constTable;
int64_t* m_dataSection;
- HashMap<ValueKey, Value*> m_constants;
InsertionSet m_insertionSet;
};
Modified: trunk/Source/_javascript_Core/dfg/DFGArgumentsEliminationPhase.cpp (225361 => 225362)
--- trunk/Source/_javascript_Core/dfg/DFGArgumentsEliminationPhase.cpp 2017-11-30 23:39:14 UTC (rev 225361)
+++ trunk/Source/_javascript_Core/dfg/DFGArgumentsEliminationPhase.cpp 2017-11-30 23:44:24 UTC (rev 225362)
@@ -192,20 +192,10 @@
{
bool changed;
do {
- 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);
- }
-
+ changed = m_candidates.removeIf(
+ [&] (Node* candidate) {
+ return !isStillValidCandidate(candidate);
+ });
} while (changed);
}
Modified: trunk/Source/_javascript_Core/dfg/DFGObjectAllocationSinkingPhase.cpp (225361 => 225362)
--- trunk/Source/_javascript_Core/dfg/DFGObjectAllocationSinkingPhase.cpp 2017-11-30 23:39:14 UTC (rev 225361)
+++ trunk/Source/_javascript_Core/dfg/DFGObjectAllocationSinkingPhase.cpp 2017-11-30 23:44:24 UTC (rev 225362)
@@ -507,14 +507,10 @@
void pruneByLiveness(const NodeSet& live)
{
- 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);
-
+ m_pointers.removeIf(
+ [&] (const auto& entry) {
+ return !live.contains(entry.key);
+ });
prune();
}
@@ -682,15 +678,10 @@
}
// Remove unreachable allocations
- {
- 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);
- }
+ m_allocations.removeIf(
+ [&] (const auto& entry) {
+ return !reachable.contains(entry.key);
+ });
}
bool m_reached = false;
@@ -1249,14 +1240,10 @@
{
// We don't create materializations if the escapee is not a
// sink candidate
- 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);
-
+ escapees.removeIf(
+ [&] (const auto& entry) {
+ return !m_sinkCandidates.contains(entry.key);
+ });
if (escapees.isEmpty())
return;
Modified: trunk/Source/_javascript_Core/wasm/WasmSignature.cpp (225361 => 225362)
--- trunk/Source/_javascript_Core/wasm/WasmSignature.cpp 2017-11-30 23:39:14 UTC (rev 225361)
+++ trunk/Source/_javascript_Core/wasm/WasmSignature.cpp 2017-11-30 23:44:24 UTC (rev 225362)
@@ -144,20 +144,18 @@
SignatureInformation& info = singleton();
LockHolder lock(info.m_lock);
- 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);
- }
+ 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;
+ });
+
if (info.m_signatureMap.isEmpty()) {
ASSERT(info.m_indexMap.isEmpty());
info.m_nextIndex = Signature::firstValidIndex;
Modified: trunk/Source/WTF/ChangeLog (225361 => 225362)
--- 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)
@@ -1,3 +1,21 @@
+2017-11-30 Yusuke Suzuki <[email protected]>
+
+ [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):
+
2017-11-30 Chris Dumez <[email protected]>
Populate self.registration.installing/waiting/active inside service workers
Modified: trunk/Source/WTF/wtf/HashMap.h (225361 => 225362)
--- 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)
@@ -135,7 +135,7 @@
bool remove(const KeyType&);
bool remove(iterator);
template<typename Functor>
- void removeIf(Functor&&);
+ bool removeIf(Functor&&);
void clear();
MappedTakeType take(const KeyType&); // efficient combination of get with remove
@@ -443,9 +443,9 @@
template<typename T, typename U, typename V, typename W, typename X>
template<typename Functor>
-inline void HashMap<T, U, V, W, X>::removeIf(Functor&& functor)
+inline bool HashMap<T, U, V, W, X>::removeIf(Functor&& functor)
{
- m_impl.removeIf(std::forward<Functor>(functor));
+ return m_impl.removeIf(std::forward<Functor>(functor));
}
template<typename T, typename U, typename V, typename W, typename X>
Modified: trunk/Source/WTF/wtf/HashSet.h (225361 => 225362)
--- 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)
@@ -105,7 +105,7 @@
bool remove(const ValueType&);
bool remove(iterator);
template<typename Functor>
- void removeIf(const Functor&);
+ bool removeIf(const Functor&);
void clear();
TakeType take(const ValueType&);
@@ -275,9 +275,9 @@
template<typename T, typename U, typename V>
template<typename Functor>
-inline void HashSet<T, U, V>::removeIf(const Functor& functor)
+inline bool HashSet<T, U, V>::removeIf(const Functor& functor)
{
- m_impl.removeIf(functor);
+ return m_impl.removeIf(functor);
}
template<typename T, typename U, typename V>
Modified: trunk/Source/WTF/wtf/HashTable.h (225361 => 225362)
--- 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)
@@ -405,7 +405,7 @@
void removeWithoutEntryConsistencyCheck(iterator);
void removeWithoutEntryConsistencyCheck(const_iterator);
template<typename Functor>
- void removeIf(const Functor&);
+ bool removeIf(const Functor&);
void clear();
static bool isEmptyBucket(const ValueType& value) { return isHashTraitsEmptyValue<KeyTraits>(Extractor::extract(value)); }
@@ -1108,7 +1108,7 @@
template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>
template<typename Functor>
- inline void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::removeIf(const Functor& functor)
+ inline bool HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::removeIf(const Functor& functor)
{
// We must use local copies in case "functor" or "deleteBucket"
// make a function call, which prevents the compiler from keeping
@@ -1134,6 +1134,7 @@
shrink();
internalCheckTableConsistency();
+ return removedBucketCount;
}
template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>