|
78 | 78 | import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
|
79 | 79 | import com.oracle.graal.python.runtime.sequence.storage.IntSequenceStorage;
|
80 | 80 | import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
|
81 |
| -import com.oracle.graal.python.runtime.sequence.storage.SequenceStoreException; |
82 | 81 | import com.oracle.truffle.api.CompilerDirectives;
|
83 | 82 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
84 | 83 | import com.oracle.truffle.api.dsl.Cached;
|
@@ -348,30 +347,16 @@ public Object repr(PByteArray self) {
|
348 | 347 | // bytearray.append(x)
|
349 | 348 | @Builtin(name = "append", fixedNumOfPositionalArgs = 2)
|
350 | 349 | @GenerateNodeFactory
|
351 |
| - public abstract static class ByteArrayAppendNode extends PythonBuiltinNode { |
352 |
| - |
353 |
| - @Specialization(guards = "isEmptyStorage(byteArray)") |
354 |
| - public PByteArray appendEmpty(PByteArray byteArray, Object arg) { |
355 |
| - byteArray.append(arg); |
356 |
| - return byteArray; |
357 |
| - } |
358 |
| - |
359 |
| - @Specialization(guards = "isByteStorage(byteArray)") |
360 |
| - public PByteArray appendInt(PByteArray byteArray, int arg) { |
361 |
| - ByteSequenceStorage store = (ByteSequenceStorage) byteArray.getSequenceStorage(); |
362 |
| - try { |
363 |
| - store.appendInt(arg); |
364 |
| - } catch (SequenceStoreException e) { |
365 |
| - throw raise(ValueError, "byte must be in range(0, 256)"); |
366 |
| - } |
| 350 | + public abstract static class ByteArrayAppendNode extends PythonBinaryBuiltinNode { |
| 351 | + @Specialization |
| 352 | + public PByteArray append(PByteArray byteArray, Object arg, |
| 353 | + @Cached("createAppend()") SequenceStorageNodes.AppendNode appendNode) { |
| 354 | + appendNode.execute(byteArray.getSequenceStorage(), arg); |
367 | 355 | return byteArray;
|
368 | 356 | }
|
369 | 357 |
|
370 |
| - @Specialization(guards = "isByteStorage(byteArray)") |
371 |
| - public PByteArray appendInt(PByteArray byteArray, byte arg) { |
372 |
| - ByteSequenceStorage store = (ByteSequenceStorage) byteArray.getSequenceStorage(); |
373 |
| - store.appendByte(arg); |
374 |
| - return byteArray; |
| 358 | + protected static SequenceStorageNodes.AppendNode createAppend() { |
| 359 | + return SequenceStorageNodes.AppendNode.create(() -> NoGeneralizationNode.create("byte must be in range(0, 256)")); |
375 | 360 | }
|
376 | 361 | }
|
377 | 362 |
|
|
0 commit comments