@@ -85,12 +85,6 @@ protected PythonClass getIt(@SuppressWarnings("unused") GetSetDescriptor object)
85
85
return getCore ().lookupType (PythonBuiltinClassType .GetSetDescriptor );
86
86
}
87
87
88
- @ Specialization (guards = "!isNone(object)" )
89
- protected PythonClass getIt (PythonObject object ,
90
- @ Cached ("createIdentityProfile()" ) ValueProfile profile ) {
91
- return profile .profile (object .getPythonClass ());
92
- }
93
-
94
88
@ Specialization (assumptions = "singleContextAssumption()" )
95
89
protected PythonClass getIt (@ SuppressWarnings ("unused" ) PNone object ,
96
90
@ Cached ("getIt(object)" ) PythonClass klass ) {
@@ -197,6 +191,28 @@ protected PythonClass getIt(PythonNativeObject object,
197
191
return getNativeClassNode .execute (object );
198
192
}
199
193
194
+ @ SuppressWarnings ("unchecked" )
195
+ protected Class <? extends PythonObject > asPythonObjectSubclass (Class <? extends Object > clazz ) {
196
+ Class <? extends PythonObject > retval = null ;
197
+ if (PythonObject .class .isAssignableFrom (clazz )) {
198
+ retval = (Class <? extends PythonObject >) clazz ;
199
+ }
200
+ return retval ;
201
+ }
202
+
203
+ @ Specialization (guards = {"object.getClass() == cachedClass" }, limit = "5" )
204
+ protected PythonClass getPythonClassCached (Object object ,
205
+ @ Cached ("asPythonObjectSubclass(object.getClass())" ) Class <? extends PythonObject > cachedClass ,
206
+ @ Cached ("createIdentityProfile()" ) ValueProfile profile ) {
207
+ return profile .profile (cachedClass .cast (object ).getPythonClass ());
208
+ }
209
+
210
+ @ Specialization (replaces = "getPythonClassCached" )
211
+ protected PythonClass getPythonClassGeneric (PythonObject object ,
212
+ @ Cached ("createIdentityProfile()" ) ValueProfile profile ) {
213
+ return profile .profile (object .getPythonClass ());
214
+ }
215
+
200
216
@ Specialization (guards = "isForeignObject(object)" , assumptions = "singleContextAssumption()" )
201
217
protected PythonClass getIt (@ SuppressWarnings ("unused" ) TruffleObject object ,
202
218
@ Cached ("getIt(object)" ) PythonClass klass ) {
0 commit comments