Bug 1690274 - Part 1: Rename mozilla::BloomFilter to mozilla::CountingBloomFilter. r=sg

Differential Revision: https://phabricator.services.mozilla.com/D104689
This commit is contained in:
Tooru Fujisawa 2021-02-16 22:07:05 +00:00
Родитель 4e4eb0a952
Коммит b1044551e9
5 изменённых файлов: 17 добавлений и 14 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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);

Просмотреть файл

@ -53,7 +53,7 @@ namespace mozilla {
*/
template <unsigned KeySize, class T>
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 <unsigned KeySize, class T>
inline void BloomFilter<KeySize, T>::clear() {
inline void CountingBloomFilter<KeySize, T>::clear() {
memset(mCounters, 0, kArraySize);
}
template <unsigned KeySize, class T>
inline void BloomFilter<KeySize, T>::add(uint32_t aHash) {
inline void CountingBloomFilter<KeySize, T>::add(uint32_t aHash) {
uint8_t& slot1 = firstSlot(aHash);
if (MOZ_LIKELY(!full(slot1))) {
++slot1;
@ -186,13 +186,13 @@ inline void BloomFilter<KeySize, T>::add(uint32_t aHash) {
}
template <unsigned KeySize, class T>
MOZ_ALWAYS_INLINE void BloomFilter<KeySize, T>::add(const T* aValue) {
MOZ_ALWAYS_INLINE void CountingBloomFilter<KeySize, T>::add(const T* aValue) {
uint32_t hash = aValue->hash();
return add(hash);
}
template <unsigned KeySize, class T>
inline void BloomFilter<KeySize, T>::remove(uint32_t aHash) {
inline void CountingBloomFilter<KeySize, T>::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<KeySize, T>::remove(uint32_t aHash) {
}
template <unsigned KeySize, class T>
MOZ_ALWAYS_INLINE void BloomFilter<KeySize, T>::remove(const T* aValue) {
MOZ_ALWAYS_INLINE void CountingBloomFilter<KeySize, T>::remove(
const T* aValue) {
uint32_t hash = aValue->hash();
remove(hash);
}
template <unsigned KeySize, class T>
MOZ_ALWAYS_INLINE bool BloomFilter<KeySize, T>::mightContain(
MOZ_ALWAYS_INLINE bool CountingBloomFilter<KeySize, T>::mightContain(
uint32_t aHash) const {
// Check that all the slots for this hash contain something
return firstSlot(aHash) && secondSlot(aHash);
}
template <unsigned KeySize, class T>
MOZ_ALWAYS_INLINE bool BloomFilter<KeySize, T>::mightContain(
MOZ_ALWAYS_INLINE bool CountingBloomFilter<KeySize, T>::mightContain(
const T* aValue) const {
uint32_t hash = aValue->hash();
return mightContain(hash);

Просмотреть файл

@ -6,11 +6,12 @@
#include "mozilla/Assertions.h"
#include "mozilla/BloomFilter.h"
#include "mozilla/UniquePtr.h"
#include <stddef.h>
#include <stdio.h>
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<CountingBloomFilter<12, FilterChecker>>();
MOZ_RELEASE_ASSERT(filter);
FilterChecker one(1);