@@ -306,15 +306,15 @@ static boolean doPNoneObject(PNone left, Object right,
306
306
}
307
307
308
308
// pstring (may be interned)
309
- @ Specialization
309
+ @ Specialization ( limit = "1" )
310
310
static boolean doPString (PString left , PString right ,
311
- @ CachedLibrary (limit = "2 " ) PythonObjectLibrary lib ) {
311
+ @ CachedLibrary ("left " ) PythonObjectLibrary lib ) {
312
312
return lib .isSame (left , right );
313
313
}
314
314
315
315
// everything else
316
- @ Specialization (limit = "getCallSiteInlineCacheMaxDepth()" )
317
- static boolean doGeneric (Object left , Object right ,
316
+ @ Specialization (guards = "isFallbackCase(left, right)" , limit = "getCallSiteInlineCacheMaxDepth()" )
317
+ static boolean doOther (Object left , Object right ,
318
318
@ CachedLibrary ("left" ) PythonObjectLibrary lib ) {
319
319
if (left == right ) {
320
320
return true ;
@@ -330,6 +330,42 @@ static boolean doGeneric(Object left, Object right,
330
330
return false ;
331
331
}
332
332
333
+ private static boolean isPrimitive (Object object ) {
334
+ return object instanceof Boolean || object instanceof Integer || object instanceof Long || object instanceof Double ;
335
+ }
336
+
337
+ private static boolean isBuiltinClassCase (Object left , Object right ) {
338
+ return left instanceof PythonBuiltinClassType && right instanceof PythonBuiltinClass ;
339
+ }
340
+
341
+ static boolean isFallbackCase (Object left , Object right ) {
342
+ if (isPrimitive (left ) && isPrimitive (right )) {
343
+ return false ;
344
+ }
345
+ if (left instanceof Boolean && right instanceof PInt || left instanceof PInt && right instanceof Boolean ) {
346
+ return false ;
347
+ }
348
+ if (left instanceof Integer && right instanceof PInt || left instanceof PInt && right instanceof Integer ) {
349
+ return false ;
350
+ }
351
+ if (left instanceof PythonAbstractNativeObject && right instanceof PythonAbstractNativeObject ) {
352
+ return false ;
353
+ }
354
+ if (left instanceof PString && right instanceof PString ) {
355
+ return false ;
356
+ }
357
+ if (isBuiltinClassCase (left , right ) || isBuiltinClassCase (right , left )) {
358
+ return false ;
359
+ }
360
+ if (left instanceof PCode && right instanceof PCode ) {
361
+ return false ;
362
+ }
363
+ if (left instanceof PNone || right instanceof PNone ) {
364
+ return false ;
365
+ }
366
+ return true ;
367
+ }
368
+
333
369
public static IsNode create () {
334
370
return IsNodeGen .create ();
335
371
}
0 commit comments