Merge "Optimize 'rcount()' function"

This commit is contained in:
jenkins-bot 2016-04-28 09:32:29 +00:00 committed by Gerrit Code Review
commit 71bb512d93

View file

@ -606,6 +606,8 @@ class AbuseFilterParser {
public static $funcCache = array();
private static $hasSmartPregMatchAll = null;
/**
* Create a new instance
*
@ -616,6 +618,11 @@ class AbuseFilterParser {
if ( $vars instanceof AbuseFilterVariableHolder ) {
$this->mVars = $vars;
}
if ( self::$hasSmartPregMatchAll === null ) {
// Starting with PHP 5.4, preg_match_all() allows omitting the '$matches' argument.
$r = new ReflectionFunction( 'preg_match_all' );
self::$hasSmartPregMatchAll = $r->getNumberOfRequiredParameters() === 2;
}
}
public function resetState() {
@ -1567,9 +1574,14 @@ class AbuseFilterParser {
$needle = preg_replace( '!(\\\\\\\\)*(\\\\)?/!', '$1\/', $needle );
$needle = "/$needle/u";
$matches = array();
if ( self::$hasSmartPregMatchAll ) {
// Omit the '$matches' argument to avoid computing them, just count.
$count = preg_match_all( $needle, $haystack );
} else {
$matches = array();
$count = preg_match_all( $needle, $haystack, $matches );
}
$count = preg_match_all( $needle, $haystack, $matches );
if ( $count === false ) {
throw new AFPUserVisibleException(
'regexfailure',