diff --git a/src/lib/adblock/adblocksearchtree.cpp b/src/lib/adblock/adblocksearchtree.cpp index 2e3c2e648..125e8300e 100644 --- a/src/lib/adblock/adblocksearchtree.cpp +++ b/src/lib/adblock/adblocksearchtree.cpp @@ -69,16 +69,18 @@ bool AdBlockSearchTree::add(const AdBlockRule* rule) return true; } -const AdBlockRule* AdBlockSearchTree::find(const QNetworkRequest &request, const QString &domain, const QString &string) const +const AdBlockRule* AdBlockSearchTree::find(const QNetworkRequest &request, const QString &domain, const QString &urlString) const { - int len = string.size(); + int len = urlString.size(); if (len <= 0) { return 0; } + const QChar* string = urlString.constData(); + for (int i = 0; i < len; ++i) { - const AdBlockRule* rule = prefixSearch(request, domain, string, string.mid(i)); + const AdBlockRule* rule = prefixSearch(request, domain, urlString, string++, len - i); if (rule) { return rule; } @@ -87,15 +89,13 @@ const AdBlockRule* AdBlockSearchTree::find(const QNetworkRequest &request, const return 0; } -const AdBlockRule* AdBlockSearchTree::prefixSearch(const QNetworkRequest &request, const QString &domain, const QString &urlString, const QString &string) const +const AdBlockRule* AdBlockSearchTree::prefixSearch(const QNetworkRequest &request, const QString &domain, const QString &urlString, const QChar* string, int len) const { - int len = string.size(); - if (len <= 0) { return 0; } - QChar c = string.at(0); + QChar c = string[0]; if (!m_root->children.contains(c)) { return 0; @@ -104,7 +104,7 @@ const AdBlockRule* AdBlockSearchTree::prefixSearch(const QNetworkRequest &reques Node* node = m_root->children[c]; for (int i = 1; i < len; ++i) { - const QChar &c = string.at(i); + const QChar &c = (++string)[0]; if (node->rule && node->rule->networkMatch(request, domain, urlString)) { return node->rule; diff --git a/src/lib/adblock/adblocksearchtree.h b/src/lib/adblock/adblocksearchtree.h index f6b9c4e99..7bdd6f307 100644 --- a/src/lib/adblock/adblocksearchtree.h +++ b/src/lib/adblock/adblocksearchtree.h @@ -36,7 +36,7 @@ public: void clear(); bool add(const AdBlockRule* rule); - const AdBlockRule* find(const QNetworkRequest &request, const QString &domain, const QString &string) const; + const AdBlockRule* find(const QNetworkRequest &request, const QString &domain, const QString &urlString) const; private: struct Node { @@ -48,7 +48,7 @@ private: }; const AdBlockRule* prefixSearch(const QNetworkRequest &request, const QString &domain, - const QString &urlString, const QString &string) const; + const QString &urlString, const QChar* string, int len) const; void deleteNode(Node* node);