mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1365654 - Add a move constructor to HashTable::Enum r=luke
This commit is contained in:
parent
c6ca6e9675
commit
e85f5ed76c
@ -1070,13 +1070,21 @@ class HashTable : private AllocPolicy
|
||||
bool rekeyed;
|
||||
bool removed;
|
||||
|
||||
/* Not copyable. */
|
||||
// Enum is movable but not copyable.
|
||||
Enum(const Enum&) = delete;
|
||||
void operator=(const Enum&) = delete;
|
||||
|
||||
public:
|
||||
template<class Map> explicit
|
||||
Enum(Map& map) : Range(map.all()), table_(map.impl), rekeyed(false), removed(false) {}
|
||||
template<class Map>
|
||||
explicit Enum(Map& map)
|
||||
: Range(map.all()), table_(map.impl), rekeyed(false), removed(false) {}
|
||||
|
||||
MOZ_IMPLICIT Enum(Enum&& other)
|
||||
: Range(other), table_(other.table_), rekeyed(other.rekeyed), removed(other.removed)
|
||||
{
|
||||
other.rekeyed = false;
|
||||
other.removed = false;
|
||||
}
|
||||
|
||||
// Removes the |front()| element from the table, leaving |front()|
|
||||
// invalid until the next call to |popFront()|. For example:
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include "js/Utility.h"
|
||||
#include "jsapi-tests/tests.h"
|
||||
|
||||
#include "mozilla/Move.h"
|
||||
|
||||
//#define FUZZ
|
||||
|
||||
typedef js::HashMap<uint32_t, uint32_t, js::DefaultHasher<uint32_t>, js::SystemAllocPolicy> IntMap;
|
||||
@ -388,3 +390,45 @@ BEGIN_TEST(testHashMapLookupWithDefaultOOM)
|
||||
|
||||
END_TEST(testHashMapLookupWithDefaultOOM)
|
||||
#endif // defined(DEBUG)
|
||||
|
||||
BEGIN_TEST(testHashTableMovableEnum)
|
||||
{
|
||||
CHECK(set.init());
|
||||
|
||||
// Exercise returning a hash table Enum object from a function.
|
||||
|
||||
CHECK(set.put(1));
|
||||
for (auto e = enumerateSet(); !e.empty(); e.popFront())
|
||||
e.removeFront();
|
||||
CHECK(set.count() == 0);
|
||||
|
||||
// Test moving an Enum object explicitly.
|
||||
|
||||
CHECK(set.put(1));
|
||||
CHECK(set.put(2));
|
||||
CHECK(set.put(3));
|
||||
CHECK(set.count() == 3);
|
||||
{
|
||||
auto e1 = IntSet::Enum(set);
|
||||
CHECK(!e1.empty());
|
||||
e1.removeFront();
|
||||
e1.popFront();
|
||||
|
||||
auto e2 = mozilla::Move(e1);
|
||||
CHECK(!e2.empty());
|
||||
e2.removeFront();
|
||||
e2.popFront();
|
||||
}
|
||||
|
||||
CHECK(set.count() == 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
IntSet set;
|
||||
|
||||
IntSet::Enum enumerateSet()
|
||||
{
|
||||
return IntSet::Enum(set);
|
||||
}
|
||||
|
||||
END_TEST(testHashTableMovableEnum)
|
||||
|
Loading…
Reference in New Issue
Block a user