Skip to content

Commit d3c5945

Browse files
committed
use System.arraycopy instead of exploded loop to init args (profile the case where this happens)
1 parent 2d23fc0 commit d3c5945

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/ApplyKeywordsNode.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,16 @@
4848
import com.oracle.graal.python.nodes.PBaseNode;
4949
import com.oracle.graal.python.nodes.argument.ApplyKeywordsNodeGen.SearchNamedParameterNodeGen;
5050
import com.oracle.graal.python.runtime.exception.PythonErrorType;
51+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5152
import com.oracle.truffle.api.dsl.Cached;
5253
import com.oracle.truffle.api.dsl.Specialization;
5354
import com.oracle.truffle.api.nodes.ExplodeLoop;
5455
import com.oracle.truffle.api.nodes.Node;
56+
import com.oracle.truffle.api.profiles.ConditionProfile;
5557

5658
public 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

Comments
 (0)