Bug 1239515 - Simplify HashSet's key-overwriting interface; r=sunfish
authorTerrence Cole <terrence@mozilla.com>
Thu, 14 Jan 2016 09:43:30 -0800
changeset 279995 3aabb2f49d41f83d8d296bd893336411e29b29c5
parent 279994 89a5dfce0c0760900b58dc2efbccc2b36605baca
child 279996 fc181e666300a6ba141badd5e430a29e173c539b
push id70290
push usertcole@mozilla.com
push dateThu, 14 Jan 2016 17:43:54 +0000
treeherdermozilla-inbound@3aabb2f49d41 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssunfish
bugs1239515
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1239515 - Simplify HashSet's key-overwriting interface; r=sunfish
js/public/HashTable.h
js/src/jit/ValueNumbering.cpp
--- a/js/public/HashTable.h
+++ b/js/public/HashTable.h
@@ -493,21 +493,26 @@ class HashSet
     bool rekeyAs(const Lookup& old_lookup, const Lookup& new_lookup, const T& new_value) {
         if (Ptr p = lookup(old_lookup)) {
             impl.rekeyAndMaybeRehash(p, new_lookup, new_value);
             return true;
         }
         return false;
     }
 
-    // Infallibly rekey one entry with a new key that is equivalent.
-    void rekeyInPlace(Ptr p, const T& new_value)
-    {
+    // Infallibly replace the current key at |p| with an equivalent key.
+    // Specifically, both HashPolicy::hash and HashPolicy::match must return
+    // identical results for the new and old key when applied against all
+    // possible matching values.
+    void replaceKey(Ptr p, const T& new_value) {
+        MOZ_ASSERT(p.found());
+        MOZ_ASSERT(*p != new_value);
+        MOZ_ASSERT(HashPolicy::hash(*p) == HashPolicy::hash(new_value));
         MOZ_ASSERT(HashPolicy::match(*p, new_value));
-        impl.rekeyInPlace(p, new_value);
+        const_cast<T&>(*p) = new_value;
     }
 
     // HashSet is movable
     HashSet(HashSet&& rhs) : impl(mozilla::Move(rhs.impl)) {}
     void operator=(HashSet&& rhs) {
         MOZ_ASSERT(this != &rhs, "self-move assignment is prohibited");
         impl = mozilla::Move(rhs.impl);
     }
@@ -1750,23 +1755,15 @@ class HashTable : private AllocPolicy
     }
 
     void rekeyAndMaybeRehash(Ptr p, const Lookup& l, const Key& k)
     {
         rekeyWithoutRehash(p, l, k);
         checkOverRemoved();
     }
 
-    void rekeyInPlace(Ptr p, const Key& k)
-    {
-        MOZ_ASSERT(table);
-        mozilla::ReentrancyGuard g(*this);
-        MOZ_ASSERT(p.found());
-        HashPolicy::rekey(const_cast<Key&>(*p), const_cast<Key&>(k));
-    }
-
 #undef METER
 };
 
 } // namespace detail
 } // namespace js
 
 #endif  /* js_HashTable_h */
--- a/js/src/jit/ValueNumbering.cpp
+++ b/js/src/jit/ValueNumbering.cpp
@@ -103,17 +103,17 @@ ValueNumberer::VisibleValues::add(AddPtr
 {
     return set_.add(p, def);
 }
 
 // Insert a value onto the set overwriting any existing entry.
 void
 ValueNumberer::VisibleValues::overwrite(AddPtr p, MDefinition* def)
 {
-    set_.rekeyInPlace(p, def);
+    set_.replaceKey(p, def);
 }
 
 // |def| will be discarded, so remove it from any sets.
 void
 ValueNumberer::VisibleValues::forget(const MDefinition* def)
 {
     Ptr p = set_.lookup(def);
     if (p && *p == def)