Skip to content

Commit ab58716

Browse files
committed
Remove method 'PByteArray.append'.
1 parent 0ece68f commit ab58716

File tree

2 files changed

+7
-30
lines changed

2 files changed

+7
-30
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
7979
import com.oracle.graal.python.runtime.sequence.storage.IntSequenceStorage;
8080
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
81-
import com.oracle.graal.python.runtime.sequence.storage.SequenceStoreException;
8281
import com.oracle.truffle.api.CompilerDirectives;
8382
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
8483
import com.oracle.truffle.api.dsl.Cached;
@@ -348,30 +347,16 @@ public Object repr(PByteArray self) {
348347
// bytearray.append(x)
349348
@Builtin(name = "append", fixedNumOfPositionalArgs = 2)
350349
@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);
367355
return byteArray;
368356
}
369357

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)"));
375360
}
376361
}
377362

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/PByteArray.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import com.oracle.graal.python.runtime.sequence.PSequence;
3434
import com.oracle.graal.python.runtime.sequence.SequenceUtil;
3535
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
36-
import com.oracle.graal.python.runtime.sequence.storage.EmptySequenceStorage;
3736
import com.oracle.graal.python.runtime.sequence.storage.NativeSequenceStorage;
3837
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
3938
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage.ListStorageType;
@@ -110,13 +109,6 @@ public final void clear() {
110109
store.clear();
111110
}
112111

113-
public final void append(Object value) {
114-
if (store instanceof EmptySequenceStorage) {
115-
store = new ByteSequenceStorage(1);
116-
}
117-
store.append(value);
118-
}
119-
120112
public PByteArray copy() {
121113
return new PByteArray(this.getPythonClass(), store.copy());
122114
}

0 commit comments

Comments
 (0)