Only create the regular expression for content/sender matches once. 54/head
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 2 Feb 2014 11:27:33 +0000 (12:27 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 20 Mar 2014 20:58:26 +0000 (21:58 +0100)
Fixes #1227.

src/common/ignorelistmanager.cpp
src/common/ignorelistmanager.h

index a6fbd16..845af07 100644 (file)
@@ -23,7 +23,6 @@
 #include <QtCore>
 #include <QDebug>
 #include <QStringList>
-#include <QRegExp>
 
 INIT_SYNCABLE_OBJECT(IgnoreListManager)
 IgnoreListManager &IgnoreListManager::operator=(const IgnoreListManager &other)
@@ -145,19 +144,13 @@ IgnoreListManager::StrictnessType IgnoreListManager::_match(const QString &msgCo
             else
                 str = msgSender;
 
-            QRegExp ruleRx = QRegExp(item.ignoreRule);
-            ruleRx.setCaseSensitivity(Qt::CaseInsensitive);
-            if (!item.isRegEx) {
-                ruleRx.setPatternSyntax(QRegExp::Wildcard);
-            }
-
 //      qDebug() << "IgnoreListManager::match: ";
 //      qDebug() << "string: " << str;
 //      qDebug() << "pattern: " << ruleRx.pattern();
 //      qDebug() << "scopeRule: " << item.scopeRule;
 //      qDebug() << "now testing";
-            if ((!item.isRegEx && ruleRx.exactMatch(str)) ||
-                (item.isRegEx && ruleRx.indexIn(str) != -1)) {
+            if ((!item.isRegEx && item.regEx.exactMatch(str)) ||
+                (item.isRegEx && item.regEx.indexIn(str) != -1)) {
 //        qDebug() << "MATCHED!";
                 return item.strictness;
             }
index 0482705..72ca0af 100644 (file)
@@ -22,6 +22,7 @@
 #define IGNORELISTMANAGER_H
 
 #include <QString>
+#include <QRegExp>
 
 #include "message.h"
 #include "syncableobject.h"
@@ -60,10 +61,16 @@ public:
         ScopeType scope;
         QString scopeRule;
         bool isActive;
+        QRegExp regEx;
         IgnoreListItem() {}
         IgnoreListItem(IgnoreType type_, const QString &ignoreRule_, bool isRegEx_, StrictnessType strictness_,
             ScopeType scope_, const QString &scopeRule_, bool isActive_)
-            : type(type_), ignoreRule(ignoreRule_), isRegEx(isRegEx_), strictness(strictness_), scope(scope_), scopeRule(scopeRule_), isActive(isActive_)  {}
+            : type(type_), ignoreRule(ignoreRule_), isRegEx(isRegEx_), strictness(strictness_), scope(scope_), scopeRule(scopeRule_), isActive(isActive_), regEx(ignoreRule_) {
+            regEx.setCaseSensitivity(Qt::CaseInsensitive);
+            if (!isRegEx_) {
+                regEx.setPatternSyntax(QRegExp::Wildcard);
+            }
+        }
         bool operator!=(const IgnoreListItem &other)
         {
             return (type != other.type ||