Skip to content

Commit 6860a53

Browse files
committed
Avoid unnecessary wrapper allocation.
1 parent 2f16058 commit 6860a53

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/PythonObjectNativeWrapperMR.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,23 @@ private static Object findBuiltinClass(PythonClass klass) {
164164
@Resolve(message = "READ")
165165
abstract static class ReadNode extends Node {
166166
@Child private ReadNativeMemberNode readNativeMemberNode;
167-
@Child AsPythonObjectNode getDelegate = AsPythonObjectNode.create();
167+
@Child private AsPythonObjectNode getDelegate;
168168

169169
public Object access(PythonNativeWrapper object, String key) {
170-
// special key for the debugger
170+
// The very common case: directly return native wrapper.
171+
// This is in particular important for PrimitiveNativeWrappers, since they are not
172+
// cached.
173+
if (key.equals(NativeMemberNames.OB_BASE)) {
174+
return object;
175+
}
176+
177+
if (getDelegate == null) {
178+
CompilerDirectives.transferToInterpreterAndInvalidate();
179+
getDelegate = insert(AsPythonObjectNode.create());
180+
}
171181
Object delegate = getDelegate.execute(object);
182+
183+
// special key for the debugger
172184
if (key.equals(GP_OBJECT)) {
173185
return delegate;
174186
}

0 commit comments

Comments
 (0)