uschindler commented on PR #14602:
URL: https://github.com/apache/lucene/pull/14602#issuecomment-2845328503
I also added a new test to make sure that using the same function two times
works correct.
```java
public void testSameFunctionTwoTimes() throws Exception {
Expression expr = compile("sqrt(20)+abs(-7)+sqrt(30)");
assertEquals(Math.sqrt(20) + 7 + Math.sqrt(30), expr.evaluate(null),
DELTA);
}
```
I also verified the bytecode, now looks like this:
```
// (version 24 : 68.0, no super bit)
public final class
org.apache.lucene.expressions.js.JavascriptCompiler$CompiledExpression extends
org.apache.lucene.expressions.Expression {
// Method descriptor #6 (Ljava/lang/String;[Ljava/lang/String;)V
// Stack: 3, Locals: 3
public JavascriptCompiler$CompiledExpression(java.lang.String arg0,
java.lang.String[] arg1);
0 aload_0 [this]
1 aload_1 [arg0]
2 aload_2 [arg1]
3 invokespecial
org.apache.lucene.expressions.Expression(java.lang.String, java.lang.String[])
[8]
6 return
// Method descriptor #10 ([Lorg/apache/lucene/search/DoubleValues;)D
// Stack: 5, Locals: 2
public double evaluate(org.apache.lucene.search.DoubleValues[] arg0)
throws java.io.IOException;
0 ldc <Dynamic> 0 _ java.lang.invoke.MethodHandle [22]
2 ldc2_w <Double 20.0> [23]
5 invokevirtual java.lang.invoke.MethodHandle.invokeExact(double) :
double [30]
8 ldc <Dynamic> 1 _ java.lang.invoke.MethodHandle [32]
10 ldc2_w <Double 7.0> [33]
13 dneg
14 invokevirtual java.lang.invoke.MethodHandle.invokeExact(double) :
double [30]
17 dadd
18 ldc <Dynamic> 0 _ java.lang.invoke.MethodHandle [22]
20 ldc2_w <Double 30.0> [35]
23 invokevirtual java.lang.invoke.MethodHandle.invokeExact(double) :
double [30]
26 dadd
27 dreturn
28 aload_0 [this]
29 invokestatic
org.apache.lucene.expressions.js.JavascriptCompiler.patchStackTrace(java.lang.Throwable,
org.apache.lucene.expressions.Expression) : java.lang.Throwable [44]
32 athrow
Exception Table:
[pc: 0, pc: 28] -> 28 when : java.lang.Throwable
Stack map table: number of frames 1
[pc: 28, same_locals_1_stack_item, stack: {java.lang.Throwable}]
Bootstrap methods:
0 : # 18 invokestatic
java/lang/invoke/MethodHandles.classDataAt:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;I)Ljava/lang/Object;
Method arguments:
#11 0,
1 : # 18 invokestatic
java/lang/invoke/MethodHandles.classDataAt:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;I)Ljava/lang/Object;
Method arguments:
#31 1
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]