|
220 | 220 | import com.oracle.graal.python.runtime.sequence.PSequenceWithStorage; |
221 | 221 | import com.oracle.graal.python.runtime.sequence.storage.BoolSequenceStorage; |
222 | 222 | import com.oracle.graal.python.runtime.sequence.storage.DoubleSequenceStorage; |
| 223 | +import com.oracle.graal.python.runtime.sequence.storage.EmptySequenceStorage; |
223 | 224 | import com.oracle.graal.python.runtime.sequence.storage.IntSequenceStorage; |
224 | 225 | import com.oracle.graal.python.runtime.sequence.storage.LongSequenceStorage; |
225 | 226 | import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage; |
@@ -1636,7 +1637,16 @@ public static Object perform(VirtualFrame frame, |
1636 | 1637 |
|
1637 | 1638 | @Operation(storeBytecodeIndex = false) |
1638 | 1639 | public static final class MakeList { |
1639 | | - @Specialization |
| 1640 | + @Specialization(guards = "elements.length == 0") |
| 1641 | + public static PList doEmpty(@Variadic Object[] elements, |
| 1642 | + @Bind PBytecodeDSLRootNode rootNode) { |
| 1643 | + // Common pattern is to create an empty list and then add items. |
| 1644 | + // We need to start from empty storage, so that we can specialize to, say, int storage |
| 1645 | + // if only ints are appended to this list |
| 1646 | + return PFactory.createList(rootNode.getLanguage(), EmptySequenceStorage.INSTANCE); |
| 1647 | + } |
| 1648 | + |
| 1649 | + @Specialization(guards = "elements.length > 0") |
1640 | 1650 | public static PList perform(@Variadic Object[] elements, |
1641 | 1651 | @Bind PBytecodeDSLRootNode rootNode) { |
1642 | 1652 | return PFactory.createList(rootNode.getLanguage(), elements); |
@@ -3210,7 +3220,7 @@ public static boolean doObject(long typeFlags, Object value, |
3210 | 3220 | @ImportStatic(PGuards.class) |
3211 | 3221 | public static final class BinarySubscript { |
3212 | 3222 | static boolean isBuiltinListOrTuple(PSequenceWithStorage s) { |
3213 | | - return PGuards.isBuiltinTuple(s) && PGuards.isBuiltinList(s); |
| 3223 | + return PGuards.isBuiltinTuple(s) || PGuards.isBuiltinList(s); |
3214 | 3224 | } |
3215 | 3225 |
|
3216 | 3226 | public static boolean isIntBuiltinListOrTuple(PSequenceWithStorage s) { |
|
0 commit comments