|
56 | 56 | import com.oracle.graal.python.builtins.objects.tuple.PTuple;
|
57 | 57 | import com.oracle.graal.python.nodes.ErrorMessages;
|
58 | 58 | import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
|
59 |
| -import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode; |
60 | 59 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
61 | 60 | import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
|
62 | 61 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
|
@@ -278,43 +277,47 @@ public int lengthHint(PBigRangeIterator self,
|
278 | 277 | }
|
279 | 278 |
|
280 | 279 | @Specialization(guards = "!self.isExhausted()")
|
281 |
| - public double lengthHint(PDoubleSequenceIterator self) { |
| 280 | + public int lengthHint(PDoubleSequenceIterator self) { |
282 | 281 | int len = self.sequence.length() - self.getIndex();
|
283 | 282 | return len < 0 ? 0 : len;
|
284 | 283 | }
|
285 | 284 |
|
286 | 285 | @Specialization(guards = "!self.isExhausted()")
|
287 |
| - public long lengthHint(PLongSequenceIterator self) { |
| 286 | + public int lengthHint(PLongSequenceIterator self) { |
288 | 287 | int len = self.sequence.length() - self.getIndex();
|
289 | 288 | return len < 0 ? 0 : len;
|
290 | 289 | }
|
291 | 290 |
|
292 | 291 | @Specialization(guards = "!self.isExhausted()")
|
293 |
| - public long lengthHint(PBaseSetIterator self, |
| 292 | + public int lengthHint(PBaseSetIterator self, |
294 | 293 | @Cached ConditionProfile profile) {
|
295 | 294 | int size = self.getSize();
|
296 | 295 | if (profile.profile(self.getSet().size() != size)) {
|
297 | 296 | return 0;
|
298 | 297 | }
|
299 |
| - return size - self.getIndex(); |
| 298 | + int len = size - self.getIndex(); |
| 299 | + return len < 0 ? 0 : len; |
300 | 300 | }
|
301 | 301 |
|
302 | 302 | @Specialization(guards = "!self.isExhausted()")
|
303 |
| - public Object lengthHint(PStringIterator self) { |
304 |
| - return self.value.length() - self.getIndex(); |
| 303 | + public int lengthHint(PStringIterator self) { |
| 304 | + int len = self.value.length() - self.getIndex(); |
| 305 | + return len < 0 ? 0 : len; |
305 | 306 | }
|
306 | 307 |
|
307 | 308 | @Specialization(guards = {"!self.isExhausted()", "self.isPSequence()"})
|
308 |
| - public Object lengthHint(PSequenceIterator self, |
| 309 | + public int lengthHint(PSequenceIterator self, |
309 | 310 | @Cached SequenceNodes.LenNode lenNode) {
|
310 |
| - return lenNode.execute(self.getPSequence()) - self.getIndex(); |
| 311 | + int len = lenNode.execute(self.getPSequence()) - self.getIndex(); |
| 312 | + return len < 0 ? 0 : len; |
311 | 313 | }
|
312 | 314 |
|
313 |
| - @Specialization(guards = {"!self.isExhausted()", "!self.isPSequence()"}) |
314 |
| - public Object lengthHint(VirtualFrame frame, PSequenceIterator self, |
315 |
| - @Cached("create(__LEN__)") LookupAndCallUnaryNode callLen, |
316 |
| - @Cached("create(__SUB__, __RSUB__)") LookupAndCallBinaryNode callSub) { |
317 |
| - return callSub.executeObject(frame, callLen.executeObject(frame, self.getObject()), self.getIndex()); |
| 315 | + @Specialization(guards = {"!self.isExhausted()", "!self.isPSequence()"}, limit = "getCallSiteInlineCacheMaxDepth()") |
| 316 | + public int lengthHint(VirtualFrame frame, PSequenceIterator self, |
| 317 | + @CachedLibrary("self.getObject()") PythonObjectLibrary lib, |
| 318 | + @Cached ConditionProfile hasFrame) { |
| 319 | + int len = lib.lengthWithFrame(self.getObject(), hasFrame, frame) - self.getIndex(); |
| 320 | + return len < 0 ? 0 : len; |
318 | 321 | }
|
319 | 322 | }
|
320 | 323 |
|
|
0 commit comments