Pastakhov has uploaded a new change for review. https://gerrit.wikimedia.org/r/135005
Change subject: new hook release 2, version 1.2.0 ...................................................................... new hook release 2, version 1.2.0 have optimized hook performance * replace function BaseHooks::isNeedReference with getFunctionInfo * replace Runtime::getHookClassName with getFunctionHookInfo Change-Id: I0d7cd36b7500c98929911e806729ffcef03e66c4 --- M PhpTags.php M includes/BaseHooks.php M includes/Runtime.php 3 files changed, 54 insertions(+), 32 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PhpTags refs/changes/05/135005/1 diff --git a/PhpTags.php b/PhpTags.php index 85a1a67..149c116 100644 --- a/PhpTags.php +++ b/PhpTags.php @@ -16,11 +16,11 @@ } define( 'PHPTAGS_MAJOR_VERSION', 1 ); -define( 'PHPTAGS_MINOR_VERSION', 1 ); +define( 'PHPTAGS_MINOR_VERSION', 2 ); define( 'PHPTAGS_RELEASE_VERSION', 0 ); define( 'PHPTAGS_VERSION', PHPTAGS_MAJOR_VERSION . '.' . PHPTAGS_MINOR_VERSION . '.' . PHPTAGS_RELEASE_VERSION ); -define( 'PHPTAGS_HOOK_RELEASE', 1 ); +define( 'PHPTAGS_HOOK_RELEASE', 2 ); define( 'PHPTAGS_RUNTIME_RELEASE', 1 ); // Register this extension on Special:Version diff --git a/includes/BaseHooks.php b/includes/BaseHooks.php index bbe2a8c..dad6d41 100644 --- a/includes/BaseHooks.php +++ b/includes/BaseHooks.php @@ -6,8 +6,13 @@ define( 'PHPTAGS_HOOK_VALUE_N', 'N' ); define( 'PHPTAGS_HOOK_VALUE_TYPE', 0 ); define( 'PHPTAGS_HOOK_NEED_LINK', 1 ); -define( 'PHPTAGS_HOOK_DEFAULT_VALUE', 2 ); define( 'PHPTAGS_HOOK_RETURNS_ON_FAIL', 2 ); +define( 'PHPTAGS_HOOK_CONTAINS_LINKS', 'L' ); +define( 'PHPTAGS_HOOK_DEFAULT_VALUES', 'D' ); + +define( 'PHPTAGS_MIXED_LINKS', null ); +define( 'PHPTAGS_NO_LINKS', false ); +define( 'PHPTAGS_ONLY_LINKS', true ); define( 'PHPTAGS_TYPE_ARRAY', 'a' ); define( 'PHPTAGS_TYPE_BOOL', 'b' ); @@ -33,21 +38,12 @@ return get_called_class(); } - public static function isNeedReference( $name, $index, &$transit ) { + public static function getFunctionInfo( $name ) { if ( !isset(static::$functions_definition[$name]) ) { throw new ExceptionPhpTags( PHPTAGS_EXCEPTION_WARNING_INVALID_HOOK, array(static::getClassName(), $name) ); } - $definition = static::$functions_definition[$name]; - if ( !isset($definition[$index+1]) ) { - if ( isset($definition[PHPTAGS_HOOK_VALUE_N]) ) { - return $definition[PHPTAGS_HOOK_VALUE_N][PHPTAGS_HOOK_NEED_LINK]; - } else { - $transit[PHPTAGS_TRANSIT_EXCEPTION][] = new ExceptionPhpTags( PHPTAGS_EXCEPTION_WARNING_WRONG_PARAMETER_COUNT, $name ); - return; - } - } - return $definition[$index+1][PHPTAGS_HOOK_NEED_LINK]; + return isset( $definition[PHPTAGS_HOOK_CONTAINS_LINKS] ) ? $definition[PHPTAGS_HOOK_CONTAINS_LINKS] : false; } public static function onFunctionHook( $name, $params, &$transit ) { @@ -59,7 +55,15 @@ for ( $i=0, $c=count($params); $i < $c; $i++ ) { $d = $i + 1; - switch ( $definition[$d][PHPTAGS_HOOK_VALUE_TYPE] ) { + if ( isset($definition[$d]) ) { + $valueType = $definition[$d]; + } elseif( isset($definition[PHPTAGS_HOOK_VALUE_N]) ) { + $valueType = $definition[$d]; + } else { + $transit[PHPTAGS_TRANSIT_EXCEPTION][] = new ExceptionPhpTags( PHPTAGS_EXCEPTION_WARNING_WRONG_PARAMETER_COUNT, $name ); + return; + } + switch ( $valueType ) { case PHPTAGS_TYPE_ARRAY: if ( !is_array($params[$i]) ) { $transit[PHPTAGS_TRANSIT_EXCEPTION][] = new ExceptionPhpTags( PHPTAGS_EXCEPTION_WARNING_EXPECTS_PARAMETER, array($name, $d, 'array', gettype($params[$i])) ); @@ -85,16 +89,17 @@ while ( !isset($definition[PHPTAGS_HOOK_INVOKE][$i]) ) { $d = $i + 1; - if ( !isset($definition[$d]) || !array_key_exists(PHPTAGS_HOOK_DEFAULT_VALUE, $definition[$d]) ) { - if ( !isset($definition[$d]) && isset($definition[PHPTAGS_HOOK_INVOKE][PHPTAGS_HOOK_VALUE_N]) ) { - $d = PHPTAGS_HOOK_VALUE_N; - break; - } - $transit[PHPTAGS_TRANSIT_EXCEPTION][] = new ExceptionPhpTags( PHPTAGS_EXCEPTION_WARNING_WRONG_PARAMETER_COUNT, $name ); - return; + if ( isset($definition[PHPTAGS_HOOK_DEFAULT_VALUES]) && array_key_exists($d, $definition[PHPTAGS_HOOK_DEFAULT_VALUES]) ) { + $params[$i] = $definition[PHPTAGS_HOOK_DEFAULT_VALUES][$d]; + $i++; + continue; } - $params[$i] = $definition[$d][PHPTAGS_HOOK_DEFAULT_VALUE]; - $i++; + if ( isset($definition[PHPTAGS_HOOK_INVOKE][PHPTAGS_HOOK_VALUE_N]) ) { + $d = PHPTAGS_HOOK_VALUE_N; + break; + } + $transit[PHPTAGS_TRANSIT_EXCEPTION][] = new ExceptionPhpTags( PHPTAGS_EXCEPTION_WARNING_WRONG_PARAMETER_COUNT, $name ); + return; } return static::$definition[PHPTAGS_HOOK_INVOKE][$d]( $params, $transit ); } diff --git a/includes/Runtime.php b/includes/Runtime.php index ac12886..3de62f9 100644 --- a/includes/Runtime.php +++ b/includes/Runtime.php @@ -418,12 +418,27 @@ break; case PHPTAGS_T_HOOK_CHECK_PARAM: $name = $value[PHPTAGS_STACK_PARAM]; - $hookClassName = self::getHookClassName( $name, $value, $place, $return ); - if ( $hookClassName === false ) { + $hookInfo = self::getFunctionHookInfo( $name, $value, $place, $return ); + if ( $hookInfo === false ) { return $return; } $i = $value[PHPTAGS_STACK_AIM]; - $isNeedFeference = $hookClassName::isNeedReference( $name, $i, $transit ); + $containsReferences = $hookInfo[1]; + if( $containsReferences === false ) { + $isNeedFeference = false; + } elseif ( $containsReferences === true ) { + $isNeedFeference = true; + } elseif ( is_array($containsReferences) ) { + if( isset($containsReferences[$i+1]) || array_key_exists($i+1, $containsReferences) ) { + $isNeedFeference = $containsReferences[$i+1]; + } elseif( isset($containsReferences[PHPTAGS_HOOK_VALUE_N]) || array_key_exists(PHPTAGS_HOOK_VALUE_N, $containsReferences) ) { + $isNeedFeference = $containsReferences[PHPTAGS_HOOK_VALUE_N]; + } else { + $isNeedFeference = false; + } + } else { + $isNeedFeference = (bool)( 1 << $i & $containsReferences ); + } if ( $value[PHPTAGS_STACK_PARAM_2] === true && $isNeedFeference === false ) { // Param is variable and it's need to clone $t = $value[PHPTAGS_STACK_RESULT][$i]; @@ -441,10 +456,11 @@ $transit[PHPTAGS_TRANSIT_EXCEPTION] = array(); if ( isset($value[PHPTAGS_STACK_PARAM_2]) ) { // This is function or object if ( is_array($value[PHPTAGS_STACK_PARAM_2]) ) { // This is function - $hookClassName = self::getHookClassName( $name, $value, $place, $return ); - if ( $hookClassName === false ) { + $hookInfo = self::getFunctionHookInfo( $name, $value, $place, $return ); + if ( $hookInfo === false ) { return $return; } + $hookClassName = $hookInfo[0]; try { wfSuppressWarnings(); @@ -768,7 +784,7 @@ self::$objectsHook += array_fill_keys( $objectsName, $className ); } - public static function getHookClassName( $name, $value, $place, &$return ) { + public static function getFunctionHookInfo( $name, $value, $place, &$return ) { static $hooks = array(); if( isset($hooks[$name]) ) { return $hooks[$name]; @@ -787,8 +803,9 @@ $return[] = new ExceptionPhpTags( PHPTAGS_EXCEPTION_FATAL_INVALID_HOOK_CLASS, array($name, $hookClassName), $value[PHPTAGS_STACK_TOKEN_LINE], $place ); return false; } - $hooks[$name] = $hookClassName; - return $hookClassName; + $hookInfo = array( $hookClassName, $hookClassName::getFunctionInfo($name) ); + $hooks[$name] = $hookInfo; + return $hookInfo; } } -- To view, visit https://gerrit.wikimedia.org/r/135005 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0d7cd36b7500c98929911e806729ffcef03e66c4 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/PhpTags Gerrit-Branch: master Gerrit-Owner: Pastakhov <pastak...@yandex.ru> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits