40
40
*/
41
41
package com .oracle .graal .python .nodes .argument ;
42
42
43
- import java .util .ArrayList ;
43
+ import java .util .Arrays ;
44
44
45
45
import com .oracle .graal .python .builtins .objects .function .Arity ;
46
46
import com .oracle .graal .python .builtins .objects .function .PArguments ;
47
47
import com .oracle .graal .python .builtins .objects .function .PKeyword ;
48
48
import com .oracle .graal .python .nodes .PBaseNode ;
49
49
import com .oracle .graal .python .nodes .argument .ApplyKeywordsNodeGen .SearchNamedParameterNodeGen ;
50
50
import com .oracle .graal .python .runtime .exception .PythonErrorType ;
51
- import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
52
51
import com .oracle .truffle .api .dsl .Cached ;
53
52
import com .oracle .truffle .api .dsl .Specialization ;
54
53
import com .oracle .truffle .api .nodes .ExplodeLoop ;
@@ -72,11 +71,6 @@ SearchNamedParameterNode createSearchNamedParameterNode() {
72
71
return SearchNamedParameterNodeGen .create ();
73
72
}
74
73
75
- @ TruffleBoundary
76
- private static void copyArgs (Object [] src , Object [] dst , int len ) {
77
- System .arraycopy (src , 0 , dst , 0 , len );
78
- }
79
-
80
74
@ Specialization (guards = {"kwLen == keywords.length" , "argLen == arguments.length" , "calleeArity == cachedArity" })
81
75
@ ExplodeLoop
82
76
Object [] applyCached (Arity calleeArity , Object [] arguments , PKeyword [] keywords ,
@@ -90,10 +84,11 @@ Object[] applyCached(Arity calleeArity, Object[] arguments, PKeyword[] keywords,
90
84
Object [] combined = arguments ;
91
85
if (expandArgs .profile (paramLen > userArgLen )) {
92
86
combined = PArguments .create (paramLen );
93
- copyArgs (arguments , combined , argLen );
87
+ System . arraycopy (arguments , 0 , combined , 0 , argLen );
94
88
}
95
89
96
- ArrayList <PKeyword > unusedKeywords = new ArrayList <>();
90
+ PKeyword [] unusedKeywords = new PKeyword [kwLen ];
91
+ int k = 0 ;
97
92
for (int i = 0 ; i < kwLen ; i ++) {
98
93
PKeyword kwArg = keywords [i ];
99
94
int kwIdx = searchParamNode .execute (parameters , kwArg .getName ());
@@ -106,10 +101,10 @@ Object[] applyCached(Arity calleeArity, Object[] arguments, PKeyword[] keywords,
106
101
}
107
102
PArguments .setArgument (combined , kwIdx , kwArg .getValue ());
108
103
} else {
109
- unusedKeywords . add ( kwArg ) ;
104
+ unusedKeywords [ k ++] = kwArg ;
110
105
}
111
106
}
112
- PArguments .setKeywordArguments (combined , unusedKeywords . toArray ( new PKeyword [ unusedKeywords . size ()] ));
107
+ PArguments .setKeywordArguments (combined , Arrays . copyOf ( unusedKeywords , k ));
113
108
return combined ;
114
109
}
115
110
@@ -122,7 +117,8 @@ Object[] applyUncached(Arity calleeArity, Object[] arguments, PKeyword[] keyword
122
117
System .arraycopy (arguments , 0 , combined , 0 , arguments .length );
123
118
}
124
119
125
- ArrayList <PKeyword > unusedKeywords = new ArrayList <>();
120
+ PKeyword [] unusedKeywords = new PKeyword [keywords .length ];
121
+ int k = 0 ;
126
122
for (int i = 0 ; i < keywords .length ; i ++) {
127
123
PKeyword kwArg = keywords [i ];
128
124
int kwIdx = -1 ;
@@ -139,10 +135,10 @@ Object[] applyUncached(Arity calleeArity, Object[] arguments, PKeyword[] keyword
139
135
}
140
136
PArguments .setArgument (combined , kwIdx , kwArg .getValue ());
141
137
} else {
142
- unusedKeywords . add ( kwArg ) ;
138
+ unusedKeywords [ k ++] = kwArg ;
143
139
}
144
140
}
145
- PArguments .setKeywordArguments (combined , unusedKeywords . toArray ( new PKeyword [ unusedKeywords . size ()] ));
141
+ PArguments .setKeywordArguments (combined , Arrays . copyOf ( unusedKeywords , k ));
146
142
return combined ;
147
143
}
148
144
0 commit comments