mediawiki-extensions-AbuseF.../tests/parserTests/count.t
Bartosz Dziewoński 5fc30112c7 Optimize 'count()' function
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
2016-04-17 08:32:27 +02:00

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