summaryrefslogtreecommitdiff
path: root/src/adblock/adblockmanager.cpp
diff options
context:
space:
mode:
authorBenjamin Poulain <benjamin.poulain@nokia.com>2010-08-18 23:41:05 +0200
committerBenjamin Poulain <benjamin.poulain@nokia.com>2010-08-19 03:18:29 +0200
commite5815346cd4870640051856abed0887717aa0bf7 (patch)
tree7ff7d8a66d1febfcc793dbe67c9d3d182ab05977 /src/adblock/adblockmanager.cpp
parentMerge commit 'refs/merge-requests/178' of git://gitorious.org/rekonq/mainline... (diff)
downloadrekonq-e5815346cd4870640051856abed0887717aa0bf7.tar.xz
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.
Diffstat (limited to 'src/adblock/adblockmanager.cpp')
-rw-r--r--src/adblock/adblockmanager.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp
index 644ecff5..e0a109f0 100644
--- a/src/adblock/adblockmanager.cpp
+++ b/src/adblock/adblockmanager.cpp
@@ -161,11 +161,14 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *pa
return 0;
QString urlString = request.url().toString();
+ // We compute a lowercase version of the URL so each rule does not
+ // have to do it.
+ const QString urlStringLowerCase = urlString.toLower();
// check white rules before :)
foreach(const AdBlockRule &filter, _whiteList)
{
- if (filter.match(urlString))
+ if (filter.match(urlString, urlStringLowerCase))
{
kDebug() << "****ADBLOCK: WHITE RULE (@@) Matched: ***********";
kDebug() << "UrlString: " << urlString;
@@ -176,7 +179,7 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *pa
// then check the black ones :(
foreach(const AdBlockRule &filter, _blackList)
{
- if (filter.match(urlString))
+ if (filter.match(urlString, urlStringLowerCase))
{
kDebug() << "****ADBLOCK: BLACK RULE Matched: ***********";
kDebug() << "UrlString: " << urlString;
@@ -185,7 +188,8 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *pa
QWebElementCollection elements = document.findAll("*");
foreach(QWebElement el, elements)
{
- if (filter.match(el.attribute("src")))
+ const QString srcAttribute = el.attribute("src");
+ if (filter.match(srcAttribute, srcAttribute.toLower()))
{
kDebug() << "MATCHES ATTRIBUTE!!!!!";
el.setStyleProperty(QL1S("visibility"), QL1S("hidden"));