diff --git a/dom/base/FragmentOrElement.cpp b/dom/base/FragmentOrElement.cpp index 86d408662fb2..c284cb19fef7 100644 --- a/dom/base/FragmentOrElement.cpp +++ b/dom/base/FragmentOrElement.cpp @@ -1793,7 +1793,7 @@ static inline bool IsVoidTag(nsAtom* aTag) { nsGkAtoms::link, nsGkAtoms::meta, nsGkAtoms::param, nsGkAtoms::source, nsGkAtoms::track, nsGkAtoms::wbr}; - static mozilla::BloomFilter<12, nsAtom> sFilter; + static mozilla::CountingBloomFilter<12, nsAtom> sFilter; static bool sInitialized = false; if (!sInitialized) { sInitialized = true; diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index d21562726d58..e7eedf587c3b 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -8879,7 +8879,7 @@ static inline bool ShouldEscape(nsIContent* aParent) { nsGkAtoms::style, nsGkAtoms::script, nsGkAtoms::xmp, nsGkAtoms::iframe, nsGkAtoms::noembed, nsGkAtoms::noframes, nsGkAtoms::plaintext, nsGkAtoms::noscript}; - static mozilla::BloomFilter<12, nsAtom> sFilter; + static mozilla::CountingBloomFilter<12, nsAtom> sFilter; static bool sInitialized = false; if (!sInitialized) { sInitialized = true; diff --git a/dom/base/nsDOMTokenList.cpp b/dom/base/nsDOMTokenList.cpp index eed8fda232b4..1c3af78b4daf 100644 --- a/dom/base/nsDOMTokenList.cpp +++ b/dom/base/nsDOMTokenList.cpp @@ -73,7 +73,7 @@ void nsDOMTokenList::RemoveDuplicates(const nsAttrValue* aAttr) { return; } - BloomFilter<8, nsAtom> filter; + CountingBloomFilter<8, nsAtom> filter; AtomArray* array = aAttr->GetAtomArrayValue(); for (uint32_t i = 0; i < array->Length(); i++) { nsAtom* atom = array->ElementAt(i); diff --git a/mfbt/BloomFilter.h b/mfbt/BloomFilter.h index 06c7143e03f9..54998e2127f5 100644 --- a/mfbt/BloomFilter.h +++ b/mfbt/BloomFilter.h @@ -53,7 +53,7 @@ namespace mozilla { */ template -class BloomFilter { +class CountingBloomFilter { /* * A counting Bloom filter with 8-bit counters. For now we assume * that having two hash functions is enough, but we may revisit that @@ -103,7 +103,7 @@ class BloomFilter { * rates for larger N. */ public: - BloomFilter() { + CountingBloomFilter() { static_assert(KeySize <= kKeyShift, "KeySize too big"); // Should we have a custom operator new using calloc instead and @@ -169,12 +169,12 @@ class BloomFilter { }; template -inline void BloomFilter::clear() { +inline void CountingBloomFilter::clear() { memset(mCounters, 0, kArraySize); } template -inline void BloomFilter::add(uint32_t aHash) { +inline void CountingBloomFilter::add(uint32_t aHash) { uint8_t& slot1 = firstSlot(aHash); if (MOZ_LIKELY(!full(slot1))) { ++slot1; @@ -186,13 +186,13 @@ inline void BloomFilter::add(uint32_t aHash) { } template -MOZ_ALWAYS_INLINE void BloomFilter::add(const T* aValue) { +MOZ_ALWAYS_INLINE void CountingBloomFilter::add(const T* aValue) { uint32_t hash = aValue->hash(); return add(hash); } template -inline void BloomFilter::remove(uint32_t aHash) { +inline void CountingBloomFilter::remove(uint32_t aHash) { // If the slots are full, we don't know whether we bumped them to be // there when we added or not, so just leave them full. uint8_t& slot1 = firstSlot(aHash); @@ -206,20 +206,21 @@ inline void BloomFilter::remove(uint32_t aHash) { } template -MOZ_ALWAYS_INLINE void BloomFilter::remove(const T* aValue) { +MOZ_ALWAYS_INLINE void CountingBloomFilter::remove( + const T* aValue) { uint32_t hash = aValue->hash(); remove(hash); } template -MOZ_ALWAYS_INLINE bool BloomFilter::mightContain( +MOZ_ALWAYS_INLINE bool CountingBloomFilter::mightContain( uint32_t aHash) const { // Check that all the slots for this hash contain something return firstSlot(aHash) && secondSlot(aHash); } template -MOZ_ALWAYS_INLINE bool BloomFilter::mightContain( +MOZ_ALWAYS_INLINE bool CountingBloomFilter::mightContain( const T* aValue) const { uint32_t hash = aValue->hash(); return mightContain(hash); diff --git a/mfbt/tests/TestBloomFilter.cpp b/mfbt/tests/TestBloomFilter.cpp index e3dfa27b9efd..729edc7b2e65 100644 --- a/mfbt/tests/TestBloomFilter.cpp +++ b/mfbt/tests/TestBloomFilter.cpp @@ -6,11 +6,12 @@ #include "mozilla/Assertions.h" #include "mozilla/BloomFilter.h" +#include "mozilla/UniquePtr.h" #include #include -using mozilla::BloomFilter; +using mozilla::CountingBloomFilter; class FilterChecker { public: @@ -23,7 +24,8 @@ class FilterChecker { }; int main() { - BloomFilter<12, FilterChecker>* filter = new BloomFilter<12, FilterChecker>(); + const mozilla::UniquePtr filter = + mozilla::MakeUnique>(); MOZ_RELEASE_ASSERT(filter); FilterChecker one(1);