Commit 1d39e4bd authored by Luke Wagner's avatar Luke Wagner
Browse files

Bug 832090 - make HashMap/Set movable (r=terrence)

parent 9eb3eb36
Loading
Loading
Loading
Loading
+29 −2
Original line number Diff line number Diff line
@@ -236,8 +236,12 @@ class HashMap
            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;

@@ -426,8 +430,12 @@ class HashSet
            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;

@@ -779,6 +787,25 @@ class HashTable : private AllocPolicy
        }
    };

    // 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