mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
AdBlockSearchTree: Save few string allocations on searching
This commit is contained in:
parent
511ef3c346
commit
d73d4f7ad7
@ -69,16 +69,18 @@ bool AdBlockSearchTree::add(const AdBlockRule* rule)
|
|||||||
return true;
|
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) {
|
if (len <= 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QChar* string = urlString.constData();
|
||||||
|
|
||||||
for (int i = 0; i < len; ++i) {
|
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) {
|
if (rule) {
|
||||||
return rule;
|
return rule;
|
||||||
}
|
}
|
||||||
@ -87,15 +89,13 @@ const AdBlockRule* AdBlockSearchTree::find(const QNetworkRequest &request, const
|
|||||||
return 0;
|
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) {
|
if (len <= 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QChar c = string.at(0);
|
QChar c = string[0];
|
||||||
|
|
||||||
if (!m_root->children.contains(c)) {
|
if (!m_root->children.contains(c)) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -104,7 +104,7 @@ const AdBlockRule* AdBlockSearchTree::prefixSearch(const QNetworkRequest &reques
|
|||||||
Node* node = m_root->children[c];
|
Node* node = m_root->children[c];
|
||||||
|
|
||||||
for (int i = 1; i < len; ++i) {
|
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)) {
|
if (node->rule && node->rule->networkMatch(request, domain, urlString)) {
|
||||||
return node->rule;
|
return node->rule;
|
||||||
|
@ -36,7 +36,7 @@ public:
|
|||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
bool add(const AdBlockRule* rule);
|
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:
|
private:
|
||||||
struct Node {
|
struct Node {
|
||||||
@ -48,7 +48,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
const AdBlockRule* prefixSearch(const QNetworkRequest &request, const QString &domain,
|
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);
|
void deleteNode(Node* node);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user