File tree Expand file tree Collapse file tree 1 file changed +22
-5
lines changed
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext Expand file tree Collapse file tree 1 file changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -1694,12 +1694,29 @@ public abstract static class GetSpecialSingletonPtrNode extends Node {
1694
1694
1695
1695
public abstract Object execute (Object obj );
1696
1696
1697
- @ Specialization
1698
- Object doGeneric (Object obj ,
1697
+ protected static Assumption singleContextAssumption () {
1698
+ return PythonLanguage .getCurrent ().singleContextAssumption ;
1699
+ }
1700
+
1701
+ // n.b.: since we guard that there is a pointer, we can be sure that
1702
+ // this is a singleton and we can cache it directly
1703
+ @ Specialization (guards = {"cachedObj == obj" , "ptr != null" }, assumptions = "singleContextAssumption()" )
1704
+ @ SuppressWarnings ("unused" )
1705
+ Object doCached (PythonAbstractObject obj ,
1706
+ @ CachedContext (PythonLanguage .class ) PythonContext context ,
1707
+ @ Cached ("obj" ) PythonAbstractObject cachedObj ,
1708
+ @ Cached ("context.getSingletonNativePtr(cachedObj)" ) Object ptr ) {
1709
+ return ptr ;
1710
+ }
1711
+
1712
+ @ Specialization (replaces = "doCached" )
1713
+ Object doAbstract (PythonAbstractObject obj ,
1699
1714
@ CachedContext (PythonLanguage .class ) PythonContext context ) {
1700
- if (obj instanceof PythonAbstractObject ) {
1701
- return context .getSingletonNativePtr ((PythonAbstractObject ) obj );
1702
- }
1715
+ return context .getSingletonNativePtr (obj );
1716
+ }
1717
+
1718
+ @ Fallback
1719
+ Object doGeneric (@ SuppressWarnings ("unused" ) Object obj ) {
1703
1720
return null ;
1704
1721
}
1705
1722
}
You can’t perform that action at this time.
0 commit comments