mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 09:32:12 +01:00
AdBlockSubscription: Don't allocate search tree on heap.
This commit is contained in:
parent
c07e9cff3c
commit
511ef3c346
|
@ -25,6 +25,17 @@ AdBlockSearchTree::AdBlockSearchTree()
|
|||
{
|
||||
}
|
||||
|
||||
AdBlockSearchTree::~AdBlockSearchTree()
|
||||
{
|
||||
deleteNode(m_root);
|
||||
}
|
||||
|
||||
void AdBlockSearchTree::clear()
|
||||
{
|
||||
deleteNode(m_root);
|
||||
m_root = new Node;
|
||||
}
|
||||
|
||||
bool AdBlockSearchTree::add(const AdBlockRule* rule)
|
||||
{
|
||||
if (rule->m_type != AdBlockRule::StringContainsMatchRule) {
|
||||
|
@ -58,7 +69,7 @@ bool AdBlockSearchTree::add(const AdBlockRule* rule)
|
|||
return true;
|
||||
}
|
||||
|
||||
const AdBlockRule* AdBlockSearchTree::find(const QNetworkRequest &request, const QString &domain, const QString &string)
|
||||
const AdBlockRule* AdBlockSearchTree::find(const QNetworkRequest &request, const QString &domain, const QString &string) const
|
||||
{
|
||||
int len = string.size();
|
||||
|
||||
|
@ -76,7 +87,7 @@ 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 AdBlockRule* AdBlockSearchTree::prefixSearch(const QNetworkRequest &request, const QString &domain, const QString &urlString, const QString &string) const
|
||||
{
|
||||
int len = string.size();
|
||||
|
||||
|
@ -127,8 +138,3 @@ void AdBlockSearchTree::deleteNode(AdBlockSearchTree::Node* node)
|
|||
|
||||
delete node;
|
||||
}
|
||||
|
||||
AdBlockSearchTree::~AdBlockSearchTree()
|
||||
{
|
||||
deleteNode(m_root);
|
||||
}
|
||||
|
|
|
@ -33,8 +33,10 @@ public:
|
|||
explicit AdBlockSearchTree();
|
||||
~AdBlockSearchTree();
|
||||
|
||||
void clear();
|
||||
|
||||
bool add(const AdBlockRule* rule);
|
||||
const AdBlockRule* find(const QNetworkRequest &request, const QString &domain, const QString &string);
|
||||
const AdBlockRule* find(const QNetworkRequest &request, const QString &domain, const QString &string) const;
|
||||
|
||||
private:
|
||||
struct Node {
|
||||
|
@ -46,7 +48,7 @@ private:
|
|||
};
|
||||
|
||||
const AdBlockRule* prefixSearch(const QNetworkRequest &request, const QString &domain,
|
||||
const QString &urlString, const QString &string);
|
||||
const QString &urlString, const QString &string) const;
|
||||
|
||||
void deleteNode(Node* node);
|
||||
|
||||
|
|
|
@ -58,8 +58,6 @@
|
|||
AdBlockSubscription::AdBlockSubscription(const QString &title, QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_reply(0)
|
||||
, m_networkBlockTree(0)
|
||||
, m_networkExceptionTree(0)
|
||||
, m_title(title)
|
||||
, m_updated(false)
|
||||
{
|
||||
|
@ -203,11 +201,11 @@ void AdBlockSubscription::saveDownloadedData(const QByteArray &data)
|
|||
|
||||
const AdBlockRule* AdBlockSubscription::match(const QNetworkRequest &request, const QString &urlDomain, const QString &urlString) const
|
||||
{
|
||||
if (m_networkExceptionTree->find(request, urlDomain, urlString)) {
|
||||
if (m_networkExceptionTree.find(request, urlDomain, urlString)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (const AdBlockRule* rule = m_networkBlockTree->find(request, urlDomain, urlString)) {
|
||||
if (const AdBlockRule* rule = m_networkBlockTree.find(request, urlDomain, urlString)) {
|
||||
return rule;
|
||||
}
|
||||
|
||||
|
@ -377,19 +375,15 @@ const AdBlockRule* AdBlockSubscription::replaceRule(AdBlockRule* rule, int offse
|
|||
|
||||
void AdBlockSubscription::populateCache()
|
||||
{
|
||||
m_networkExceptionTree.clear();
|
||||
m_networkExceptionRules.clear();
|
||||
m_networkBlockTree.clear();
|
||||
m_networkBlockRules.clear();
|
||||
m_domainRestrictedCssRules.clear();
|
||||
m_elementHidingRules.clear();
|
||||
m_documentRules.clear();
|
||||
m_elemhideRules.clear();
|
||||
|
||||
delete m_networkBlockTree;
|
||||
delete m_networkExceptionTree;
|
||||
|
||||
m_networkBlockTree = new AdBlockSearchTree;
|
||||
m_networkExceptionTree = new AdBlockSearchTree;
|
||||
|
||||
// Apparently, excessive amount of selectors for one CSS rule is not what WebKit likes.
|
||||
// (In my testings, 4931 is the number that makes it crash)
|
||||
// So let's split it by 1000 selectors...
|
||||
|
@ -423,12 +417,12 @@ void AdBlockSubscription::populateCache()
|
|||
m_elemhideRules.append(rule);
|
||||
}
|
||||
else if (rule->isException()) {
|
||||
if (!m_networkExceptionTree->add(rule)) {
|
||||
if (!m_networkExceptionTree.add(rule)) {
|
||||
m_networkExceptionRules.append(rule);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!m_networkBlockTree->add(rule)) {
|
||||
if (!m_networkBlockTree.add(rule)) {
|
||||
m_networkBlockRules.append(rule);
|
||||
}
|
||||
}
|
||||
|
@ -443,8 +437,6 @@ void AdBlockSubscription::populateCache()
|
|||
AdBlockSubscription::~AdBlockSubscription()
|
||||
{
|
||||
qDeleteAll(m_rules);
|
||||
delete m_networkBlockTree;
|
||||
delete m_networkExceptionTree;
|
||||
}
|
||||
|
||||
// AdBlockCustomList
|
||||
|
|
|
@ -51,12 +51,12 @@
|
|||
|
||||
#include "qz_namespace.h"
|
||||
#include "adblockrule.h"
|
||||
#include "adblocksearchtree.h"
|
||||
|
||||
class QNetworkRequest;
|
||||
class QNetworkReply;
|
||||
class QUrl;
|
||||
|
||||
class AdBlockSearchTree;
|
||||
class FollowRedirectReply;
|
||||
|
||||
class QT_QUPZILLA_EXPORT AdBlockSubscription : public QObject
|
||||
|
@ -124,8 +124,8 @@ protected:
|
|||
QVector<const AdBlockRule*> m_documentRules;
|
||||
QVector<const AdBlockRule*> m_elemhideRules;
|
||||
|
||||
AdBlockSearchTree* m_networkBlockTree;
|
||||
AdBlockSearchTree* m_networkExceptionTree;
|
||||
AdBlockSearchTree m_networkBlockTree;
|
||||
AdBlockSearchTree m_networkExceptionTree;
|
||||
|
||||
private:
|
||||
QString m_title;
|
||||
|
|
Loading…
Reference in New Issue
Block a user