Skip to content

Commit f0c2497

Browse files
committed
Address few review comments
1 parent b84cbd6 commit f0c2497

File tree

1 file changed

+12
-29
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array

1 file changed

+12
-29
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -706,32 +706,18 @@ Object extend(VirtualFrame frame, PArray self, PSequence value,
706706
@Cached SequenceStorageNodes.GetItemScalarNode getItemNode) {
707707
SequenceStorage storage = getSequenceStorageNode.execute(value);
708708
int storageLength = lenNode.execute(storage);
709-
boolean capacityEnsured = false;
710709
try {
711710
self.resizeStorage(PythonUtils.addExact(self.getLength(), storageLength));
712-
capacityEnsured = true;
713711
} catch (OverflowException e) {
714712
CompilerDirectives.transferToInterpreterAndInvalidate();
715-
// Let it fail later, so that it fails in the same state as the generic
716-
// specialization
713+
throw raise(MemoryError);
717714
}
718715
int length = self.getLength();
719716
for (int i = 0; i < storageLength; i++) {
720717
// The whole extend is not atomic, just individual inserts are. That's the same as
721718
// in CPython
722-
if (capacityEnsured) {
723-
length++;
724-
} else {
725-
try {
726-
length = PythonUtils.addExact(length, 1);
727-
self.resizeStorage(length);
728-
} catch (OverflowException e) {
729-
CompilerDirectives.transferToInterpreterAndInvalidate();
730-
throw raise(MemoryError);
731-
}
732-
}
733-
putValueNode.execute(frame, self, length - 1, getItemNode.execute(storage, i));
734-
self.setLength(length);
719+
putValueNode.execute(frame, self, length, getItemNode.execute(storage, i));
720+
self.setLength(++length);
735721
}
736722

737723
return PNone.NONE;
@@ -1101,24 +1087,21 @@ static Object byteswap1(@SuppressWarnings("unused") PArray self) {
11011087
return PNone.NONE;
11021088
}
11031089

1104-
@Specialization(guards = {"self.getFormat().bytesize == itemsize", "itemsize == 2"})
1105-
static Object byteswap2(PArray self,
1106-
@Cached("self.getFormat().bytesize") int itemsize) {
1107-
doByteSwapExploded(self, itemsize, self.getBuffer());
1090+
@Specialization(guards = "self.getFormat().bytesize == 2")
1091+
static Object byteswap2(PArray self) {
1092+
doByteSwapExploded(self, 2, self.getBuffer());
11081093
return PNone.NONE;
11091094
}
11101095

1111-
@Specialization(guards = {"self.getFormat().bytesize == itemsize", "itemsize == 4"})
1112-
static Object byteswap4(PArray self,
1113-
@Cached("self.getFormat().bytesize") int itemsize) {
1114-
doByteSwapExploded(self, itemsize, self.getBuffer());
1096+
@Specialization(guards = "self.getFormat().bytesize == 4")
1097+
static Object byteswap4(PArray self) {
1098+
doByteSwapExploded(self, 4, self.getBuffer());
11151099
return PNone.NONE;
11161100
}
11171101

1118-
@Specialization(guards = {"self.getFormat().bytesize == itemsize", "itemsize == 8"})
1119-
static Object byteswap8(PArray self,
1120-
@Cached("self.getFormat().bytesize") int itemsize) {
1121-
doByteSwapExploded(self, itemsize, self.getBuffer());
1102+
@Specialization(guards = "self.getFormat().bytesize == 8")
1103+
static Object byteswap8(PArray self) {
1104+
doByteSwapExploded(self, 8, self.getBuffer());
11221105
return PNone.NONE;
11231106
}
11241107

0 commit comments

Comments
 (0)