Backed out 3 changesets (bug 1733963) for causing build bustages on SyncedContext.h. CLOSED TREE

Backed out changeset de5c7a16378c (bug 1733963)
Backed out changeset f5f3a27abf60 (bug 1733963)
Backed out changeset cc3a0603f88a (bug 1733963)
This commit is contained in:
Marian-Vasile Laza 2021-11-05 20:54:33 +02:00
parent cc3d9c2dec
commit fca6bc6241
8 changed files with 112 additions and 265 deletions

View File

@ -11,7 +11,6 @@
#include <type_traits>
#include <utility>
#include "mozilla/Attributes.h"
#include "mozilla/BitSet.h"
#include "mozilla/EnumSet.h"
#include "nsStringFwd.h"
#include "nscore.h"
@ -44,14 +43,11 @@ namespace syncedcontext {
template <size_t I>
using Index = typename std::integral_constant<size_t, I>;
template <size_t I>
using IndexSet = EnumSet<size_t, BitSet<I>>;
using IndexSet = EnumSet<size_t, uint64_t>;
template <typename Context>
class Transaction {
public:
using IndexSet = IndexSet<Context::FieldValues::count>;
// Set a field at the given index in this `Transaction`. Creating a
// `Transaction` object and setting multiple fields on it allows for
// multiple mutations to be performed atomically.
@ -126,6 +122,9 @@ class FieldValues : public Base {
public:
// The number of fields stored by this type.
static constexpr size_t count = Count;
static_assert(count < 64,
"At most 64 synced fields are supported. Please file a bug if "
"you need additional fields.");
// The base type will define a series of `Get` methods for looking up a field
// by its field index.

View File

@ -61,8 +61,7 @@ void FormatFieldValue(nsACString& aStr, const T& aValue) {
// a synced context transaction is going to perform.
template <typename Context>
nsAutoCString FormatTransaction(
typename Transaction<Context>::IndexSet aModified,
const typename Context::FieldValues& aOldValues,
IndexSet aModified, const typename Context::FieldValues& aOldValues,
const typename Context::FieldValues& aNewValues) {
nsAutoCString result;
Context::FieldValues::EachIndex([&](auto idx) {
@ -79,8 +78,7 @@ nsAutoCString FormatTransaction(
}
template <typename Context>
nsCString FormatValidationError(
typename Transaction<Context>::IndexSet aFailedFields, const char* prefix) {
nsCString FormatValidationError(IndexSet aFailedFields, const char* prefix) {
MOZ_ASSERT(!aFailedFields.isEmpty());
return nsDependentCString{prefix} +
StringJoin(", "_ns, aFailedFields,
@ -247,8 +245,8 @@ inline CanSetResult AsCanSetResult(bool aValue) {
}
template <typename Context>
typename Transaction<Context>::IndexSet Transaction<Context>::Validate(
Context* aOwner, ContentParent* aSource) {
IndexSet Transaction<Context>::Validate(Context* aOwner,
ContentParent* aSource) {
IndexSet failedFields;
Transaction<Context> revertTxn;
@ -297,7 +295,7 @@ void Transaction<Context>::Write(IPC::Message* aMsg,
mozilla::ipc::IProtocol* aActor) const {
// Record which field indices will be included, and then write those fields
// out.
typename IndexSet::serializedType modified = mModified.serialize();
uint64_t modified = mModified.serialize();
WriteIPDLParam(aMsg, aActor, modified);
EachIndex([&](auto idx) {
if (mModified.contains(idx)) {
@ -311,8 +309,7 @@ bool Transaction<Context>::Read(const IPC::Message* aMsg, PickleIterator* aIter,
mozilla::ipc::IProtocol* aActor) {
// Read in which field indices were sent by the remote, followed by the fields
// identified by those indices.
typename IndexSet::serializedType modified =
typename IndexSet::serializedType{};
uint64_t modified = 0;
if (!ReadIPDLParam(aMsg, aIter, aActor, &modified)) {
return false;
}

View File

@ -27,7 +27,7 @@ TEST(IntlPluralRules, CategoriesEnCardinal)
ASSERT_TRUE(catResult.isOk());
auto categories = catResult.unwrap();
ASSERT_EQ(categories.size(), 2u);
ASSERT_EQ(categories.size(), 2);
ASSERT_TRUE(categories.contains(PluralRules::Keyword::One));
ASSERT_TRUE(categories.contains(PluralRules::Keyword::Other));
}
@ -45,7 +45,7 @@ TEST(IntlPluralRules, CategoriesEnOrdinal)
ASSERT_TRUE(catResult.isOk());
auto categories = catResult.unwrap();
ASSERT_EQ(categories.size(), 4u);
ASSERT_EQ(categories.size(), 4);
ASSERT_TRUE(categories.contains(PluralRules::Keyword::Few));
ASSERT_TRUE(categories.contains(PluralRules::Keyword::One));
ASSERT_TRUE(categories.contains(PluralRules::Keyword::Other));
@ -64,7 +64,7 @@ TEST(IntlPluralRules, CategoriesCyCardinal)
ASSERT_TRUE(catResult.isOk());
auto categories = catResult.unwrap();
ASSERT_EQ(categories.size(), 6u);
ASSERT_EQ(categories.size(), 6);
ASSERT_TRUE(categories.contains(PluralRules::Keyword::Few));
ASSERT_TRUE(categories.contains(PluralRules::Keyword::One));
ASSERT_TRUE(categories.contains(PluralRules::Keyword::Other));
@ -86,7 +86,7 @@ TEST(IntlPluralRules, CategoriesCyOrdinal)
ASSERT_TRUE(catResult.isOk());
auto categories = catResult.unwrap();
ASSERT_EQ(categories.size(), 6u);
ASSERT_EQ(categories.size(), 6);
ASSERT_TRUE(categories.contains(PluralRules::Keyword::Few));
ASSERT_TRUE(categories.contains(PluralRules::Keyword::One));
ASSERT_TRUE(categories.contains(PluralRules::Keyword::Other));
@ -107,7 +107,7 @@ TEST(IntlPluralRules, CategoriesBrCardinal)
ASSERT_TRUE(catResult.isOk());
auto categories = catResult.unwrap();
ASSERT_EQ(categories.size(), 5u);
ASSERT_EQ(categories.size(), 5);
ASSERT_TRUE(categories.contains(PluralRules::Keyword::Few));
ASSERT_TRUE(categories.contains(PluralRules::Keyword::One));
ASSERT_TRUE(categories.contains(PluralRules::Keyword::Other));
@ -128,7 +128,7 @@ TEST(IntlPluralRules, CategoriesBrOrdinal)
ASSERT_TRUE(catResult.isOk());
auto categories = catResult.unwrap();
ASSERT_EQ(categories.size(), 1u);
ASSERT_EQ(categories.size(), 1);
ASSERT_TRUE(categories.contains(PluralRules::Keyword::Other));
}
@ -144,7 +144,7 @@ TEST(IntlPluralRules, CategoriesHsbCardinal)
ASSERT_TRUE(catResult.isOk());
auto categories = catResult.unwrap();
ASSERT_EQ(categories.size(), 4u);
ASSERT_EQ(categories.size(), 4);
ASSERT_TRUE(categories.contains(PluralRules::Keyword::Few));
ASSERT_TRUE(categories.contains(PluralRules::Keyword::One));
ASSERT_TRUE(categories.contains(PluralRules::Keyword::Other));
@ -164,7 +164,7 @@ TEST(IntlPluralRules, CategoriesHsbOrdinal)
ASSERT_TRUE(catResult.isOk());
auto categories = catResult.unwrap();
ASSERT_EQ(categories.size(), 1u);
ASSERT_EQ(categories.size(), 1);
ASSERT_TRUE(categories.contains(PluralRules::Keyword::Other));
}

View File

@ -29,7 +29,7 @@ class Array {
using ElementType = T;
static constexpr size_t Length = _Length;
constexpr Array() = default;
Array() = default;
template <typename... Args>
MOZ_IMPLICIT constexpr Array(Args&&... aArgs)

View File

@ -8,8 +8,6 @@
#define mozilla_BitSet_h
#include "mozilla/Array.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/PodOperations.h"
#include "mozilla/Span.h"
@ -30,18 +28,10 @@ class BitSet {
private:
static constexpr size_t kBitsPerWord = 8 * sizeof(Word);
static constexpr size_t kNumWords = (N + kBitsPerWord - 1) / kBitsPerWord;
static constexpr size_t kPaddingBits = (kNumWords * kBitsPerWord) - N;
static constexpr Word kPaddingMask = Word(-1) >> kPaddingBits;
// The zeroth bit in the bitset is the least significant bit of mStorage[0].
Array<Word, kNumWords> mStorage;
constexpr void ResetPaddingBits() {
if constexpr (kPaddingBits != 0) {
mStorage[kNumWords - 1] &= kPaddingMask;
}
}
public:
class Reference {
public:
@ -62,7 +52,7 @@ class BitSet {
size_t mPos;
};
constexpr BitSet() : mStorage() {}
BitSet() { ResetAll(); }
BitSet(const BitSet& aOther) { *this = aOther; }
@ -82,17 +72,6 @@ class BitSet {
return mStorage[aPos / kBitsPerWord] & (Word(1) << (aPos % kBitsPerWord));
}
constexpr bool IsEmpty() const {
for (const Word& word : mStorage) {
if (word) {
return false;
}
}
return true;
}
explicit constexpr operator bool() { return !IsEmpty(); }
constexpr bool operator[](size_t aPos) const { return Test(aPos); }
Reference operator[](size_t aPos) {
@ -113,58 +92,17 @@ class BitSet {
return *this;
}
BitSet operator~() const {
BitSet result = *this;
result.Flip();
return result;
}
BitSet& operator&=(const BitSet<N, Word>& aOther) {
for (size_t i = 0; i < ArrayLength(mStorage); i++) {
mStorage[i] &= aOther.mStorage[i];
}
return *this;
}
BitSet operator&(const BitSet<N, Word>& aOther) const {
BitSet result = *this;
result &= aOther;
return result;
}
bool operator==(const BitSet<N, Word>& aOther) const {
return mStorage == aOther.mStorage;
}
size_t Count() const {
size_t count = 0;
for (const Word& word : mStorage) {
if constexpr (kBitsPerWord > 32) {
count += CountPopulation64(word);
} else {
count += CountPopulation32(word);
}
}
return count;
}
// Set all bits to false.
void ResetAll() { PodArrayZero(mStorage); }
// Set all bits to true.
void SetAll() {
memset(mStorage.begin(), 0xff, kNumWords * sizeof(Word));
ResetPaddingBits();
}
void Flip() {
for (Word& word : mStorage) {
word = ~word;
constexpr size_t paddingBits = (kNumWords * kBitsPerWord) - N;
constexpr Word paddingMask = Word(-1) >> paddingBits;
if constexpr (paddingBits != 0) {
mStorage[kNumWords - 1] &= paddingMask;
}
ResetPaddingBits();
}
Span<Word> Storage() { return mStorage; }

View File

@ -11,7 +11,6 @@
#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/MathAlgorithms.h"
#include <initializer_list>
#include <type_traits>
@ -23,16 +22,15 @@ namespace mozilla {
/**
* EnumSet<T, U> is a set of values defined by an enumeration. It is implemented
* using a bit mask with the size of U for each value. It works both for enum
* and enum class types. EnumSet also works with U being a BitSet.
* and enum class types.
*/
template <typename T, typename Serialized = typename std::make_unsigned<
typename std::underlying_type<T>::type>::type>
class EnumSet {
public:
using valueType = T;
using serializedType = Serialized;
typedef T valueType;
constexpr EnumSet() : mBitField() {}
constexpr EnumSet() : mBitField(0) {}
constexpr MOZ_IMPLICIT EnumSet(T aEnum) : mBitField(bitFor(aEnum)) {}
@ -46,7 +44,7 @@ class EnumSet {
: mBitField(bitFor(aEnum1) | bitFor(aEnum2) | bitFor(aEnum3) |
bitFor(aEnum4)) {}
constexpr MOZ_IMPLICIT EnumSet(std::initializer_list<T> list) : mBitField() {
constexpr MOZ_IMPLICIT EnumSet(std::initializer_list<T> list) : mBitField(0) {
for (auto value : list) {
(*this) += value;
}
@ -135,7 +133,7 @@ class EnumSet {
*/
void clear() {
incVersion();
mBitField = Serialized();
mBitField = 0;
}
/**
@ -182,9 +180,7 @@ class EnumSet {
/**
* Test is an element is contained in the set.
*/
bool contains(T aEnum) const {
return static_cast<bool>(mBitField & bitFor(aEnum));
}
bool contains(T aEnum) const { return mBitField & bitFor(aEnum); }
/**
* Test if a set is contained in the set.
@ -196,25 +192,17 @@ class EnumSet {
/**
* Return the number of elements in the set.
*/
size_t size() const {
if constexpr (std::is_unsigned_v<Serialized>) {
if constexpr (kMaxBits > 32) {
return CountPopulation64(mBitField);
} else {
return CountPopulation32(mBitField);
uint8_t size() const {
uint8_t count = 0;
for (Serialized bitField = mBitField; bitField; bitField >>= 1) {
if (bitField & 1) {
count++;
}
} else {
return mBitField.Count();
}
return count;
}
bool isEmpty() const {
if constexpr (std::is_unsigned_v<Serialized>) {
return mBitField == 0;
} else {
return mBitField.IsEmpty();
}
}
bool isEmpty() const { return mBitField == 0; }
Serialized serialize() const { return mBitField; }
@ -242,9 +230,7 @@ class EnumSet {
mVersion = mSet->mVersion;
#endif
MOZ_ASSERT(aPos <= kMaxBits);
if (aPos != kMaxBits && !mSet->contains(T(mPos))) {
++*this;
}
if (aPos != kMaxBits && !mSet->contains(T(mPos))) ++*this;
}
ConstIterator(const ConstIterator& aOther)
@ -301,15 +287,9 @@ class EnumSet {
private:
constexpr static Serialized bitFor(T aEnum) {
auto bitNumber = static_cast<size_t>(aEnum);
auto bitNumber = static_cast<Serialized>(aEnum);
MOZ_DIAGNOSTIC_ASSERT(bitNumber < kMaxBits);
if constexpr (std::is_unsigned_v<Serialized>) {
return static_cast<Serialized>(Serialized{1} << bitNumber);
} else {
Serialized bitField;
bitField[bitNumber] = true;
return bitField;
}
return static_cast<Serialized>(Serialized{1} << bitNumber);
}
constexpr void incVersion() {
@ -318,15 +298,7 @@ class EnumSet {
#endif
}
constexpr size_t MaxBits() const {
if constexpr (std::is_unsigned_v<Serialized>) {
return sizeof(Serialized) * 8;
} else {
return mBitField.Size();
}
};
static constexpr size_t kMaxBits = EnumSet().MaxBits();
static const size_t kMaxBits = sizeof(Serialized) * 8;
Serialized mBitField;

View File

@ -4,114 +4,65 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/Assertions.h"
#include "mozilla/BitSet.h"
using mozilla::BitSet;
template <typename Storage>
class BitSetSuite {
template <size_t N>
using TestBitSet = BitSet<N, Storage>;
// Work around issue with commas in macro use.
template <size_t N>
using BitSetUint8 = BitSet<N, uint8_t>;
template <size_t N>
using BitSetUint32 = BitSet<N, uint32_t>;
static constexpr size_t kBitsPerWord = sizeof(Storage) * 8;
void TestBitSet() {
MOZ_RELEASE_ASSERT(BitSetUint8<1>().Storage().LengthBytes() == 1);
MOZ_RELEASE_ASSERT(BitSetUint32<1>().Storage().LengthBytes() == 4);
static constexpr Storage kAllBitsSet = ~Storage{0};
MOZ_RELEASE_ASSERT(BitSetUint8<1>().Storage().Length() == 1);
MOZ_RELEASE_ASSERT(BitSetUint8<8>().Storage().Length() == 1);
MOZ_RELEASE_ASSERT(BitSetUint8<9>().Storage().Length() == 2);
public:
void testLength() {
MOZ_RELEASE_ASSERT(TestBitSet<1>().Storage().LengthBytes() ==
sizeof(Storage));
MOZ_RELEASE_ASSERT(BitSetUint32<1>().Storage().Length() == 1);
MOZ_RELEASE_ASSERT(BitSetUint32<32>().Storage().Length() == 1);
MOZ_RELEASE_ASSERT(BitSetUint32<33>().Storage().Length() == 2);
MOZ_RELEASE_ASSERT(TestBitSet<1>().Storage().Length() == 1);
MOZ_RELEASE_ASSERT(TestBitSet<kBitsPerWord>().Storage().Length() == 1);
MOZ_RELEASE_ASSERT(TestBitSet<kBitsPerWord + 1>().Storage().Length() == 2);
BitSetUint8<10> bitset;
MOZ_RELEASE_ASSERT(!bitset.Test(3));
MOZ_RELEASE_ASSERT(!bitset[3]);
bitset[3] = true;
MOZ_RELEASE_ASSERT(bitset.Test(3));
MOZ_RELEASE_ASSERT(bitset[3]);
bitset.ResetAll();
for (size_t i = 0; i < bitset.Size(); i++) {
MOZ_RELEASE_ASSERT(!bitset[i]);
}
void testConstruct() {
MOZ_RELEASE_ASSERT(TestBitSet<1>().Storage()[0] == 0);
MOZ_RELEASE_ASSERT(TestBitSet<kBitsPerWord>().Storage()[0] == 0);
MOZ_RELEASE_ASSERT(TestBitSet<kBitsPerWord + 1>().Storage()[0] == 0);
MOZ_RELEASE_ASSERT(TestBitSet<kBitsPerWord + 1>().Storage()[1] == 0);
TestBitSet<1> bitset1;
bitset1.SetAll();
TestBitSet<kBitsPerWord> bitsetW;
bitsetW.SetAll();
TestBitSet<kBitsPerWord + 1> bitsetW1;
bitsetW1.SetAll();
MOZ_RELEASE_ASSERT(bitset1.Storage()[0] == 1);
MOZ_RELEASE_ASSERT(bitsetW.Storage()[0] == kAllBitsSet);
MOZ_RELEASE_ASSERT(bitsetW1.Storage()[0] == kAllBitsSet);
MOZ_RELEASE_ASSERT(bitsetW1.Storage()[1] == 1);
MOZ_RELEASE_ASSERT(TestBitSet<1>(bitset1).Storage()[0] == 1);
MOZ_RELEASE_ASSERT(TestBitSet<kBitsPerWord>(bitsetW).Storage()[0] ==
kAllBitsSet);
MOZ_RELEASE_ASSERT(TestBitSet<kBitsPerWord + 1>(bitsetW1).Storage()[0] ==
kAllBitsSet);
MOZ_RELEASE_ASSERT(TestBitSet<kBitsPerWord + 1>(bitsetW1).Storage()[1] ==
1);
MOZ_RELEASE_ASSERT(TestBitSet<1>(bitset1.Storage()).Storage()[0] == 1);
MOZ_RELEASE_ASSERT(
TestBitSet<kBitsPerWord>(bitsetW.Storage()).Storage()[0] ==
kAllBitsSet);
MOZ_RELEASE_ASSERT(
TestBitSet<kBitsPerWord + 1>(bitsetW1.Storage()).Storage()[0] ==
kAllBitsSet);
MOZ_RELEASE_ASSERT(
TestBitSet<kBitsPerWord + 1>(bitsetW1.Storage()).Storage()[1] == 1);
bitset.SetAll();
for (size_t i = 0; i < bitset.Size(); i++) {
MOZ_RELEASE_ASSERT(bitset[i]);
}
void testSetBit() {
TestBitSet<kBitsPerWord + 2> bitset;
MOZ_RELEASE_ASSERT(!bitset.Test(3));
MOZ_RELEASE_ASSERT(!bitset[3]);
MOZ_RELEASE_ASSERT(!bitset.Test(kBitsPerWord + 1));
MOZ_RELEASE_ASSERT(!bitset[kBitsPerWord + 1]);
bitset[3] = true;
MOZ_RELEASE_ASSERT(bitset.Test(3));
MOZ_RELEASE_ASSERT(bitset[3]);
bitset[kBitsPerWord + 1] = true;
MOZ_RELEASE_ASSERT(bitset.Test(3));
MOZ_RELEASE_ASSERT(bitset[3]);
MOZ_RELEASE_ASSERT(bitset.Test(kBitsPerWord + 1));
MOZ_RELEASE_ASSERT(bitset[kBitsPerWord + 1]);
bitset.ResetAll();
for (size_t i = 0; i < bitset.Size(); i++) {
MOZ_RELEASE_ASSERT(!bitset[i]);
}
bitset.SetAll();
for (size_t i = 0; i < bitset.Size(); i++) {
MOZ_RELEASE_ASSERT(bitset[i]);
}
// Test trailing unused bits are not set by SetAll().
MOZ_RELEASE_ASSERT(bitset.Storage()[1] == 3);
bitset.ResetAll();
for (size_t i = 0; i < bitset.Size(); i++) {
MOZ_RELEASE_ASSERT(!bitset[i]);
}
bitset.ResetAll();
for (size_t i = 0; i < bitset.Size(); i++) {
MOZ_RELEASE_ASSERT(!bitset[i]);
}
void runTests() {
testLength();
testConstruct();
testSetBit();
// Test trailing unused bits are not set by SetAll().
bitset.SetAll();
BitSetUint8<16> bitset2(bitset.Storage());
MOZ_RELEASE_ASSERT(bitset.Size() < bitset2.Size());
MOZ_RELEASE_ASSERT(bitset.Storage().Length() == bitset2.Storage().Length());
for (size_t i = 0; i < bitset.Size(); i++) {
MOZ_RELEASE_ASSERT(bitset2[i]);
}
};
for (size_t i = bitset.Size(); i < bitset2.Size(); i++) {
MOZ_RELEASE_ASSERT(!bitset2[i]);
}
}
int main() {
BitSetSuite<uint8_t>().runTests();
BitSetSuite<uint32_t>().runTests();
BitSetSuite<uint64_t>().runTests();
TestBitSet();
return 0;
}

View File

@ -4,7 +4,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/BitSet.h"
#include "mozilla/EnumSet.h"
#include "mozilla/Vector.h"
@ -32,9 +31,7 @@ enum SeaBird {
GULL,
TERN,
SKIMMER,
AUK,
SEA_BIRD_COUNT
AUK
};
enum class SmallEnum : uint8_t {
@ -47,12 +44,8 @@ enum class BigEnum : uint64_t {
Bar = 35,
};
template <typename Storage = typename std::make_unsigned<
typename std::underlying_type<SeaBird>::type>::type>
class EnumSetSuite {
public:
using EnumSetSeaBird = EnumSet<SeaBird, Storage>;
EnumSetSuite()
: mAlcidae(),
mDiomedeidae(ALBATROSS),
@ -124,7 +117,7 @@ class EnumSetSuite {
}
void testCopy() {
EnumSetSeaBird likes = mPetrels;
EnumSet<SeaBird> likes = mPetrels;
likes -= TRUE_PETREL;
MOZ_RELEASE_ASSERT(mPetrels.size() == 4);
MOZ_RELEASE_ASSERT(mPetrels.contains(TRUE_PETREL));
@ -136,7 +129,7 @@ class EnumSetSuite {
}
void testAddTo() {
EnumSetSeaBird seen = mPetrels;
EnumSet<SeaBird> seen = mPetrels;
seen += CORMORANT;
seen += TRUE_PETREL;
MOZ_RELEASE_ASSERT(mPetrels.size() == 4);
@ -150,7 +143,7 @@ class EnumSetSuite {
}
void testAdd() {
EnumSetSeaBird seen = mPetrels + CORMORANT + STORM_PETREL;
EnumSet<SeaBird> seen = mPetrels + CORMORANT + STORM_PETREL;
MOZ_RELEASE_ASSERT(mPetrels.size() == 4);
MOZ_RELEASE_ASSERT(!mPetrels.contains(CORMORANT));
MOZ_RELEASE_ASSERT(seen.size() == 5);
@ -162,13 +155,13 @@ class EnumSetSuite {
}
void testAddAll() {
EnumSetSeaBird procellariidae;
EnumSet<SeaBird> procellariidae;
procellariidae += mPetrelProcellariidae;
procellariidae += mNonPetrelProcellariidae;
MOZ_RELEASE_ASSERT(procellariidae.size() == 5);
// Both procellariidae and mPetrels include GADFLY_PERTEL and TRUE_PETREL
EnumSetSeaBird procellariiformes;
EnumSet<SeaBird> procellariiformes;
procellariiformes += mDiomedeidae;
procellariiformes += procellariidae;
procellariiformes += mPetrels;
@ -176,17 +169,18 @@ class EnumSetSuite {
}
void testUnion() {
EnumSetSeaBird procellariidae =
EnumSet<SeaBird> procellariidae =
mPetrelProcellariidae + mNonPetrelProcellariidae;
MOZ_RELEASE_ASSERT(procellariidae.size() == 5);
// Both procellariidae and mPetrels include GADFLY_PETREL and TRUE_PETREL
EnumSetSeaBird procellariiformes = mDiomedeidae + procellariidae + mPetrels;
EnumSet<SeaBird> procellariiformes =
mDiomedeidae + procellariidae + mPetrels;
MOZ_RELEASE_ASSERT(procellariiformes.size() == 8);
}
void testRemoveFrom() {
EnumSetSeaBird likes = mPetrels;
EnumSet<SeaBird> likes = mPetrels;
likes -= TRUE_PETREL;
likes -= DIVING_PETREL;
MOZ_RELEASE_ASSERT(likes.size() == 2);
@ -195,14 +189,14 @@ class EnumSetSuite {
}
void testRemove() {
EnumSetSeaBird likes = mPetrels - TRUE_PETREL - DIVING_PETREL;
EnumSet<SeaBird> likes = mPetrels - TRUE_PETREL - DIVING_PETREL;
MOZ_RELEASE_ASSERT(likes.size() == 2);
MOZ_RELEASE_ASSERT(likes.contains(GADFLY_PETREL));
MOZ_RELEASE_ASSERT(likes.contains(STORM_PETREL));
}
void testRemoveAllFrom() {
EnumSetSeaBird likes = mPetrels;
EnumSet<SeaBird> likes = mPetrels;
likes -= mPetrelProcellariidae;
MOZ_RELEASE_ASSERT(likes.size() == 2);
MOZ_RELEASE_ASSERT(likes.contains(DIVING_PETREL));
@ -210,14 +204,14 @@ class EnumSetSuite {
}
void testRemoveAll() {
EnumSetSeaBird likes = mPetrels - mPetrelProcellariidae;
EnumSet<SeaBird> likes = mPetrels - mPetrelProcellariidae;
MOZ_RELEASE_ASSERT(likes.size() == 2);
MOZ_RELEASE_ASSERT(likes.contains(DIVING_PETREL));
MOZ_RELEASE_ASSERT(likes.contains(STORM_PETREL));
}
void testIntersect() {
EnumSetSeaBird likes = mPetrels;
EnumSet<SeaBird> likes = mPetrels;
likes &= mPetrelProcellariidae;
MOZ_RELEASE_ASSERT(likes.size() == 2);
MOZ_RELEASE_ASSERT(likes.contains(GADFLY_PETREL));
@ -225,19 +219,19 @@ class EnumSetSuite {
}
void testInsersection() {
EnumSetSeaBird likes = mPetrels & mPetrelProcellariidae;
EnumSet<SeaBird> likes = mPetrels & mPetrelProcellariidae;
MOZ_RELEASE_ASSERT(likes.size() == 2);
MOZ_RELEASE_ASSERT(likes.contains(GADFLY_PETREL));
MOZ_RELEASE_ASSERT(likes.contains(TRUE_PETREL));
}
void testEquality() {
EnumSetSeaBird likes = mPetrels & mPetrelProcellariidae;
MOZ_RELEASE_ASSERT(likes == EnumSetSeaBird(GADFLY_PETREL, TRUE_PETREL));
EnumSet<SeaBird> likes = mPetrels & mPetrelProcellariidae;
MOZ_RELEASE_ASSERT(likes == EnumSet<SeaBird>(GADFLY_PETREL, TRUE_PETREL));
}
void testDuplicates() {
EnumSetSeaBird likes = mPetrels;
EnumSet<SeaBird> likes = mPetrels;
likes += GADFLY_PETREL;
likes += TRUE_PETREL;
likes += DIVING_PETREL;
@ -247,7 +241,7 @@ class EnumSetSuite {
}
void testIteration() {
EnumSetSeaBird birds;
EnumSet<SeaBird> birds;
Vector<SeaBird> vec;
for (auto bird : birds) {
@ -271,11 +265,10 @@ class EnumSetSuite {
}
void testInitializerListConstuctor() {
EnumSetSeaBird empty{};
EnumSet<SeaBird> empty{};
MOZ_RELEASE_ASSERT(empty.size() == 0);
MOZ_RELEASE_ASSERT(empty.isEmpty());
EnumSetSeaBird someBirds{SKIMMER, GULL, BOOBY};
EnumSet<SeaBird> someBirds{SKIMMER, GULL, BOOBY};
MOZ_RELEASE_ASSERT(someBirds.size() == 3);
MOZ_RELEASE_ASSERT(someBirds.contains(SKIMMER));
MOZ_RELEASE_ASSERT(someBirds.contains(GULL));
@ -289,18 +282,15 @@ class EnumSetSuite {
(uint64_t(1) << uint64_t(BigEnum::Bar)));
}
EnumSetSeaBird mAlcidae;
EnumSetSeaBird mDiomedeidae;
EnumSetSeaBird mPetrelProcellariidae;
EnumSetSeaBird mNonPetrelProcellariidae;
EnumSetSeaBird mPetrels;
EnumSet<SeaBird> mAlcidae;
EnumSet<SeaBird> mDiomedeidae;
EnumSet<SeaBird> mPetrelProcellariidae;
EnumSet<SeaBird> mNonPetrelProcellariidae;
EnumSet<SeaBird> mPetrels;
};
int main() {
EnumSetSuite suite1;
suite1.runTests();
EnumSetSuite<BitSet<SEA_BIRD_COUNT>> suite2;
suite2.runTests();
EnumSetSuite suite;
suite.runTests();
return 0;
}