mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-18 20:29:10 +03:00
Merge pull request #5008 from SpiritCroc/globstar
Speed up event match regex evaluation for big messages
This commit is contained in:
commit
63b3def667
2 changed files with 7 additions and 1 deletions
1
changelog.d/5008.bugfix
Normal file
1
changelog.d/5008.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Big messages taking inappropriately long to evaluate .m.rule.roomnotif push rules
|
|
@ -56,7 +56,12 @@ class EventMatchCondition(
|
|||
if (wordsOnly) {
|
||||
value.caseInsensitiveFind(pattern)
|
||||
} else {
|
||||
val modPattern = if (pattern.hasSpecialGlobChar()) pattern.simpleGlobToRegExp() else "*$pattern*".simpleGlobToRegExp()
|
||||
val modPattern = if (pattern.hasSpecialGlobChar())
|
||||
// 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
|
||||
pattern.simpleGlobToRegExp()
|
||||
val regex = Regex(modPattern, RegexOption.DOT_MATCHES_ALL)
|
||||
regex.containsMatchIn(value)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue