<commit_before>package org.mvel.compiled;

import org.mvel.AccessorNode;
import static org.mvel.DataConversion.convert;
import org.mvel.integration.VariableResolverFactory;
import org.mvel.optimizers.ExecutableStatement;

import java.lang.reflect.Method;

public class MethodAccessor implements AccessorNode {
    private AccessorNode nextNode;

    private Method method;
    private Class[] parameterTypes;
    private ExecutableStatement[] compiledParameters;
    private boolean coercionNeeded = false;

    public Object getValue(Object ctx, Object elCtx, VariableResolverFactory vars) throws Exception {
        if (!coercionNeeded) {
            try {
                if (nextNode != null) {
                    return nextNode.getValue(method.invoke(ctx, executeAll(elCtx, vars)), elCtx, vars);
                }
                else {
                    return method.invoke(ctx, executeAll(elCtx, vars));
                }
            }
            catch (IllegalArgumentException e) {
                coercionNeeded = true;
                return getValue(ctx, elCtx, vars);
            }

        }
        else {
            if (nextNode != null) {
                return nextNode.getValue(method.invoke(ctx, executeAndCoerce(parameterTypes, elCtx, vars)), elCtx, vars);
            }
            else {
                return method.invoke(ctx, executeAndCoerce(parameterTypes, elCtx, vars));
            }
        }
    }

    private Object[] executeAll(Object ctx, VariableResolverFactory vars) {
        if (compiledParameters == null) return GetterAccessor.EMPTY;
        
        Object[] vals = new Object[compiledParameters.length];
        for (int i = 0; i < vals.length; i++) {
            vals[i] = compiledParameters[i].getValue(ctx, vars);
        }
        return vals;
    }

    private Object[] executeAndCoerce(Class[] target, Object elCtx, VariableResolverFactory vars) {
        Object[] values = new Object[compiledParameters.length];
        for (int i = 0; i < compiledParameters.length; i++) {
            //noinspection unchecked
            values[i] = convert(compiledParameters[i].getValue(elCtx, vars), target[i]);
        }
        return values;
    }

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
        this.parameterTypes = this.method.getParameterTypes();
    }


    public ExecutableStatement[] getCompiledParameters() {
        return compiledParameters;
    }

    public void setCompiledParameters(ExecutableStatement[] compiledParameters) {
        this.compiledParameters = compiledParameters;
    }

    public MethodAccessor() {
    }

    public AccessorNode getNextNode() {
        return nextNode;
    }
<commit_msg>Minor performance enhancement<commit_after>package org.mvel.compiled;

import org.mvel.AccessorNode;
import static org.mvel.DataConversion.convert;
import org.mvel.integration.VariableResolverFactory;
import org.mvel.optimizers.ExecutableStatement;

import java.lang.reflect.Method;

public class MethodAccessor implements AccessorNode {
    private AccessorNode nextNode;

    private Method method;
    private Class[] parameterTypes;
    private ExecutableStatement[] compiledParameters;
    int length;
    private boolean coercionNeeded = false;

    public Object getValue(Object ctx, Object elCtx, VariableResolverFactory vars) throws Exception {
        if (!coercionNeeded) {
            try {
                if (nextNode != null) {
                    return nextNode.getValue(method.invoke(ctx, executeAll(elCtx, vars)), elCtx, vars);
                }
                else {
                    return method.invoke(ctx, executeAll(elCtx, vars));
                }
            }
            catch (IllegalArgumentException e) {
                coercionNeeded = true;
                return getValue(ctx, elCtx, vars);
            }

        }
        else {
            if (nextNode != null) {
                return nextNode.getValue(method.invoke(ctx, executeAndCoerce(parameterTypes, elCtx, vars)), elCtx, vars);
            }
            else {
                return method.invoke(ctx, executeAndCoerce(parameterTypes, elCtx, vars));
            }
        }
    }

    private Object[] executeAll(Object ctx, VariableResolverFactory vars) {
        if (length == 0) return GetterAccessor.EMPTY;
        
        Object[] vals = new Object[length];
        for (int i = 0; i < length; i++) {
            vals[i] = compiledParameters[i].getValue(ctx, vars);
        }
        return vals;
    }

    private Object[] executeAndCoerce(Class[] target, Object elCtx, VariableResolverFactory vars) {
        Object[] values = new Object[length];
        for (int i = 0; i < length; i++) {
            //noinspection unchecked
            values[i] = convert(compiledParameters[i].getValue(elCtx, vars), target[i]);
        }
        return values;
    }

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
        this.length = (this.parameterTypes = this.method.getParameterTypes()).length;
    }


    public ExecutableStatement[] getCompiledParameters() {
        return compiledParameters;
    }

    public void setCompiledParameters(ExecutableStatement[] compiledParameters) {
        this.compiledParameters = compiledParameters;
    }

    public MethodAccessor() {
    }

    public AccessorNode getNextNode() {
        return nextNode;
    }

{'fraction_non_alphanumeric': 0.09242479159115621, 'fraction_numerical': 0.0009061254077564335, 'mean_word_length': 2.3028126870137644, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4115626', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1416, 'n_words': 349}