Skip to content

Commit 0b50030

Browse files
committed
Fix: avoid unnecessary copy of sequence when replacing whole sequence.
1 parent e1674f7 commit 0b50030

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,24 @@ protected SequenceStorage doScalarGeneric(SequenceStorage storage, Object idx, O
11611161
}
11621162

11631163
@Specialization
1164-
protected SequenceStorage doSlice(SequenceStorage storage, PSlice slice, Object iterable,
1164+
protected SequenceStorage doSliceSequence(SequenceStorage storage, PSlice slice, PSequence sequence,
1165+
@Shared("generalizeProfile") @Cached BranchProfile generalizeProfile,
1166+
@Cached SetItemSliceNode setItemSliceNode,
1167+
@Cached LenNode lenNode) {
1168+
SliceInfo info = slice.computeIndices(lenNode.execute(storage));
1169+
try {
1170+
setItemSliceNode.execute(storage, info, sequence);
1171+
return storage;
1172+
} catch (SequenceStoreException e) {
1173+
generalizeProfile.enter();
1174+
SequenceStorage generalized = generalizeStore(storage, e.getIndicationValue());
1175+
setItemSliceNode.execute(generalized, info, sequence);
1176+
return generalized;
1177+
}
1178+
}
1179+
1180+
@Specialization(replaces = "doSliceSequence")
1181+
protected SequenceStorage doSliceGeneric(SequenceStorage storage, PSlice slice, Object iterable,
11651182
@Shared("generalizeProfile") @Cached BranchProfile generalizeProfile,
11661183
@Cached SetItemSliceNode setItemSliceNode,
11671184
@Cached ListNodes.ConstructListNode constructListNode) {
@@ -2010,12 +2027,12 @@ byte[] doNativeByte(NativeSequenceStorage s) {
20102027
return barr;
20112028
}
20122029

2013-
@Specialization(guards = { "len(lenNode, s) == cachedLen", "cachedLen <= 32"})
2030+
@Specialization(guards = {"len(lenNode, s) == cachedLen", "cachedLen <= 32"})
20142031
@ExplodeLoop
20152032
byte[] doGenericLenCached(SequenceStorage s,
2016-
@Cached CastToByteNode castToByteNode,
2017-
@Cached @SuppressWarnings("unused") LenNode lenNode,
2018-
@Cached("len(lenNode, s)") int cachedLen) {
2033+
@Cached CastToByteNode castToByteNode,
2034+
@Cached @SuppressWarnings("unused") LenNode lenNode,
2035+
@Cached("len(lenNode, s)") int cachedLen) {
20192036
byte[] barr = new byte[cachedLen];
20202037
for (int i = 0; i < cachedLen; i++) {
20212038
barr[i] = castToByteNode.execute(getGetItemNode().execute(s, i));

0 commit comments

Comments
 (0)