|
67 | 67 | import com.oracle.graal.python.builtins.objects.tuple.PTuple;
|
68 | 68 | import com.oracle.graal.python.nodes.SpecialMethodNames;
|
69 | 69 | import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
|
| 70 | +import com.oracle.graal.python.nodes.control.GetIteratorExpressionNode.GetIteratorNode; |
| 71 | +import com.oracle.graal.python.nodes.control.GetNextNode; |
70 | 72 | import com.oracle.graal.python.nodes.expression.BinaryComparisonNode;
|
71 | 73 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
72 | 74 | import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
|
73 | 75 | import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
|
74 | 76 | import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
|
75 | 77 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
|
76 | 78 | import com.oracle.graal.python.nodes.object.GetLazyClassNode;
|
| 79 | +import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile; |
77 | 80 | import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
|
| 81 | +import com.oracle.graal.python.runtime.exception.PException; |
78 | 82 | import com.oracle.graal.python.runtime.sequence.PSequence;
|
79 | 83 | import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
|
80 | 84 | import com.oracle.graal.python.runtime.sequence.storage.IntSequenceStorage;
|
@@ -478,15 +482,28 @@ abstract static class StartsWithNode extends PythonBuiltinNode {
|
478 | 482 | @Child private SequenceStorageNodes.LenNode lenNode;
|
479 | 483 |
|
480 | 484 | @Specialization
|
481 |
| - boolean startswith(PByteArray self, PTuple prefixes, @SuppressWarnings("unused") PNone start, @SuppressWarnings("unused") PNone end, |
482 |
| - @Cached("create()") BytesNodes.FindNode findNode) { |
483 |
| - for (Object arrayObj : prefixes.getArray()) { |
484 |
| - PIBytesLike array = (PIBytesLike) arrayObj; |
485 |
| - if (startswith(self, array, start, end, findNode)) { |
486 |
| - return true; |
| 485 | + boolean startswith(VirtualFrame frame, PByteArray self, PTuple prefixes, @SuppressWarnings("unused") PNone start, @SuppressWarnings("unused") PNone end, |
| 486 | + @Cached GetIteratorNode getIteratorNode, |
| 487 | + @Cached IsBuiltinClassProfile errorProfile, |
| 488 | + @Cached GetNextNode getNextNode, |
| 489 | + @Cached BytesNodes.FindNode findNode) { |
| 490 | + Object iterator = getIteratorNode.executeWith(frame, prefixes); |
| 491 | + while (true) { |
| 492 | + try { |
| 493 | + Object arrayObj = getNextNode.execute(frame, iterator); |
| 494 | + if (arrayObj instanceof PIBytesLike) { |
| 495 | + PIBytesLike array = (PIBytesLike) arrayObj; |
| 496 | + if (startswith(self, array, start, end, findNode)) { |
| 497 | + return true; |
| 498 | + } |
| 499 | + } else { |
| 500 | + throw raise(PythonBuiltinClassType.TypeError, "a bytes-like object is required, not '%p'", arrayObj); |
| 501 | + } |
| 502 | + } catch (PException e) { |
| 503 | + e.expectStopIteration(errorProfile); |
| 504 | + return false; |
487 | 505 | }
|
488 | 506 | }
|
489 |
| - return false; |
490 | 507 | }
|
491 | 508 |
|
492 | 509 | @Specialization
|
|
0 commit comments