<commit_before><?php
/**
 * Go! OOP&AOP PHP framework
 *
 * @copyright     Copyright 2012, <NAME> <<EMAIL>>
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */

namespace Go\Aop\Support;

/**
 * Invoker class is used to prepare closure for method invocation
 *
 * NB: This class is used only with PHP>=5.4.0 to build closure invocation.
 *
 * @author <NAME> <<EMAIL>>
 * @package go
 */
class Invoker
{

    /**
     * Restrict direct creation
     */
    final private function __construct()
    {
    }


    /**
     * Returns static method invoker
     *
     * @return closure
     */
    public static function getStatic()
    {
        static $invoker = null;
        if (!$invoker) {
            $invoker = function ($parentClass, $method, array $args) {
                return forward_static_call_array(array($parentClass, $method), $args);
            };
        }
        return $invoker;
    }

    /**
     * Returns dynamic parent invoker
     *
     * @return Closure
     */
    public static function getDynamicParent()
    {
        static $invoker = null;
        if (!$invoker) {
            $instance = new self();
            $invoker = $instance->getDynamicInvoker();
        }
        return $invoker;
    }

    /**
     * Private method that will use object instance to build dynamic parent invoker
     *
     * @return Closure
     */
    private function getDynamicInvoker()
    {
        return function ($parentClass, $method, array $args) {
            return call_user_func_array(array('parent', $method), $args);
        };
    }
}<commit_msg>Speed up original method invocation by checking the number of parameters and using direct method call instead of call_user_func_array for special cases<commit_after><?php
/**
 * Go! OOP&AOP PHP framework
 *
 * @copyright     Copyright 2012, <NAME> <<EMAIL>>
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */

namespace Go\Aop\Support;

/**
 * Invoker class is used to prepare closure for method invocation
 *
 * NB: This class is used only with PHP>=5.4.0 to build closure invocation.
 *
 * @author <NAME> <<EMAIL>>
 * @package go
 */
class Invoker
{

    /**
     * Restrict direct creation
     */
    final private function __construct()
    {
    }


    /**
     * Returns static method invoker
     *
     * @return closure
     */
    public static function getStatic()
    {
        static $invoker = null;
        if (!$invoker) {
            $invoker = function ($parentClass, $method, array $args) {
                switch(count($args)) {
                    case 0:
                        return parent::$method();
                    case 1:
                        return parent::$method($args[0]);
                    case 2:
                        return parent::$method($args[0], $args[1]);
                    case 3:
                        return parent::$method($args[0], $args[1], $args[2]);
                    case 4:
                        return parent::$method($args[0], $args[1], $args[2], $args[3]);
                    case 5:
                        return parent::$method($args[0], $args[1], $args[2], $args[3], $args[4]);
                    default:
                        return forward_static_call_array(array($parentClass, $method), $args);
                }
            };
        }
        return $invoker;
    }

    /**
     * Returns dynamic parent invoker
     *
     * @return Closure
     */
    public static function getDynamicParent()
    {
        static $invoker = null;
        if (!$invoker) {
            $instance = new self();
            $invoker = $instance->getDynamicInvoker();
        }
        return $invoker;
    }

    /**
     * Private method that will use object instance to build dynamic parent invoker
     *
     * @return Closure
     */
    private function getDynamicInvoker()
    {
        return function ($parentClass, $method, array $args) {
            switch(count($args)) {
                case 0:
                    return parent::$method();
                case 1:
                    return parent::$method($args[0]);
                case 2:
                    return parent::$method($args[0], $args[1]);
                case 3:
                    return parent::$method($args[0], $args[1], $args[2]);
                case 4:
                    return parent::$method($args[0], $args[1], $args[2], $args[3]);
                case 5:
                    return parent::$method($args[0], $args[1], $args[2], $args[3], $args[4]);
                default:
                    return call_user_func_array(array('parent', $method), $args);
            }
        };
    }
}
{'fraction_non_alphanumeric': 0.1256900212314225, 'fraction_numerical': 0.0118895966029724, 'mean_word_length': 1.7043628013777268, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7635099', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1266, 'n_words': 351}