Bug 832090 - make HashMap/Set movable (r=terrence)
authorLuke Wagner <luke@mozilla.com>
Wed, 28 Nov 2012 15:19:39 -0800
changeset 119328 6e5e10fb6d73dbee1bced3a42eb795bfa98b7c68
parent 119327 d835ea3c8339c5533aff81c43ef582f4c1960604
child 119329 879677a0aa37c0f811a6c4348d5a3dc27aa98984
push id24195
push userMs2ger@gmail.com
push dateSat, 19 Jan 2013 16:10:11 +0000
treeherdermozilla-central@02e12a80aef9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs832090
milestone21.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 832090 - make HashMap/Set movable (r=terrence)
js/public/HashTable.h
--- a/js/public/HashTable.h
+++ b/js/public/HashTable.h
@@ -231,18 +231,22 @@ class HashMap
     }
 
     // Remove if present.
     void remove(const Lookup &l) {
         if (Ptr p = lookup(l))
             remove(p);
     }
 
+    // HashMap is movable
+    HashMap(MoveRef<HashMap> rhs) : impl(Move(rhs->impl)) {}
+    void operator=(MoveRef<HashMap> rhs) { impl = Move(rhs->impl); }
+
   private:
-    // Not implicitly copyable (expensive). May add explicit |clone| later.
+    // HashMap is not copyable or assignable
     HashMap(const HashMap &hm) MOZ_DELETE;
     HashMap &operator=(const HashMap &hm) MOZ_DELETE;
 
     friend class Impl::Enum;
 
     typedef typename tl::StaticAssert<tl::IsRelocatableHeapType<Key>::result>::result keyAssert;
     typedef typename tl::StaticAssert<tl::IsRelocatableHeapType<Value>::result>::result valAssert;
 };
@@ -421,18 +425,22 @@ class HashSet
         return impl.putNew(l, t);
     }
 
     void remove(const Lookup &l) {
         if (Ptr p = lookup(l))
             remove(p);
     }
 
+    // HashSet is movable
+    HashSet(MoveRef<HashSet> rhs) : impl(Move(rhs->impl)) {}
+    void operator=(MoveRef<HashSet> rhs) { impl = Move(rhs->impl); }
+
   private:
-    // Not implicitly copyable (expensive). May add explicit |clone| later.
+    // HashSet is not copyable or assignable
     HashSet(const HashSet &hs) MOZ_DELETE;
     HashSet &operator=(const HashSet &hs) MOZ_DELETE;
 
     friend class Impl::Enum;
 
     typedef typename tl::StaticAssert<tl::IsRelocatableHeapType<T>::result>::result _;
 };
 
@@ -774,16 +782,35 @@ class HashTable : private AllocPolicy
             if (rekeyed)
                 table.checkOverRemoved();
 
             if (removed)
                 table.compactIfUnderloaded();
         }
     };
 
+    // HashTable is movable
+    HashTable(MoveRef<HashTable> rhs)
+      : AllocPolicy(*rhs)
+    {
+        PodAssign(this, &*rhs);
+        rhs->table = NULL;
+    }
+    void operator=(MoveRef<HashTable> rhs) {
+        if (table)
+            destroyTable(*this, table, capacity());
+        PodAssign(this, &*rhs);
+        rhs->table = NULL;
+    }
+
+  private:
+    // HashTable is not copyable or assignable
+    HashTable(const HashTable &) MOZ_DELETE;
+    void operator=(const HashTable &) MOZ_DELETE;
+
   private:
     uint32_t    hashShift;      // multiplicative hash shift
     uint32_t    entryCount;     // number of entries in table
     uint32_t    gen;            // entry storage generation number
     uint32_t    removedCount;   // removed entry sentinels in table
     Entry       *table;         // entry storage
 
     void setTableSizeLog2(unsigned sizeLog2)