Skip to content

Commit e191c94

Browse files
authored
Minor Painless Clean Up (#49844)
This cleans up two minor things. - Cleans up style of == false - Pulls maxLoopCounter into a member variable instead of accessing CompilerSettings multiple times in the SFunction node
1 parent f002cd1 commit e191c94

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ERegex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void extractVariables(Set<String> variables) {
6363

6464
@Override
6565
void analyze(ScriptRoot scriptRoot, Locals locals) {
66-
if (false == scriptRoot.getCompilerSettings().areRegexesEnabled()) {
66+
if (scriptRoot.getCompilerSettings().areRegexesEnabled() == false) {
6767
throw createError(new IllegalStateException("Regexes are disabled. Set [script.painless.regex.enabled] to [true] "
6868
+ "in elasticsearch.yaml to allow them. Be careful though, regexes break out of Painless's protection against deep "
6969
+ "recursion and long loops."));

modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.elasticsearch.painless.node;
2121

2222
import org.elasticsearch.painless.ClassWriter;
23-
import org.elasticsearch.painless.CompilerSettings;
2423
import org.elasticsearch.painless.Globals;
2524
import org.elasticsearch.painless.Locals;
2625
import 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

Comments
 (0)