From 8677a82a6664da67c67610d0b438ee17904b12fb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 2 Feb 2014 12:27:33 +0100 Subject: [PATCH 1/1] Only create the regular expression for content/sender matches once. Fixes #1227. --- src/common/ignorelistmanager.cpp | 11 ++--------- src/common/ignorelistmanager.h | 9 ++++++++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/common/ignorelistmanager.cpp b/src/common/ignorelistmanager.cpp index a6fbd161..845af07c 100644 --- a/src/common/ignorelistmanager.cpp +++ b/src/common/ignorelistmanager.cpp @@ -23,7 +23,6 @@ #include #include #include -#include 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; } diff --git a/src/common/ignorelistmanager.h b/src/common/ignorelistmanager.h index 0482705e..72ca0af9 100644 --- a/src/common/ignorelistmanager.h +++ b/src/common/ignorelistmanager.h @@ -22,6 +22,7 @@ #define IGNORELISTMANAGER_H #include +#include #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 || -- 2.20.1