1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

AdBlockSearchTree: Save few string allocations on searching

This commit is contained in:
nowrep 2013-11-03 14:49:58 +01:00
parent 511ef3c346
commit d73d4f7ad7
2 changed files with 10 additions and 10 deletions

View File

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

View File

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