Skip to content

Commit 313922b

Browse files
committed
[GR-24977] Improve isIdentical(OrUndefined) implementation of PythonAbstractNativeObject.
PullRequest: graalpython/1136
2 parents 2bc1468 + 14e9346 commit 313922b

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import com.oracle.truffle.api.dsl.Cached;
7676
import com.oracle.truffle.api.dsl.Cached.Exclusive;
7777
import com.oracle.truffle.api.dsl.Cached.Shared;
78+
import com.oracle.truffle.api.dsl.Fallback;
7879
import com.oracle.truffle.api.dsl.GenerateUncached;
7980
import com.oracle.truffle.api.dsl.Specialization;
8081
import com.oracle.truffle.api.interop.ArityException;
@@ -291,14 +292,31 @@ int identityHashCode(@CachedLibrary("this.object") InteropLibrary lib) throws Un
291292

292293
@ExportMessage
293294
boolean isIdentical(Object other, InteropLibrary otherInterop,
294-
@CachedLibrary("this.object") InteropLibrary lib) {
295-
return lib.isIdentical(object, other, otherInterop);
295+
@Cached("createClassProfile()") ValueProfile otherProfile,
296+
@CachedLibrary(limit = "1") InteropLibrary thisLib,
297+
@CachedLibrary("this.object") InteropLibrary objLib,
298+
@CachedLibrary(limit = "1") InteropLibrary otherObjLib) {
299+
Object profiled = otherProfile.profile(other);
300+
if (profiled instanceof PythonAbstractNativeObject) {
301+
return objLib.isIdentical(object, ((PythonAbstractNativeObject) profiled).object, otherObjLib);
302+
}
303+
return otherInterop.isIdentical(profiled, this, thisLib);
296304
}
297305

298306
@ExportMessage
299-
TriState isIdenticalOrUndefined(Object other,
300-
@CachedLibrary(limit = "3") InteropLibrary lib) {
301-
return TriState.valueOf(lib.isIdentical(object, other, lib));
307+
@SuppressWarnings("unused")
308+
static final class IsIdenticalOrUndefined {
309+
@Specialization
310+
static TriState doPythonAbstractNativeObject(PythonAbstractNativeObject receiver, PythonAbstractNativeObject other,
311+
@CachedLibrary("receiver.object") InteropLibrary objLib,
312+
@CachedLibrary(limit = "1") InteropLibrary otherObjectLib) {
313+
return TriState.valueOf(objLib.isIdentical(receiver.object, other.object, otherObjectLib));
314+
}
315+
316+
@Fallback
317+
static TriState doOther(PythonAbstractNativeObject receiver, Object other) {
318+
return TriState.UNDEFINED;
319+
}
302320
}
303321

304322
@ExportMessage(library = PythonObjectLibrary.class, name = "isLazyPythonClass")

0 commit comments

Comments
 (0)