diff --git a/docshell/base/SyncedContext.h b/docshell/base/SyncedContext.h index 34db4fa7b488..90c34dbc6463 100644 --- a/docshell/base/SyncedContext.h +++ b/docshell/base/SyncedContext.h @@ -11,7 +11,6 @@ #include #include #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 using Index = typename std::integral_constant; -template -using IndexSet = EnumSet>; +using IndexSet = EnumSet; template class Transaction { public: - using IndexSet = IndexSet; - // 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. diff --git a/docshell/base/SyncedContextInlines.h b/docshell/base/SyncedContextInlines.h index c822f7f9e572..4ad8b99296ac 100644 --- a/docshell/base/SyncedContextInlines.h +++ b/docshell/base/SyncedContextInlines.h @@ -61,8 +61,7 @@ void FormatFieldValue(nsACString& aStr, const T& aValue) { // a synced context transaction is going to perform. template nsAutoCString FormatTransaction( - typename Transaction::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 -nsCString FormatValidationError( - typename Transaction::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 Transaction::IndexSet Transaction::Validate( - Context* aOwner, ContentParent* aSource) { +IndexSet Transaction::Validate(Context* aOwner, + ContentParent* aSource) { IndexSet failedFields; Transaction revertTxn; @@ -297,7 +295,7 @@ void Transaction::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::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; } diff --git a/intl/components/gtest/TestPluralRules.cpp b/intl/components/gtest/TestPluralRules.cpp index 0058a3786529..95ecb298adc5 100644 --- a/intl/components/gtest/TestPluralRules.cpp +++ b/intl/components/gtest/TestPluralRules.cpp @@ -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)); } diff --git a/mfbt/Array.h b/mfbt/Array.h index 55b724a2882d..45bf916386e9 100644 --- a/mfbt/Array.h +++ b/mfbt/Array.h @@ -29,7 +29,7 @@ class Array { using ElementType = T; static constexpr size_t Length = _Length; - constexpr Array() = default; + Array() = default; template MOZ_IMPLICIT constexpr Array(Args&&... aArgs) diff --git a/mfbt/BitSet.h b/mfbt/BitSet.h index fb4a4ea2195b..2828be418262 100644 --- a/mfbt/BitSet.h +++ b/mfbt/BitSet.h @@ -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 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& aOther) { - for (size_t i = 0; i < ArrayLength(mStorage); i++) { - mStorage[i] &= aOther.mStorage[i]; - } - return *this; - } - - BitSet operator&(const BitSet& aOther) const { - BitSet result = *this; - result &= aOther; - return result; - } - - bool operator==(const BitSet& 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 Storage() { return mStorage; } diff --git a/mfbt/EnumSet.h b/mfbt/EnumSet.h index 929370918e06..f635ec51ffbf 100644 --- a/mfbt/EnumSet.h +++ b/mfbt/EnumSet.h @@ -11,7 +11,6 @@ #include "mozilla/Assertions.h" #include "mozilla/Attributes.h" -#include "mozilla/MathAlgorithms.h" #include #include @@ -23,16 +22,15 @@ namespace mozilla { /** * EnumSet 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 ::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 list) : mBitField() { + constexpr MOZ_IMPLICIT EnumSet(std::initializer_list 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(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) { - 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) { - 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(aEnum); + auto bitNumber = static_cast(aEnum); MOZ_DIAGNOSTIC_ASSERT(bitNumber < kMaxBits); - if constexpr (std::is_unsigned_v) { - return static_cast(Serialized{1} << bitNumber); - } else { - Serialized bitField; - bitField[bitNumber] = true; - return bitField; - } + return static_cast(Serialized{1} << bitNumber); } constexpr void incVersion() { @@ -318,15 +298,7 @@ class EnumSet { #endif } - constexpr size_t MaxBits() const { - if constexpr (std::is_unsigned_v) { - 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; diff --git a/mfbt/tests/TestBitSet.cpp b/mfbt/tests/TestBitSet.cpp index dd491b8dd55c..e8a4a5267fad 100644 --- a/mfbt/tests/TestBitSet.cpp +++ b/mfbt/tests/TestBitSet.cpp @@ -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 -class BitSetSuite { - template - using TestBitSet = BitSet; +// Work around issue with commas in macro use. +template +using BitSetUint8 = BitSet; +template +using BitSetUint32 = BitSet; - 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().Storage().Length() == 1); - MOZ_RELEASE_ASSERT(TestBitSet().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().Storage()[0] == 0); - MOZ_RELEASE_ASSERT(TestBitSet().Storage()[0] == 0); - MOZ_RELEASE_ASSERT(TestBitSet().Storage()[1] == 0); - - TestBitSet<1> bitset1; - bitset1.SetAll(); - TestBitSet bitsetW; - bitsetW.SetAll(); - TestBitSet 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(bitsetW).Storage()[0] == - kAllBitsSet); - MOZ_RELEASE_ASSERT(TestBitSet(bitsetW1).Storage()[0] == - kAllBitsSet); - MOZ_RELEASE_ASSERT(TestBitSet(bitsetW1).Storage()[1] == - 1); - - MOZ_RELEASE_ASSERT(TestBitSet<1>(bitset1.Storage()).Storage()[0] == 1); - MOZ_RELEASE_ASSERT( - TestBitSet(bitsetW.Storage()).Storage()[0] == - kAllBitsSet); - MOZ_RELEASE_ASSERT( - TestBitSet(bitsetW1.Storage()).Storage()[0] == - kAllBitsSet); - MOZ_RELEASE_ASSERT( - TestBitSet(bitsetW1.Storage()).Storage()[1] == 1); + bitset.SetAll(); + for (size_t i = 0; i < bitset.Size(); i++) { + MOZ_RELEASE_ASSERT(bitset[i]); } - void testSetBit() { - TestBitSet 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().runTests(); - BitSetSuite().runTests(); - BitSetSuite().runTests(); - + TestBitSet(); return 0; } diff --git a/mfbt/tests/TestEnumSet.cpp b/mfbt/tests/TestEnumSet.cpp index 2cf5236d03e8..035c1fcfee9a 100644 --- a/mfbt/tests/TestEnumSet.cpp +++ b/mfbt/tests/TestEnumSet.cpp @@ -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 ::type>::type> class EnumSetSuite { public: - using EnumSetSeaBird = EnumSet; - EnumSetSuite() : mAlcidae(), mDiomedeidae(ALBATROSS), @@ -124,7 +117,7 @@ class EnumSetSuite { } void testCopy() { - EnumSetSeaBird likes = mPetrels; + EnumSet 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 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 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 procellariidae; procellariidae += mPetrelProcellariidae; procellariidae += mNonPetrelProcellariidae; MOZ_RELEASE_ASSERT(procellariidae.size() == 5); // Both procellariidae and mPetrels include GADFLY_PERTEL and TRUE_PETREL - EnumSetSeaBird procellariiformes; + EnumSet procellariiformes; procellariiformes += mDiomedeidae; procellariiformes += procellariidae; procellariiformes += mPetrels; @@ -176,17 +169,18 @@ class EnumSetSuite { } void testUnion() { - EnumSetSeaBird procellariidae = + EnumSet 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 procellariiformes = + mDiomedeidae + procellariidae + mPetrels; MOZ_RELEASE_ASSERT(procellariiformes.size() == 8); } void testRemoveFrom() { - EnumSetSeaBird likes = mPetrels; + EnumSet 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 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 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 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 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 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 likes = mPetrels & mPetrelProcellariidae; + MOZ_RELEASE_ASSERT(likes == EnumSet(GADFLY_PETREL, TRUE_PETREL)); } void testDuplicates() { - EnumSetSeaBird likes = mPetrels; + EnumSet likes = mPetrels; likes += GADFLY_PETREL; likes += TRUE_PETREL; likes += DIVING_PETREL; @@ -247,7 +241,7 @@ class EnumSetSuite { } void testIteration() { - EnumSetSeaBird birds; + EnumSet birds; Vector vec; for (auto bird : birds) { @@ -271,11 +265,10 @@ class EnumSetSuite { } void testInitializerListConstuctor() { - EnumSetSeaBird empty{}; + EnumSet empty{}; MOZ_RELEASE_ASSERT(empty.size() == 0); - MOZ_RELEASE_ASSERT(empty.isEmpty()); - EnumSetSeaBird someBirds{SKIMMER, GULL, BOOBY}; + EnumSet 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 mAlcidae; + EnumSet mDiomedeidae; + EnumSet mPetrelProcellariidae; + EnumSet mNonPetrelProcellariidae; + EnumSet mPetrels; }; int main() { - EnumSetSuite suite1; - suite1.runTests(); - - EnumSetSuite> suite2; - suite2.runTests(); + EnumSetSuite suite; + suite.runTests(); return 0; }