[
https://issues.apache.org/jira/browse/GROOVY-12044?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18084620#comment-18084620
]
ASF GitHub Bot commented on GROOVY-12044:
-----------------------------------------
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.
> CurriedClosure per-element allocation
> -------------------------------------
>
> Key: GROOVY-12044
> URL: https://issues.apache.org/jira/browse/GROOVY-12044
> Project: Groovy
> Issue Type: Sub-task
> Reporter: Paul King
> Assignee: Paul King
> Priority: Major
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)