uschindler commented on code in PR #12873:
URL: https://github.com/apache/lucene/pull/12873#discussion_r1413150788

##########
lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptCompiler.java:
##########
@@ -201,48 +210,75 @@ private static void unusedTestCompile() throws 
IOException {
    *
    * @param sourceText The expression to compile
    */
-  private JavascriptCompiler(String sourceText, Map<String, Method> functions, 
boolean picky) {
-    if (sourceText == null) {
-      throw new NullPointerException();
-    }
-    this.sourceText = sourceText;
-    this.functions = functions;
+  private JavascriptCompiler(
+      String sourceText, Map<String, MethodHandle> functions, boolean picky) {
+    this.sourceText = Objects.requireNonNull(sourceText, "sourceText");
+    this.functions = Map.copyOf(functions);
     this.picky = picky;
+
+    // calculate all functions which can be invoked directly by cracking 
MethodHandle:
+    final HashMap<String, MethodHandleInfo> map = new HashMap<>();
+    for (var e : functions.entrySet()) {
+      final MethodHandleInfo info;
+      try {
+        info = EXPRESSION_LOOKUP.revealDirect(e.getValue());
+      } catch (
+          @SuppressWarnings("unused")
+          IllegalArgumentException iae) {
+        continue;
+      }
+      if (info.getReferenceKind() == MethodHandleInfo.REF_invokeStatic
+          && REACHABLE_FROM_OUR_CLASSLOADER.get(info.getDeclaringClass())) {
+        map.put(e.getKey(), info);
+      }
+    }
+    this.directFunctions = Collections.unmodifiableMap(map);

Review Comment:
   set this to `Map.empty()` to test using dynamic constants and 
`MethodHandles#invokeExact` for all functions.



-- 
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: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to