mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-24 06:03:49 +00:00
Merge "Optimize 'rcount()' function"
This commit is contained in:
commit
71bb512d93
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue