2020package org .elasticsearch .painless .node ;
2121
2222import org .elasticsearch .painless .ClassWriter ;
23- import org .elasticsearch .painless .CompilerSettings ;
2423import org .elasticsearch .painless .Globals ;
2524import org .elasticsearch .painless .Locals ;
2625import org .elasticsearch .painless .Locals .Parameter ;
@@ -54,7 +53,7 @@ public final class SFunction extends AStatement {
5453 private final SBlock block ;
5554 public final boolean synthetic ;
5655
57- private CompilerSettings settings ;
56+ private int maxLoopCounter ;
5857
5958 Class <?> returnType ;
6059 List <Class <?>> typeParameters ;
@@ -121,7 +120,7 @@ void generateSignature(PainlessLookup painlessLookup) {
121120
122121 @ Override
123122 void analyze (ScriptRoot scriptRoot , Locals locals ) {
124- this . settings = scriptRoot .getCompilerSettings ();
123+ maxLoopCounter = scriptRoot .getCompilerSettings (). getMaxLoopCounter ();
125124
126125 if (block .statements .isEmpty ()) {
127126 throw createError (new IllegalArgumentException ("Cannot generate an empty function [" + name + "]." ));
@@ -137,7 +136,7 @@ void analyze(ScriptRoot scriptRoot, Locals locals) {
137136 throw createError (new IllegalArgumentException ("Not all paths provide a return value for method [" + name + "]." ));
138137 }
139138
140- if (settings . getMaxLoopCounter () > 0 ) {
139+ if (maxLoopCounter > 0 ) {
141140 loop = locals .getVariable (null , Locals .LOOP );
142141 }
143142 }
@@ -156,10 +155,10 @@ void write(ClassWriter classWriter, Globals globals) {
156155
157156 @ Override
158157 void write (ClassWriter classWriter , MethodWriter methodWriter , Globals globals ) {
159- if (settings . getMaxLoopCounter () > 0 ) {
158+ if (maxLoopCounter > 0 ) {
160159 // if there is infinite loop protection, we do this once:
161160 // int #loop = settings.getMaxLoopCounter()
162- methodWriter .push (settings . getMaxLoopCounter () );
161+ methodWriter .push (maxLoopCounter );
163162 methodWriter .visitVarInsn (Opcodes .ISTORE , loop .getSlot ());
164163 }
165164
0 commit comments