Search in sources :

Example 6 with AccessorOptimizer

use of org.mvel2.optimizers.AccessorOptimizer in project mvel by mikebrock.

the class ASTNode method optimize.

private Object optimize(Object ctx, Object thisValue, VariableResolverFactory factory) {
    if ((fields & DEOP) != 0) {
        fields ^= DEOP;
    }
    AccessorOptimizer optimizer;
    Object retVal = null;
    if ((fields & NOJIT) != 0 || factory != null && factory.isResolveable(nameCache)) {
        optimizer = getAccessorCompiler(SAFE_REFLECTIVE);
    } else {
        optimizer = getDefaultAccessorCompiler();
    }
    ParserContext pCtx;
    if ((fields & PCTX_STORED) != 0) {
        pCtx = (ParserContext) literal;
    } else {
        pCtx = new ParserContext(new ParserConfiguration(getInjectedImports(factory), null));
    }
    try {
        pCtx.optimizationNotify();
        setAccessor(optimizer.optimizeAccessor(pCtx, expr, start, offset, ctx, thisValue, factory, true, egressType));
    } catch (OptimizationNotSupported ne) {
        setAccessor((optimizer = getAccessorCompiler(SAFE_REFLECTIVE)).optimizeAccessor(pCtx, expr, start, offset, ctx, thisValue, factory, true, null));
    }
    if (accessor == null) {
        return get(expr, start, offset, ctx, factory, thisValue);
    }
    if (retVal == null) {
        retVal = optimizer.getResultOptPass();
    }
    if (egressType == null) {
        egressType = optimizer.getEgressType();
    }
    return retVal;
}
Also used : AccessorOptimizer(org.mvel2.optimizers.AccessorOptimizer) ParserContext(org.mvel2.ParserContext) OptimizationNotSupported(org.mvel2.optimizers.OptimizationNotSupported) ParserConfiguration(org.mvel2.ParserConfiguration)

Example 7 with AccessorOptimizer

use of org.mvel2.optimizers.AccessorOptimizer in project mvel by mikebrock.

the class InlineCollectionNode method getReducedValueAccelerated.

public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) {
    if (accessor != null) {
        return accessor.getValue(ctx, thisValue, factory);
    } else {
        try {
            AccessorOptimizer ao = OptimizerFactory.getThreadAccessorOptimizer();
            if (collectionGraph == null)
                parseGraph(true, null, null);
            accessor = ao.optimizeCollection(AbstractParser.getCurrentThreadParserContext(), collectionGraph, egressType, expr, trailingStart, trailingOffset, ctx, thisValue, factory);
            egressType = ao.getEgressType();
            return accessor.getValue(ctx, thisValue, factory);
        } finally {
            OptimizerFactory.clearThreadAccessorOptimizer();
        }
    }
}
Also used : AccessorOptimizer(org.mvel2.optimizers.AccessorOptimizer)

Example 8 with AccessorOptimizer

use of org.mvel2.optimizers.AccessorOptimizer in project mvel by mikebrock.

the class Union method get.

private Object get(Object ctx, Object elCtx, VariableResolverFactory variableFactory) {
    if (nextAccessor == null) {
        Object o = accessor.getValue(ctx, elCtx, variableFactory);
        AccessorOptimizer ao = OptimizerFactory.getDefaultAccessorCompiler();
        Class ingress = accessor.getKnownEgressType();
        nextAccessor = ao.optimizeAccessor(getCurrentThreadParserContext(), nextExpr, start, offset, o, elCtx, variableFactory, false, ingress);
        return ao.getResultOptPass();
    } else {
        return accessor.getValue(ctx, elCtx, variableFactory);
    }
}
Also used : AccessorOptimizer(org.mvel2.optimizers.AccessorOptimizer)

Aggregations

AccessorOptimizer (org.mvel2.optimizers.AccessorOptimizer)7 ParserContext (org.mvel2.ParserContext)2 OptimizerFactory.getThreadAccessorOptimizer (org.mvel2.optimizers.OptimizerFactory.getThreadAccessorOptimizer)2 CompileException (org.mvel2.CompileException)1 ParserConfiguration (org.mvel2.ParserConfiguration)1 OptimizationNotSupported (org.mvel2.optimizers.OptimizationNotSupported)1 ASMAccessorOptimizer (org.mvel2.optimizers.impl.asm.ASMAccessorOptimizer)1 ReflectiveAccessorOptimizer (org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer)1