4848import com .oracle .graal .python .nodes .PBaseNode ;
4949import com .oracle .graal .python .nodes .argument .ApplyKeywordsNodeGen .SearchNamedParameterNodeGen ;
5050import com .oracle .graal .python .runtime .exception .PythonErrorType ;
51+ import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
5152import com .oracle .truffle .api .dsl .Cached ;
5253import com .oracle .truffle .api .dsl .Specialization ;
5354import com .oracle .truffle .api .nodes .ExplodeLoop ;
5455import com .oracle .truffle .api .nodes .Node ;
56+ import com .oracle .truffle .api .profiles .ConditionProfile ;
5557
5658public abstract class ApplyKeywordsNode extends PBaseNode {
59+ private final ConditionProfile expandArgs = ConditionProfile .createBinaryProfile ();
60+
5761 public abstract Object [] execute (Arity calleeArity , Object [] arguments , PKeyword [] keywords );
5862
5963 public static ApplyKeywordsNode create () {
@@ -68,11 +72,9 @@ SearchNamedParameterNode createSearchNamedParameterNode() {
6872 return SearchNamedParameterNodeGen .create ();
6973 }
7074
71- @ ExplodeLoop
75+ @ TruffleBoundary
7276 private static void copyArgs (Object [] src , Object [] dst , int len ) {
73- for (int i = 0 ; i < len ; i ++) {
74- dst [i ] = src [i ];
75- }
77+ System .arraycopy (src , 0 , dst , 0 , len );
7678 }
7779
7880 @ Specialization (guards = {"kwLen == keywords.length" , "argLen == arguments.length" , "calleeArity == cachedArity" })
@@ -86,7 +88,7 @@ Object[] applyCached(Arity calleeArity, Object[] arguments, PKeyword[] keywords,
8688 @ Cached ("parameters.length" ) int paramLen ,
8789 @ Cached ("createSearchNamedParameterNode()" ) SearchNamedParameterNode searchParamNode ) {
8890 Object [] combined = arguments ;
89- if (paramLen > userArgLen ) {
91+ if (expandArgs . profile ( paramLen > userArgLen ) ) {
9092 combined = PArguments .create (paramLen );
9193 copyArgs (arguments , combined , argLen );
9294 }
@@ -98,7 +100,9 @@ Object[] applyCached(Arity calleeArity, Object[] arguments, PKeyword[] keywords,
98100
99101 if (kwIdx != -1 ) {
100102 if (PArguments .getArgument (combined , kwIdx ) != null ) {
101- throw raise (PythonErrorType .TypeError , "%s() got multiple values for argument '%s'" , calleeArity .getFunctionName (), kwArg .getName ());
103+ throw raise (PythonErrorType .TypeError , "%s() got multiple values for argument '%s'" ,
104+ calleeArity .getFunctionName (),
105+ kwArg .getName ());
102106 }
103107 PArguments .setArgument (combined , kwIdx , kwArg .getValue ());
104108 } else {
0 commit comments