Diff
Modified: trunk/Source/WebCore/ChangeLog (290537 => 290538)
--- trunk/Source/WebCore/ChangeLog 2022-02-26 00:27:37 UTC (rev 290537)
+++ trunk/Source/WebCore/ChangeLog 2022-02-26 01:19:30 UTC (rev 290538)
@@ -1,3 +1,25 @@
+2022-02-25 Chris Dumez <[email protected]>
+
+ Use the modern Hasher more in Content Extensions code
+ https://bugs.webkit.org/show_bug.cgi?id=237228
+
+ Reviewed by Darin Adler.
+
+ * contentextensions/CombinedFiltersAlphabet.cpp:
+ (WebCore::ContentExtensions::add):
+ (WebCore::ContentExtensions::TermCreatorTranslator::hash):
+ * contentextensions/CombinedFiltersAlphabet.h:
+ (WebCore::ContentExtensions::CombinedFiltersAlphabet::TermPointerHash::hash):
+ * contentextensions/ContentExtensionRule.h:
+ (WebCore::ContentExtensions::add):
+ (WebCore::ContentExtensions::TriggerHash::hash):
+ * contentextensions/Term.h:
+ (WebCore::ContentExtensions::Term::Group::operator== const):
+ (WebCore::ContentExtensions::add):
+ (WebCore::ContentExtensions::Term::CharacterSet::hash const): Deleted.
+ (WebCore::ContentExtensions::Term::Group::hash const): Deleted.
+ (WebCore::ContentExtensions::Term::hash const): Deleted.
+
2022-02-25 Brandon Stewart <[email protected]>
Do not trigger didFail during FileReaderLoader Destruction
Modified: trunk/Source/WebCore/contentextensions/CombinedFiltersAlphabet.cpp (290537 => 290538)
--- trunk/Source/WebCore/contentextensions/CombinedFiltersAlphabet.cpp 2022-02-26 00:27:37 UTC (rev 290537)
+++ trunk/Source/WebCore/contentextensions/CombinedFiltersAlphabet.cpp 2022-02-26 01:19:30 UTC (rev 290538)
@@ -37,10 +37,15 @@
Vector<std::unique_ptr<Term>>& internedTermsStorage;
};
+inline void add(Hasher& hasher, const TermCreatorInput& input)
+{
+ add(hasher, input.term);
+}
+
struct TermCreatorTranslator {
static unsigned hash(const TermCreatorInput& input)
{
- return input.term.hash();
+ return computeHash(input);
}
static inline bool equal(const Term* term, const TermCreatorInput& input)
Modified: trunk/Source/WebCore/contentextensions/CombinedFiltersAlphabet.h (290537 => 290538)
--- trunk/Source/WebCore/contentextensions/CombinedFiltersAlphabet.h 2022-02-26 00:27:37 UTC (rev 290537)
+++ trunk/Source/WebCore/contentextensions/CombinedFiltersAlphabet.h 2022-02-26 01:19:30 UTC (rev 290538)
@@ -45,7 +45,7 @@
private:
struct TermPointerHash {
- static unsigned hash(const Term* key) { return key->hash(); }
+ static unsigned hash(const Term* key) { return computeHash(*key); }
static inline bool equal(const Term* a, const Term* b)
{
return *a == *b;
Modified: trunk/Source/WebCore/contentextensions/ContentExtensionRule.h (290537 => 290538)
--- trunk/Source/WebCore/contentextensions/ContentExtensionRule.h 2022-02-26 00:27:37 UTC (rev 290537)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionRule.h 2022-02-26 01:19:30 UTC (rev 290538)
@@ -80,10 +80,15 @@
}
};
+inline void add(Hasher& hasher, const Trigger& trigger)
+{
+ add(hasher, trigger.urlFilterIsCaseSensitive, trigger.urlFilter, trigger.flags, trigger.conditions);
+}
+
struct TriggerHash {
static unsigned hash(const Trigger& trigger)
{
- return computeHash(trigger.urlFilterIsCaseSensitive, trigger.urlFilter, trigger.flags, trigger.conditions);
+ return computeHash(trigger);
}
static bool equal(const Trigger& a, const Trigger& b)
{
Modified: trunk/Source/WebCore/contentextensions/Term.h (290537 => 290538)
--- trunk/Source/WebCore/contentextensions/Term.h 2022-02-26 00:27:37 UTC (rev 290537)
+++ trunk/Source/WebCore/contentextensions/Term.h 2022-02-26 01:19:30 UTC (rev 290538)
@@ -100,8 +100,6 @@
bool operator==(const Term& other) const;
- unsigned hash() const;
-
bool isEmptyValue() const;
#if CONTENT_EXTENSIONS_STATE_MACHINE_DEBUGGING
@@ -113,6 +111,8 @@
#endif
private:
+ friend void add(Hasher&, const Term&);
+
// This is exact for character sets but conservative for groups.
// The return value can be false for a group equivalent to a universal transition.
bool isUniversalTransition() const;
@@ -165,15 +165,13 @@
&& other.m_characters[1] == m_characters[1];
}
- unsigned hash() const
- {
- return computeHash(m_inverted, m_characters);
- }
+ private:
+ friend void add(Hasher&, const CharacterSet&);
- private:
bool m_inverted { false };
std::array<uint64_t, 2> m_characters { 0, 0 };
};
+ friend void add(Hasher&, const Term::CharacterSet&);
struct Group {
Vector<Term> terms;
@@ -182,18 +180,8 @@
{
return other.terms == terms;
}
-
- unsigned hash() const
- {
- unsigned hash = 6421749;
- for (const Term& term : terms) {
- unsigned termHash = term.hash();
- hash = (hash << 16) ^ ((termHash << 11) ^ hash);
- hash += hash >> 11;
- }
- return hash;
- }
};
+ friend void add(Hasher&, const Term::Group&);
union AtomData {
AtomData()
@@ -210,6 +198,31 @@
} m_atomData;
};
+inline void add(Hasher& hasher, const Term::CharacterSet& characterSet)
+{
+ add(hasher, characterSet.m_inverted, characterSet.m_characters);
+}
+
+inline void add(Hasher& hasher, const Term::Group& group)
+{
+ add(hasher, group.terms);
+}
+
+inline void add(Hasher& hasher, const Term& term)
+{
+ add(hasher, term.m_termType, term.m_quantifier);
+ switch (term.m_termType) {
+ case Term::TermType::Empty:
+ break;
+ case Term::TermType::CharacterSet:
+ add(hasher, term.m_atomData.characterSet);
+ break;
+ case Term::TermType::Group:
+ add(hasher, term.m_atomData.group);
+ break;
+ }
+}
+
#if CONTENT_EXTENSIONS_STATE_MACHINE_DEBUGGING
inline String quantifierToString(AtomQuantifier quantifier)
{
@@ -542,24 +555,6 @@
return false;
}
-inline unsigned Term::hash() const
-{
- unsigned primary = static_cast<unsigned>(m_termType) << 16 | static_cast<unsigned>(m_quantifier);
- unsigned secondary = 0;
- switch (m_termType) {
- case TermType::Empty:
- secondary = 52184393;
- break;
- case TermType::CharacterSet:
- secondary = m_atomData.characterSet.hash();
- break;
- case TermType::Group:
- secondary = m_atomData.group.hash();
- break;
- }
- return pairIntHash(primary, secondary);
-}
-
inline bool Term::isEmptyValue() const
{
return m_termType == TermType::Empty;