From e5815346cd4870640051856abed0887717aa0bf7 Mon Sep 17 00:00:00 2001 From: Benjamin Poulain Date: Wed, 18 Aug 2010 23:41:05 +0200 Subject: Improve the performance of AdBlockRuleTextMatchImpl Comparing unicode string without case sensitive is rather expensive because each codepoint must be converted, which is non trivial for unicode. This patch introduce a new argument of ::match() taking the encoded url in lowercase. This way, the conversion can be done only once for a lot of rules. --- src/adblock/adblockruletextmatchimpl.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/adblock/adblockruletextmatchimpl.cpp') diff --git a/src/adblock/adblockruletextmatchimpl.cpp b/src/adblock/adblockruletextmatchimpl.cpp index 7c02ea37..892d78e0 100644 --- a/src/adblock/adblockruletextmatchimpl.cpp +++ b/src/adblock/adblockruletextmatchimpl.cpp @@ -34,13 +34,18 @@ AdBlockRuleTextMatchImpl::AdBlockRuleTextMatchImpl(const QString &filter) { Q_ASSERT(AdBlockRuleTextMatchImpl::isTextMatchFilter(filter)); - m_textToMatch = filter; + m_textToMatch = filter.toLower(); m_textToMatch.remove(QL1C('*')); } -bool AdBlockRuleTextMatchImpl::match(const QString &encodedUrl) const +bool AdBlockRuleTextMatchImpl::match(const QString &encodedUrl, const QString &encodedUrlLowerCase) const { - return encodedUrl.contains(m_textToMatch, Qt::CaseInsensitive); + Q_UNUSED(encodedUrl); + // Case sensitive compare is faster, but would be incorrect with encodedUrl since + // we do want case insensitive. + // What we do is work on a lowercase version of m_textToMatch, and compare to the lowercase + // version of encodedUrl. + return encodedUrlLowerCase.contains(m_textToMatch, Qt::CaseSensitive); } bool AdBlockRuleTextMatchImpl::isTextMatchFilter(const QString &filter) -- cgit v1.2.1