Skip to content

Commit 2cdeedf

Browse files
committed
Do very fast check for 'ob_base'.
1 parent f9ce7a7 commit 2cdeedf

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130

131131
@MessageResolution(receiverType = PythonNativeWrapper.class)
132132
public class PythonObjectNativeWrapperMR {
133-
protected static String GP_OBJECT = "gp_object";
133+
private static final String GP_OBJECT = "gp_object";
134134

135135
@SuppressWarnings("unknown-message")
136136
@Resolve(message = "com.oracle.truffle.llvm.spi.GetDynamicType")
@@ -170,11 +170,17 @@ abstract static class ReadNode extends Node {
170170
@Child private ReadNativeMemberNode readNativeMemberNode;
171171
@Child private AsPythonObjectNode getDelegate;
172172

173+
@CompilationFinal private String cachedObBase;
174+
173175
public Object access(PythonNativeWrapper object, String key) {
174176
// The very common case: directly return native wrapper.
175177
// This is in particular important for PrimitiveNativeWrappers, since they are not
176178
// cached.
177-
if (key.equals(NativeMemberNames.OB_BASE)) {
179+
if (key == cachedObBase) {
180+
return object;
181+
} else if (cachedObBase == null && key.equals(NativeMemberNames.OB_BASE)) {
182+
CompilerDirectives.transferToInterpreterAndInvalidate();
183+
cachedObBase = key;
178184
return object;
179185
}
180186

0 commit comments

Comments
 (0)