Skip to content

Commit f5ea50b

Browse files
committed
use Python identity has identityHashCode for interop
1 parent 46adeb8 commit f5ea50b

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474

7575
import com.oracle.graal.python.PythonLanguage;
7676
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
77+
import com.oracle.graal.python.builtins.modules.BuiltinFunctions;
7778
import com.oracle.graal.python.builtins.modules.MathGuards;
7879
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
7980
import com.oracle.graal.python.builtins.objects.cext.CApiGuards;
@@ -2026,19 +2027,13 @@ public Object getMetaObject(@Shared("getClassThis") @Cached GetClassNode getClas
20262027
}
20272028

20282029
@ExportMessage
2029-
public int identityHashCode(
2030-
@CachedLibrary("this") PythonObjectLibrary objectLib) {
2031-
if (objectLib.isHashable(this)) {
2032-
return Long.hashCode(objectLib.hash(this));
2033-
} else {
2034-
// everything in Python has an identity, but not everything provides a __hash__ method
2035-
return systemHashCode(this);
2036-
}
2030+
public int identityHashCode(@Cached BuiltinFunctions.IdExpressionNode idNode) {
2031+
return Long.hashCode(idNode.executeLong(0));
20372032
}
20382033

20392034
@TruffleBoundary
2040-
public static int systemHashCode(Object obj) {
2041-
return System.identityHashCode(obj);
2035+
public static int systemHashCode(Object value) {
2036+
return System.identityHashCode(value);
20422037
}
20432038

20442039
@ExportMessage

0 commit comments

Comments
 (0)