4040 */
4141package com .oracle .graal .python .nodes .argument ;
4242
43- import java .util .ArrayList ;
43+ import java .util .Arrays ;
4444
4545import com .oracle .graal .python .builtins .objects .function .Arity ;
4646import com .oracle .graal .python .builtins .objects .function .PArguments ;
4747import com .oracle .graal .python .builtins .objects .function .PKeyword ;
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 ;
5251import com .oracle .truffle .api .dsl .Cached ;
5352import com .oracle .truffle .api .dsl .Specialization ;
5453import com .oracle .truffle .api .nodes .ExplodeLoop ;
@@ -72,11 +71,6 @@ SearchNamedParameterNode createSearchNamedParameterNode() {
7271 return SearchNamedParameterNodeGen .create ();
7372 }
7473
75- @ TruffleBoundary
76- private static void copyArgs (Object [] src , Object [] dst , int len ) {
77- System .arraycopy (src , 0 , dst , 0 , len );
78- }
79-
8074 @ Specialization (guards = {"kwLen == keywords.length" , "argLen == arguments.length" , "calleeArity == cachedArity" })
8175 @ ExplodeLoop
8276 Object [] applyCached (Arity calleeArity , Object [] arguments , PKeyword [] keywords ,
@@ -90,10 +84,11 @@ Object[] applyCached(Arity calleeArity, Object[] arguments, PKeyword[] keywords,
9084 Object [] combined = arguments ;
9185 if (expandArgs .profile (paramLen > userArgLen )) {
9286 combined = PArguments .create (paramLen );
93- copyArgs (arguments , combined , argLen );
87+ System . arraycopy (arguments , 0 , combined , 0 , argLen );
9488 }
9589
96- ArrayList <PKeyword > unusedKeywords = new ArrayList <>();
90+ PKeyword [] unusedKeywords = new PKeyword [kwLen ];
91+ int k = 0 ;
9792 for (int i = 0 ; i < kwLen ; i ++) {
9893 PKeyword kwArg = keywords [i ];
9994 int kwIdx = searchParamNode .execute (parameters , kwArg .getName ());
@@ -106,10 +101,10 @@ Object[] applyCached(Arity calleeArity, Object[] arguments, PKeyword[] keywords,
106101 }
107102 PArguments .setArgument (combined , kwIdx , kwArg .getValue ());
108103 } else {
109- unusedKeywords . add ( kwArg ) ;
104+ unusedKeywords [ k ++] = kwArg ;
110105 }
111106 }
112- PArguments .setKeywordArguments (combined , unusedKeywords . toArray ( new PKeyword [ unusedKeywords . size ()] ));
107+ PArguments .setKeywordArguments (combined , Arrays . copyOf ( unusedKeywords , k ));
113108 return combined ;
114109 }
115110
@@ -122,7 +117,8 @@ Object[] applyUncached(Arity calleeArity, Object[] arguments, PKeyword[] keyword
122117 System .arraycopy (arguments , 0 , combined , 0 , arguments .length );
123118 }
124119
125- ArrayList <PKeyword > unusedKeywords = new ArrayList <>();
120+ PKeyword [] unusedKeywords = new PKeyword [keywords .length ];
121+ int k = 0 ;
126122 for (int i = 0 ; i < keywords .length ; i ++) {
127123 PKeyword kwArg = keywords [i ];
128124 int kwIdx = -1 ;
@@ -139,10 +135,10 @@ Object[] applyUncached(Arity calleeArity, Object[] arguments, PKeyword[] keyword
139135 }
140136 PArguments .setArgument (combined , kwIdx , kwArg .getValue ());
141137 } else {
142- unusedKeywords . add ( kwArg ) ;
138+ unusedKeywords [ k ++] = kwArg ;
143139 }
144140 }
145- PArguments .setKeywordArguments (combined , unusedKeywords . toArray ( new PKeyword [ unusedKeywords . size ()] ));
141+ PArguments .setKeywordArguments (combined , Arrays . copyOf ( unusedKeywords , k ));
146142 return combined ;
147143 }
148144
0 commit comments