Bring back the body match optimization

Signed-off-by: Nicolas Werner <nicolas.werner@hotmail.de>
This commit is contained in:
Nicolas Werner 2022-07-21 12:18:55 +02:00
parent bc20ad5cf1
commit 4a383523e5
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9

View File

@ -54,7 +54,14 @@ class EventMatchCondition(
// word boundary.
return try {
if (key == "content.body") {
val regex = Regex("(\\W|^)" + pattern.simpleGlobToRegExp() + "(\\W|$)", setOf(RegexOption.DOT_MATCHES_ALL, RegexOption.IGNORE_CASE))
val modPattern = if (pattern.startsWith("*") && pattern.endsWith("*")) {
// Regex.containsMatchIn() is way faster without leading and trailing
// stars, that don't make any difference for the evaluation result
pattern.removePrefix("*").removeSuffix("*").simpleGlobToRegExp()
} else {
"(\\W|^)" + pattern.simpleGlobToRegExp() + "(\\W|$)"
}
val regex = Regex(modPattern, setOf(RegexOption.DOT_MATCHES_ALL, RegexOption.IGNORE_CASE))
regex.containsMatchIn(value)
} else {
val regex = Regex(pattern.simpleGlobToRegExp(), setOf(RegexOption.DOT_MATCHES_ALL, RegexOption.IGNORE_CASE))