Bug 912567 - Split HashMap/HashSet::rekey() into rekey() and rekeyIfMoved() r=terrence
authorJon Coppeard <jcoppeard@mozilla.com>
Tue, 24 Sep 2013 10:03:32 +0100
changeset 148414 58de1d903b6fdbc565e62f692d5c70fa1660939a
parent 148413 8e10ba98b509622f34d14c9a30ad3618f396adc2
child 148415 104bd5bd8154492238c47adb676ed662e378ef9d
push id34213
push userjcoppeard@mozilla.com
push dateTue, 24 Sep 2013 09:38:40 +0000
treeherdermozilla-inbound@6d6942eeef1a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs912567
milestone27.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 912567 - Split HashMap/HashSet::rekey() into rekey() and rekeyIfMoved() r=terrence
js/ipc/JavaScriptShared.cpp
js/public/HashTable.h
js/src/ctypes/CTypes.cpp
js/src/gc/StoreBuffer.h
js/xpconnect/src/XPCMaps.h
--- a/js/ipc/JavaScriptShared.cpp
+++ b/js/ipc/JavaScriptShared.cpp
@@ -100,17 +100,17 @@ ObjectIdCache::add(JSContext *cx, JSObje
  * been moved.
  */
 /* static */ void
 ObjectIdCache::keyMarkCallback(JSTracer *trc, void *k, void *d) {
     JSObject *key = static_cast<JSObject*>(k);
     ObjectIdCache* self = static_cast<ObjectIdCache*>(d);
     JSObject *prior = key;
     JS_CallObjectTracer(trc, &key, "ObjectIdCache::table_ key");
-    self->table_.rekey(prior, key);
+    self->table_.rekeyIfMoved(prior, key);
 }
 
 void
 ObjectIdCache::remove(JSObject *obj)
 {
     table_.remove(obj);
 }
 
--- a/js/public/HashTable.h
+++ b/js/public/HashTable.h
@@ -245,22 +245,27 @@ class HashMap
     }
 
     // Remove if present.
     void remove(const Lookup &l) {
         if (Ptr p = lookup(l))
             remove(p);
     }
 
+    // Infallibly rekey one entry, if necessary.
+    // Requires template parameters Key and HashPolicy::Lookup to be the same type.
+    void rekeyIfMoved(const Key &old_key, const Key &new_key) {
+        if (old_key != new_key)
+            rekeyAs(old_key, new_key, new_key);
+    }
+
     // Infallibly rekey one entry, if present.
-    void rekey(const Lookup &old_key, const Key &new_key) {
-        if (old_key != new_key) {
-            if (Ptr p = lookup(old_key))
-                impl.rekeyAndMaybeRehash(p, new_key, new_key);
-        }
+    void rekeyAs(const Lookup &old_lookup, const Lookup &new_lookup, const Key &new_key) {
+        if (Ptr p = lookup(old_lookup))
+            impl.rekeyAndMaybeRehash(p, new_lookup, new_key);
     }
 
     // HashMap is movable
     HashMap(mozilla::MoveRef<HashMap> rhs) : impl(mozilla::OldMove(rhs->impl)) {}
     void operator=(mozilla::MoveRef<HashMap> rhs) { impl = mozilla::OldMove(rhs->impl); }
 
   private:
     // HashMap is not copyable or assignable
@@ -445,21 +450,26 @@ class HashSet
     }
 
     void remove(const Lookup &l) {
         if (Ptr p = lookup(l))
             remove(p);
     }
 
     // Infallibly rekey one entry, if present.
-    void rekey(const Lookup &old_key, const T &new_key) {
-        if (old_key != new_key) {
-            if (Ptr p = lookup(old_key))
-                impl.rekeyAndMaybeRehash(p, new_key, new_key);
-        }
+    // Requires template parameters T and HashPolicy::Lookup to be the same type.
+    void rekeyIfMoved(const Lookup &old_value, const T &new_value) {
+        if (old_value != new_value)
+            rekeyAs(old_value, new_value, new_value);
+    }
+
+    // Infallibly rekey one entry, if present.
+    void 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);
     }
 
     // HashSet is movable
     HashSet(mozilla::MoveRef<HashSet> rhs) : impl(mozilla::OldMove(rhs->impl)) {}
     void operator=(mozilla::MoveRef<HashSet> rhs) { impl = mozilla::OldMove(rhs->impl); }
 
   private:
     // HashSet is not copyable or assignable
--- a/js/src/ctypes/CTypes.cpp
+++ b/js/src/ctypes/CTypes.cpp
@@ -4739,17 +4739,17 @@ StructType::Create(JSContext* cx, unsign
 
 static void
 PostBarrierCallback(JSTracer *trc, void *k, void *d)
 {
     JSString *prior = static_cast<JSString*>(k);
     FieldInfoHash *table = static_cast<FieldInfoHash*>(d);
     JSString *key = prior;
     JS_CallStringTracer(trc, &key, "CType fieldName");
-    table->rekey(JS_ASSERT_STRING_IS_FLAT(prior), JS_ASSERT_STRING_IS_FLAT(key));
+    table->rekeyIfMoved(JS_ASSERT_STRING_IS_FLAT(prior), JS_ASSERT_STRING_IS_FLAT(key));
 }
 
 bool
 StructType::DefineInternal(JSContext* cx, JSObject* typeObj_, JSObject* fieldsObj_)
 {
   RootedObject typeObj(cx, typeObj_);
   RootedObject fieldsObj(cx, fieldsObj_);
 
--- a/js/src/gc/StoreBuffer.h
+++ b/js/src/gc/StoreBuffer.h
@@ -54,17 +54,17 @@ class HashKeyRef : public BufferableRef
 
     void mark(JSTracer *trc) {
         Key prior = key;
         typename Map::Ptr p = map->lookup(key);
         if (!p)
             return;
         JS_SET_TRACING_LOCATION(trc, (void*)&*p);
         Mark(trc, &key, "HashKeyRef");
-        map->rekey(prior, key);
+        map->rekeyIfMoved(prior, key);
     }
 };
 
 typedef HashSet<void *, PointerHasher<void *, 3>, SystemAllocPolicy> EdgeSet;
 
 /*
  * The StoreBuffer observes all writes that occur in the system and performs
  * efficient filtering of them to derive a remembered set for nursery GC.
--- a/js/xpconnect/src/XPCMaps.h
+++ b/js/xpconnect/src/XPCMaps.h
@@ -85,17 +85,17 @@ private:
      * This function is called during minor GCs for each key in the HashMap that
      * has been moved.
      */
     static void KeyMarkCallback(JSTracer *trc, void *k, void *d) {
         JSObject *key = static_cast<JSObject*>(k);
         JSObject2WrappedJSMap* self = static_cast<JSObject2WrappedJSMap*>(d);
         JSObject *prior = key;
         JS_CallObjectTracer(trc, &key, "XPCJSRuntime::mWrappedJSMap key");
-        self->mTable.rekey(prior, key);
+        self->mTable.rekeyIfMoved(prior, key);
     }
 
     Map mTable;
 };
 
 /*************************/
 
 class Native2WrappedNativeMap
@@ -694,15 +694,15 @@ private:
      * This function is called during minor GCs for each key in the HashMap that
      * has been moved.
      */
     static void KeyMarkCallback(JSTracer *trc, void *k, void *d) {
         JSObject *key = static_cast<JSObject*>(k);
         JSObject2JSObjectMap *self = static_cast<JSObject2JSObjectMap *>(d);
         JSObject *prior = key;
         JS_CallObjectTracer(trc, &key, "XPCWrappedNativeScope::mWaiverWrapperMap key");
-        self->mTable.rekey(prior, key);
+        self->mTable.rekeyIfMoved(prior, key);
     }
 
     Map mTable;
 };
 
 #endif /* xpcmaps_h___ */