Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 8808df6c authored by Laurent Montel's avatar Laurent Montel 😁

Minor optimization

parent 2c663247
......@@ -124,14 +124,19 @@ void AdblockManager::save()
}
}
QStringList AdblockManager::disabledRules() const
{
return mDisabledRules;
}
void AdblockManager::removeDisabledRule(const QString &filter)
{
//TODO
mDisabledRules.removeOne(filter);
}
void AdblockManager::addDisabledRule(const QString &filter)
{
//TODO
mDisabledRules.append(filter);
}
bool AdblockManager::isEnabled() const
......
......@@ -43,6 +43,9 @@ public:
void removeDisabledRule(const QString &filter);
void save();
Q_REQUIRED_RESULT QStringList disabledRules() const;
Q_SIGNALS:
void enabledChanged(bool);
......@@ -54,6 +57,7 @@ private:
bool canRunOnScheme(const QString &scheme) const;
bool mEnabled;
AdBlockMatcher *mAdBlockMatcher = nullptr;
QStringList mDisabledRules;
QList<AdBlockSubscription *> mSubscriptions;
};
}
......
......@@ -71,14 +71,15 @@ bool AdBlockSearchTree::add(const AdBlockRule *rule)
for (int i = 0; i < len; ++i) {
const QChar c = filter.at(i);
if (!node->children.contains(c)) {
Node *n = new Node;
n->c = c;
Node *next = node->children.value(c);
if (!next) {
next = new Node;
next->c = c;
node->children[c] = n;
node->children[c] = next;
}
node = node->children[c];
node = next;
}
node->rule = rule;
......@@ -91,7 +92,7 @@ const AdBlockRule *AdBlockSearchTree::find(const QWebEngineUrlRequestInfo &reque
int len = urlString.size();
if (len <= 0) {
return 0;
return nullptr;
}
const QChar *string = urlString.constData();
......@@ -103,7 +104,7 @@ const AdBlockRule *AdBlockSearchTree::find(const QWebEngineUrlRequestInfo &reque
}
}
return 0;
return nullptr;
}
const AdBlockRule *AdBlockSearchTree::prefixSearch(const QWebEngineUrlRequestInfo &request, const QString &domain, const QString &urlString, const QChar *string, int len) const
......@@ -113,25 +114,21 @@ const AdBlockRule *AdBlockSearchTree::prefixSearch(const QWebEngineUrlRequestInf
}
QChar c = string[0];
Node* node = m_root->children.value(c);
if (!m_root->children.contains(c)) {
if (!node) {
return nullptr;
}
Node *node = m_root->children[c];
for (int i = 1; i < len; ++i) {
const QChar c = (++string)[0];
if (node->rule && node->rule->networkMatch(request, domain, urlString)) {
return node->rule;
}
if (!node->children.contains(c)) {
node = node->children.value(c);
if (!node) {
return nullptr;
}
node = node->children[c];
}
if (node->rule && node->rule->networkMatch(request, domain, urlString)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment