Skip to content

Commit 63b3def

Browse files
authored
Merge pull request #5008 from SpiritCroc/globstar
Speed up event match regex evaluation for big messages
2 parents f914717 + af34399 commit 63b3def

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

changelog.d/5008.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Big messages taking inappropriately long to evaluate .m.rule.roomnotif push rules

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/pushrules/EventMatchCondition.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ class EventMatchCondition(
5656
if (wordsOnly) {
5757
value.caseInsensitiveFind(pattern)
5858
} else {
59-
val modPattern = if (pattern.hasSpecialGlobChar()) pattern.simpleGlobToRegExp() else "*$pattern*".simpleGlobToRegExp()
59+
val modPattern = if (pattern.hasSpecialGlobChar())
60+
// Regex.containsMatchIn() is way faster without leading and trailing
61+
// stars, that don't make any difference for the evaluation result
62+
pattern.removePrefix("*").removeSuffix("*").simpleGlobToRegExp()
63+
else
64+
pattern.simpleGlobToRegExp()
6065
val regex = Regex(modPattern, RegexOption.DOT_MATCHES_ALL)
6166
regex.containsMatchIn(value)
6267
}

0 commit comments

Comments
 (0)