Skip to content

Commit 5ffe3d7

Browse files
committed
fix concatenation and generalization of empty ListStorage list
1 parent 9246001 commit 5ffe3d7

File tree

3 files changed

+12
-41
lines changed

3 files changed

+12
-41
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,7 @@ private SequenceStorage createEmpty(SequenceStorage l, SequenceStorage r, int le
20122012
return createEmptyNode.execute(r, len);
20132013
}
20142014
SequenceStorage empty = createEmptyNode.execute(l, len);
2015+
empty.ensureCapacity(len);
20152016
empty.setNewLength(len);
20162017
return empty;
20172018
}
@@ -2427,8 +2428,8 @@ DoubleSequenceStorage doEmptyDouble(@SuppressWarnings("unused") EmptySequenceSto
24272428
}
24282429

24292430
@Specialization
2430-
ListSequenceStorage doEmptyPList(@SuppressWarnings("unused") EmptySequenceStorage s, PList val) {
2431-
return new ListSequenceStorage(val.getSequenceStorage());
2431+
ListSequenceStorage doEmptyPList(@SuppressWarnings("unused") EmptySequenceStorage s, @SuppressWarnings("unused") PList val) {
2432+
return new ListSequenceStorage(0);
24322433
}
24332434

24342435
@Specialization
@@ -2623,9 +2624,9 @@ DoubleSequenceStorage doDouble(@SuppressWarnings("unused") SequenceStorage s, in
26232624
}
26242625

26252626
@Specialization(guards = "isList(s)")
2626-
ListSequenceStorage doList(@SuppressWarnings("unused") SequenceStorage s, @SuppressWarnings("unused") int cap) {
2627+
ListSequenceStorage doList(@SuppressWarnings("unused") SequenceStorage s, int cap) {
26272628
// TODO not quite accurate in case of native sequence storage
2628-
return new ListSequenceStorage(s);
2629+
return new ListSequenceStorage(cap);
26292630
}
26302631

26312632
@Specialization(guards = "isTuple(s)")

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/EmptySequenceStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public SequenceStorage generalizeFor(Object value, SequenceStorage target) {
5757
} else if (value instanceof Double) {
5858
generalized = new DoubleSequenceStorage();
5959
} else if (value instanceof PList) {
60-
generalized = new ListSequenceStorage(((PList) value).getSequenceStorage());
60+
generalized = new ListSequenceStorage(0);
6161
} else if (value instanceof PTuple) {
6262
generalized = new TupleSequenceStorage();
6363
} else {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/ListSequenceStorage.java

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,49 +32,23 @@
3232
public final class ListSequenceStorage extends TypedSequenceStorage {
3333

3434
private PList[] values;
35-
private Class<?> kind;
36-
37-
public ListSequenceStorage(SequenceStorage elementSample) {
38-
values = new PList[]{};
39-
if (elementSample instanceof ListSequenceStorage) {
40-
ListSequenceStorage list = (ListSequenceStorage) elementSample;
41-
this.kind = list.getKind();
42-
} else {
43-
this.kind = elementSample.getClass();
44-
}
45-
}
4635

4736
public ListSequenceStorage(PList[] elements) {
48-
this(elements, elements[0].getSequenceStorage().getClass());
49-
if (kind == ListSequenceStorage.class)
50-
this.kind = ((ListSequenceStorage) elements[0].getSequenceStorage()).getKind();
51-
}
52-
53-
public ListSequenceStorage(PList[] elements, int length) {
54-
this(elements, elements[0].getSequenceStorage().getClass(), length);
55-
if (kind == ListSequenceStorage.class)
56-
this.kind = ((ListSequenceStorage) elements[0].getSequenceStorage()).getKind();
57-
}
58-
59-
public ListSequenceStorage(PList[] elements, Class<?> kind) {
6037
this.values = elements;
6138
capacity = values.length;
6239
length = elements.length;
63-
this.kind = kind;
6440
}
6541

66-
public ListSequenceStorage(PList[] elements, Class<?> kind, int length) {
42+
public ListSequenceStorage(PList[] elements, int length) {
6743
this.values = elements;
6844
capacity = values.length;
6945
this.length = length;
70-
this.kind = kind;
7146
}
7247

73-
public ListSequenceStorage(int capacity, Class<?> kind) {
48+
public ListSequenceStorage(int capacity) {
7449
this.values = new PList[capacity];
7550
this.capacity = capacity;
7651
length = 0;
77-
this.kind = kind;
7852
}
7953

8054
@Override
@@ -91,16 +65,12 @@ protected void increaseCapacityExact(int newCapacity) {
9165

9266
@Override
9367
public SequenceStorage copy() {
94-
return new ListSequenceStorage(Arrays.copyOf(values, length), this.kind);
68+
return new ListSequenceStorage(Arrays.copyOf(values, length));
9569
}
9670

9771
@Override
9872
public SequenceStorage createEmpty(int newCapacity) {
99-
return new ListSequenceStorage(newCapacity, this.kind);
100-
}
101-
102-
public Class<?> getKind() {
103-
return kind;
73+
return new ListSequenceStorage(newCapacity);
10474
}
10575

10676
@Override
@@ -175,14 +145,14 @@ public SequenceStorage getSliceInBound(int start, int stop, int step, int sliceL
175145

176146
if (step == 1) {
177147
System.arraycopy(values, start, newArray, 0, sliceLength);
178-
return new ListSequenceStorage(newArray, this.kind);
148+
return new ListSequenceStorage(newArray);
179149
}
180150

181151
for (int i = start, j = 0; j < sliceLength; i += step, j++) {
182152
newArray[j] = values[i];
183153
}
184154

185-
return new ListSequenceStorage(newArray, this.kind);
155+
return new ListSequenceStorage(newArray);
186156
}
187157

188158
public void setListSliceInBound(int start, int stop, int step, ListSequenceStorage sequence) {

0 commit comments

Comments
 (0)