From 699e8c1dbb7d53b3d3cd7bd15bfa4dd07a008f86 Mon Sep 17 00:00:00 2001 From: mariofusco Date: Thu, 13 Jul 2023 09:58:50 +0200 Subject: [PATCH] wip --- .../consequence/LambdaConsequence.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drools-model/drools-model-compiler/src/main/java/org/drools/modelcompiler/consequence/LambdaConsequence.java b/drools-model/drools-model-compiler/src/main/java/org/drools/modelcompiler/consequence/LambdaConsequence.java index b881816b9be..9568ff551b5 100644 --- a/drools-model/drools-model-compiler/src/main/java/org/drools/modelcompiler/consequence/LambdaConsequence.java +++ b/drools-model/drools-model-compiler/src/main/java/org/drools/modelcompiler/consequence/LambdaConsequence.java @@ -16,10 +16,6 @@ package org.drools.modelcompiler.consequence; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - import org.drools.base.base.ValueResolver; import org.drools.base.definitions.rule.impl.RuleImpl; import org.drools.base.reteoo.BaseTuple; @@ -32,6 +28,10 @@ import org.drools.model.Variable; import org.kie.api.runtime.rule.FactHandle; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + public class LambdaConsequence implements Consequence { // Enable the optimization to extract from the activation tuple the arguments to be passed to this @@ -39,18 +39,20 @@ public class LambdaConsequence implements Consequence { private static final boolean ENABLE_LINEARIZED_ARGUMENTS_RETRIEVAL_OPTIMIZATION = true; private final org.drools.model.Consequence consequence; - private final boolean enabledTupleOptimization; - private Declaration[] requiredDeclarations; + private final int factsNr; + private final boolean enabledTupleOptimization; + private Declaration[] requiredDeclarations; private TupleFactSupplier[] factSuppliers; - private GlobalSupplier[] globalSuppliers; - private Object[] facts; + private GlobalSupplier[] globalSuppliers; + private Object[] facts; - private FactHandleLookup fhLookup; + private FactHandleLookup fhLookup; public LambdaConsequence( org.drools.model.Consequence consequence, boolean enabledTupleOptimization) { this.consequence = consequence; this.enabledTupleOptimization = ENABLE_LINEARIZED_ARGUMENTS_RETRIEVAL_OPTIMIZATION & enabledTupleOptimization; + this.factsNr = consequence.getVariables().length + ( consequence.isUsingDrools() ? 1 : 0 ); } @Override @@ -125,12 +127,10 @@ private Object[] fetchFacts( KnowledgeHelper knowledgeHelper, ValueResolver valu Object[] facts; FactHandleLookup fhLookup = null; if (reteEvaluator.getRuleSessionConfiguration().isThreadSafe()) { + facts = new Object[factsNr]; if ( consequence.isUsingDrools() ) { - facts = new Object[consequence.getVariables().length + 1]; fhLookup = FactHandleLookup.create( factSuppliers.length ); facts[0] = new DroolsImpl( knowledgeHelper, reteEvaluator, fhLookup ); - } else { - facts = new Object[consequence.getVariables().length]; } } else { facts = this.facts;