Merge "Optimize 'count()' function"

This commit is contained in:
jenkins-bot 2016-04-25 22:31:52 +00:00 committed by Gerrit Code Review
commit 7e096abc85
2 changed files with 5 additions and 10 deletions

View file

@ -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 );
}
}

View file

@ -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