Skip to content

Commit e19e421

Browse files
committed
remove unnecessary TruffleBoundary for intrinsified call to arrayCopy
- reduce amount of inlined java lib code (ArrayList) - style fix
1 parent 7501965 commit e19e421

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,8 @@ public PZip zip(PythonClass cls, Object[] args,
14741474
}
14751475

14761476
// function(code, globals[, name[, argdefs[, closure]]])
1477-
@Builtin(name = "function", minNumOfPositionalArgs = 3, maxNumOfPositionalArgs = 6, constructsClass = {PythonBuiltinClassType.PFunction, PythonBuiltinClassType.PGeneratorFunction}, isPublic = false)
1477+
@Builtin(name = "function", minNumOfPositionalArgs = 3, maxNumOfPositionalArgs = 6, constructsClass = {PythonBuiltinClassType.PFunction,
1478+
PythonBuiltinClassType.PGeneratorFunction}, isPublic = false)
14781479
@GenerateNodeFactory
14791480
public abstract static class FunctionNode extends PythonBuiltinNode {
14801481

@@ -1498,7 +1499,8 @@ public PFunction function(Object cls, Object method_def, Object def, Object name
14981499

14991500
// type(object)
15001501
// type(object, bases, dict)
1501-
@Builtin(name = TYPE, minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 4, takesVarKeywordArgs = true, constructsClass = {PythonBuiltinClassType.PythonClass, PythonBuiltinClassType.PythonBuiltinClass})
1502+
@Builtin(name = TYPE, minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 4, takesVarKeywordArgs = true, constructsClass = {PythonBuiltinClassType.PythonClass,
1503+
PythonBuiltinClassType.PythonBuiltinClass})
15021504
@GenerateNodeFactory
15031505
public abstract static class TypeNode extends PythonBuiltinNode {
15041506
@Specialization(guards = {"isNoValue(bases)", "isNoValue(dict)"})
@@ -1935,7 +1937,8 @@ protected boolean isMapping(Object o) {
19351937
}
19361938
}
19371939

1938-
@Builtin(name = "getset_descriptor", constructsClass = {PythonBuiltinClassType.GetSetDescriptor}, isPublic = false, fixedNumOfPositionalArgs = 1, keywordArguments = {"fget", "fset", "name", "owner"})
1940+
@Builtin(name = "getset_descriptor", constructsClass = {PythonBuiltinClassType.GetSetDescriptor}, isPublic = false, fixedNumOfPositionalArgs = 1, keywordArguments = {"fget", "fset", "name",
1941+
"owner"})
19391942
@GenerateNodeFactory
19401943
@SuppressWarnings("unused")
19411944
public abstract static class GetSetDescriptorNode extends PythonBuiltinNode {

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,14 @@
4040
*/
4141
package com.oracle.graal.python.nodes.argument;
4242

43-
import java.util.ArrayList;
43+
import java.util.Arrays;
4444

4545
import com.oracle.graal.python.builtins.objects.function.Arity;
4646
import com.oracle.graal.python.builtins.objects.function.PArguments;
4747
import com.oracle.graal.python.builtins.objects.function.PKeyword;
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;
5251
import com.oracle.truffle.api.dsl.Cached;
5352
import com.oracle.truffle.api.dsl.Specialization;
5453
import 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

Comments
 (0)