Copilot commented on code in PR #2571:
URL: https://github.com/apache/groovy/pull/2571#discussion_r3329322889


##########
src/main/java/org/codehaus/groovy/runtime/CurriedClosure.java:
##########
@@ -108,6 +108,28 @@ public CurriedClosure(final Closure<V> uncurriedClosure, 
final Object... argumen
 
     
//--------------------------------------------------------------------------
 
+    /**
+     * Fast path for the dominant rcurry/curry shape — one curried argument 
and a
+     * single incoming argument against a binary owner. Skips the wrapping
+     * {@code Object[1]} that {@link Closure#call(Object)} would otherwise 
allocate
+     * before dispatch, leaving just the one combined {@code Object[2]} that 
the
+     * underlying call already requires.
+     */
+    @Override
+    @SuppressWarnings("unchecked")
+    public V call(final Object argument) {
+        if (varargType == null
+                && curriedArguments.length == 1
+                && maximumNumberOfParameters == 1
+                && (index == 0 || index == 1)) {
+            Object[] combined = index == 0
+                    ? new Object[]{curriedArguments[0], argument}
+                    : new Object[]{argument, curriedArguments[0]};
+            return (V) getOwner().call(combined);
+        }
+        return super.call(argument);

Review Comment:
   The fallback re-enters this new `call(Object)` override for any one-argument 
curried closure that does not match the fast-path shape. `super.call(argument)` 
wraps the value and then `Closure.call(Object...)` detects CurriedClosure's 
one-argument override via `CALL_OVERRIDES`, reflectively invoking this method 
again, so cases like multi-argument curry or vararg curry can recurse until 
stack overflow instead of using the normal uncurrying path.



-- 
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]

Reply via email to