@@ -2104,28 +2104,39 @@ public TriState isIdenticalOrUndefined(Object other,
2104
2104
* {@code tp_iter} for every user class.
2105
2105
*/
2106
2106
@ ExportMessage
2107
- public Object getIteratorWithState (ThreadState state ,
2108
- @ Cached ("createIdentityProfile()" ) ValueProfile iterMethodProfile ,
2109
- @ CachedLibrary ("this" ) PythonObjectLibrary plib ,
2110
- @ CachedLibrary (limit = "2" ) PythonObjectLibrary methodLib ,
2111
- @ Cached IteratorNodes .IsIteratorObjectNode isIteratorObjectNode ,
2112
- @ Cached PythonObjectFactory factory ,
2113
- @ Shared ("raise" ) @ Cached PRaiseNode raise ) {
2114
- Object v = plib .getDelegatedValue (this );
2115
- Object iterMethod = iterMethodProfile .profile (plib .lookupAttributeOnType (this , __ITER__ ));
2116
- if (iterMethod != PNone .NONE ) {
2117
- if (iterMethod != PNone .NO_VALUE ) {
2118
- Object iterObj = methodLib .callUnboundMethodIgnoreGetExceptionWithState (iterMethod , state , v );
2119
- if (iterObj != PNone .NO_VALUE && isIteratorObjectNode .execute (iterObj )) {
2120
- return iterObj ;
2121
- }
2107
+ public static class GetIteratorWithState {
2108
+ public static final ValueProfile createIterMethodProfile () {
2109
+ if (singleContextAssumption ().isValid ()) {
2110
+ return ValueProfile .createIdentityProfile ();
2122
2111
} else {
2123
- Object getItemAttrObj = plib .lookupAttributeOnType (this , __GETITEM__ );
2124
- if (getItemAttrObj != PNone .NO_VALUE ) {
2125
- return factory .createSequenceIterator (v );
2112
+ return ValueProfile .createClassProfile ();
2113
+ }
2114
+ }
2115
+
2116
+ @ Specialization
2117
+ public static Object getIteratorWithState (PythonAbstractObject self , ThreadState state ,
2118
+ @ Cached ("createIterMethodProfile()" ) ValueProfile iterMethodProfile ,
2119
+ @ CachedLibrary ("self" ) PythonObjectLibrary plib ,
2120
+ @ CachedLibrary (limit = "2" ) PythonObjectLibrary methodLib ,
2121
+ @ Cached IteratorNodes .IsIteratorObjectNode isIteratorObjectNode ,
2122
+ @ Cached PythonObjectFactory factory ,
2123
+ @ Shared ("raise" ) @ Cached PRaiseNode raise ) {
2124
+ Object v = plib .getDelegatedValue (self );
2125
+ Object iterMethod = iterMethodProfile .profile (plib .lookupAttributeOnType (self , __ITER__ ));
2126
+ if (iterMethod != PNone .NONE ) {
2127
+ if (iterMethod != PNone .NO_VALUE ) {
2128
+ Object iterObj = methodLib .callUnboundMethodIgnoreGetExceptionWithState (iterMethod , state , v );
2129
+ if (iterObj != PNone .NO_VALUE && isIteratorObjectNode .execute (iterObj )) {
2130
+ return iterObj ;
2131
+ }
2132
+ } else {
2133
+ Object getItemAttrObj = plib .lookupAttributeOnType (self , __GETITEM__ );
2134
+ if (getItemAttrObj != PNone .NO_VALUE ) {
2135
+ return factory .createSequenceIterator (v );
2136
+ }
2126
2137
}
2127
2138
}
2139
+ throw raise .raise (PythonErrorType .TypeError , ErrorMessages .OBJ_NOT_ITERABLE , self );
2128
2140
}
2129
- throw raise .raise (PythonErrorType .TypeError , ErrorMessages .OBJ_NOT_ITERABLE , this );
2130
2141
}
2131
2142
}
0 commit comments