|
97 | 97 | import com.oracle.graal.python.builtins.objects.bytes.PBytes;
|
98 | 98 | import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary;
|
99 | 99 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.EnsureCapacityNode;
|
| 100 | +import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.GetCapacityNode; |
100 | 101 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.GetInternalArrayNode;
|
101 | 102 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.GetInternalByteArrayNode;
|
102 | 103 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.GetInternalObjectArrayNode;
|
@@ -684,24 +685,27 @@ protected static boolean shouldCopy(PBytesIO self) {
|
684 | 685 | return self.getStringSize() <= 1 || self.getExports() > 0;
|
685 | 686 | }
|
686 | 687 |
|
687 |
| - protected static boolean shouldUnshare(PBytesIO self) { |
688 |
| - return self.getStringSize() != self.getBufCapacity(); |
| 688 | + protected static boolean shouldUnshare(GetCapacityNode getCapacityNode, PBytesIO self) { |
| 689 | + int capacity = getCapacityNode.execute(self.getBuf().getSequenceStorage()); |
| 690 | + return self.getStringSize() != capacity; |
689 | 691 | }
|
690 | 692 |
|
691 | 693 | @Specialization(guards = {"self.hasBuf()", "shouldCopy(self)"})
|
692 |
| - Object copy(PBytesIO self, |
| 694 | + Object doCopy(PBytesIO self, |
693 | 695 | @Cached GetInternalByteArrayNode getBytes) {
|
694 | 696 | byte[] buf = getBytes.execute(self.getBuf().getSequenceStorage());
|
695 | 697 | return factory().createBytes(PythonUtils.arrayCopyOf(buf, self.getStringSize()));
|
696 | 698 | }
|
697 | 699 |
|
698 |
| - @Specialization(guards = {"self.hasBuf()", "!shouldCopy(self)", "!shouldUnshare(self)"}) |
699 |
| - static Object doit(PBytesIO self) { |
| 700 | + @Specialization(guards = {"self.hasBuf()", "!shouldCopy(self)", "!shouldUnshare(getCapacityNode, self)"}, limit = "1") |
| 701 | + static Object doShare(PBytesIO self, |
| 702 | + @SuppressWarnings("unused") @Shared("getCapacityNode") @Cached GetCapacityNode getCapacityNode) { |
700 | 703 | return self.getBuf();
|
701 | 704 | }
|
702 | 705 |
|
703 |
| - @Specialization(guards = {"self.hasBuf()", "!shouldCopy(self)", "shouldUnshare(self)"}) |
704 |
| - Object unshare(PBytesIO self, |
| 706 | + @Specialization(guards = {"self.hasBuf()", "!shouldCopy(self)", "shouldUnshare(getCapacityNode, self)"}, limit = "1") |
| 707 | + Object doUnshare(PBytesIO self, |
| 708 | + @SuppressWarnings("unused") @Shared("getCapacityNode") @Cached GetCapacityNode getCapacityNode, |
705 | 709 | @Cached GetInternalArrayNode internalArray) {
|
706 | 710 | // if (SHARED_BUF(self))
|
707 | 711 | unshareBuffer(self, self.getStringSize(), internalArray, factory());
|
|
0 commit comments