mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-27 23:40:19 +00:00
Merge "Optimize 'count()' function"
This commit is contained in:
commit
7e096abc85
|
@ -1525,21 +1525,17 @@ class AbuseFilterParser {
|
|||
return new AFPData( AFPData::DINT, count( $args[0]->data ) );
|
||||
}
|
||||
|
||||
$offset = -1;
|
||||
|
||||
if ( count( $args ) == 1 ) {
|
||||
$count = count( explode( ',', $args[0]->toString() ) );
|
||||
} else {
|
||||
$needle = $args[0]->toString();
|
||||
$haystack = $args[1]->toString();
|
||||
|
||||
$count = 0;
|
||||
|
||||
// Bug #60203: Keep empty parameters from causing PHP warnings
|
||||
if ( $needle !== '' ) {
|
||||
while ( ( $offset = strpos( $haystack, $needle, $offset + 1 ) ) !== false ) {
|
||||
$count++;
|
||||
}
|
||||
if ( $needle === '' ) {
|
||||
$count = 0;
|
||||
} else {
|
||||
$count = substr_count( $haystack, $needle );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,5 +3,4 @@ count(",", "a,b,c,d") = 3 &
|
|||
count("", "abcd") = 0 &
|
||||
count("a", "abab") = 2 &
|
||||
count("ab", "abab") = 2 &
|
||||
/* This probably shouldn't count overlapping occurrences... */
|
||||
count("aa", "aaaaa") = 4
|
||||
count("aa", "aaaaa") = 2
|
||||
|
|
Loading…
Reference in a new issue