mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-25 06:26:03 +00:00
5fc30112c7
substr_count() is just as fast as looped strpos() when there are no matches, and gets faster as the number of matches increases. Note that this introduces a small change in behavior when the needle is composed of repeated substrings, e.g. 'asdasdasd' or 'aa', and haystack is such that the needle can be matched in overlapping positions, e.g. 'asdasdasdasd' or 'aaaaa'. The old implementation counted overlapping matches, the new one doesn't. I don't think this behavior was intentional and I don't think this change will cause any real problems. Change-Id: Icc905ca34bf08d63e969787a5e3c119d498bf878
7 lines
151 B
Raku
7 lines
151 B
Raku
count("a,b,c,d") = 4 &
|
|
count(",", "a,b,c,d") = 3 &
|
|
count("", "abcd") = 0 &
|
|
count("a", "abab") = 2 &
|
|
count("ab", "abab") = 2 &
|
|
count("aa", "aaaaa") = 2
|