Skip to content

Commit e2cb219

Browse files
committed
Extract common method for creating empty bytes objects
1 parent 8073dc0 commit e2cb219

19 files changed

+33
-40
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteCodecUtil.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
6767
import static com.oracle.graal.python.runtime.exception.PythonErrorType.UnicodeDecodeError;
6868
import static com.oracle.graal.python.runtime.exception.PythonErrorType.UnicodeEncodeError;
69-
import static com.oracle.graal.python.util.PythonUtils.EMPTY_BYTE_ARRAY;
7069
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
7170
import static com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
7271

@@ -427,7 +426,7 @@ static void decerror(VirtualFrame frame, MultibyteCodec codec,
427426
protected static PBytes encodeEmptyInput(int len, int flags,
428427
PythonObjectFactory factory) {
429428
if (len == 0 && (flags & MBENC_RESET) == 0) {
430-
return factory.createBytes(EMPTY_BYTE_ARRAY);
429+
return factory.createEmptyBytes();
431430
}
432431
return null;
433432
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCArrayBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ static Object Array_subscript(CDataObject self, PSlice slice,
273273
byte[] ptr = bufferLib.getInternalOrCopiedByteArray(self);
274274

275275
if (slicelen <= 0) {
276-
return factory.createBytes(PythonUtils.EMPTY_BYTE_ARRAY);
276+
return factory.createEmptyBytes();
277277
}
278278
if (sliceInfo.step == 1) {
279279
return factory.createBytes(ptr, sliceInfo.start, slicelen);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCPointerBuiltins.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
9191
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
9292
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
93-
import com.oracle.graal.python.util.PythonUtils;
9493
import com.oracle.truffle.api.dsl.Bind;
9594
import com.oracle.truffle.api.dsl.Cached;
9695
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -355,7 +354,7 @@ static Object Pointer_subscriptSlice(VirtualFrame frame, CDataObject self, PSlic
355354
byte[] ptr = bufferLib.getInternalOrCopiedByteArray(self);
356355

357356
if (len <= 0) {
358-
return factory.createBytes(PythonUtils.EMPTY_BYTE_ARRAY);
357+
return factory.createEmptyBytes();
359358
}
360359
if (step == 1) {
361360
return factory.createBytes(ptr, start, len);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedReaderMixinBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public static boolean isReadFast(PBuffered self, int size) {
252252
Object empty(VirtualFrame frame, PBuffered self, @SuppressWarnings("unused") int size,
253253
@Shared @Cached PythonObjectFactory factory) {
254254
checkIsClosedNode.execute(frame, self);
255-
return factory.createBytes(PythonUtils.EMPTY_BYTE_ARRAY);
255+
return factory.createEmptyBytes();
256256
}
257257

258258
/*
@@ -501,7 +501,7 @@ static PBytes doit(VirtualFrame frame, PBuffered self, int size,
501501
}
502502

503503
if (n == 0) {
504-
return factory.createBytes(PythonUtils.EMPTY_BYTE_ARRAY);
504+
return factory.createEmptyBytes();
505505
}
506506
/*- Return up to n bytes. If at least one byte is buffered, we
507507
only return buffered bytes. Otherwise, we do one raw read. */

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BytesIOBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static PBytes readBytes(PBytesIO self, int size,
205205
PythonBufferAccessLibrary bufferLib,
206206
PythonObjectFactory factory) {
207207
if (size == 0) {
208-
return factory.createBytes(PythonUtils.EMPTY_BYTE_ARRAY);
208+
return factory.createEmptyBytes();
209209
}
210210

211211
assert (size <= self.getStringSize());

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/FileIOBuiltins.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@
157157
import com.oracle.graal.python.runtime.PythonContext;
158158
import com.oracle.graal.python.runtime.exception.PException;
159159
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
160-
import com.oracle.graal.python.util.PythonUtils;
161160
import com.oracle.truffle.api.dsl.Bind;
162161
import com.oracle.truffle.api.dsl.Cached;
163162
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -518,7 +517,7 @@ static Object readall(VirtualFrame frame, PFileIO self, @SuppressWarnings("unuse
518517
@Specialization(guards = {"!self.isClosed()", "self.isReadable()", "size == 0"})
519518
static Object none(@SuppressWarnings("unused") PFileIO self, @SuppressWarnings("unused") int size,
520519
@Shared @Cached PythonObjectFactory factory) {
521-
return factory.createBytes(PythonUtils.EMPTY_BYTE_ARRAY);
520+
return factory.createEmptyBytes();
522521
}
523522

524523
@Specialization(guards = {"!self.isClosed()", "self.isReadable()", "size >= 0"})

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IncrementalNewlineDecoderBuiltins.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
8484
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
8585
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
86-
import com.oracle.graal.python.util.PythonUtils;
8786
import com.oracle.truffle.api.dsl.Bind;
8887
import com.oracle.truffle.api.dsl.Cached;
8988
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -286,7 +285,7 @@ abstract static class GetStateNode extends PythonUnaryBuiltinNode {
286285
@Specialization(guards = "!self.hasDecoder()")
287286
static Object noDecoder(PNLDecoder self,
288287
@Shared @Cached PythonObjectFactory factory) {
289-
PBytes buffer = factory.createBytes(PythonUtils.EMPTY_BYTE_ARRAY);
288+
PBytes buffer = factory.createEmptyBytes();
290289
int flag = self.isPendingCR() ? 1 : 0;
291290
return factory.createTuple(new Object[]{buffer, flag});
292291
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/RawIOBaseBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static Object read(VirtualFrame frame, Object self, int size,
132132
}
133133
int n = asSizeNode.executeExact(frame, inliningTarget, res, ValueError);
134134
if (n == 0) {
135-
return factory.createBytes(PythonUtils.EMPTY_BYTE_ARRAY);
135+
return factory.createEmptyBytes();
136136
}
137137
byte[] bytes = toBytes.execute(b);
138138
if (n < size) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperNodes.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
import com.oracle.graal.python.runtime.PythonOptions;
102102
import com.oracle.graal.python.runtime.exception.PException;
103103
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
104-
import com.oracle.graal.python.util.PythonUtils;
105104
import com.oracle.truffle.api.dsl.Bind;
106105
import com.oracle.truffle.api.dsl.Cached;
107106
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -659,7 +658,7 @@ static void atInit(VirtualFrame frame, Node inliningTarget, PTextIO self, @Suppr
659658
@Specialization(guards = {"self.hasDecoder()", "!isAtInit(cookie)"})
660659
static void decoderSetstate(VirtualFrame frame, Node inliningTarget, PTextIO self, PTextIO.CookieType cookie, PythonObjectFactory factory,
661660
@Exclusive @Cached PyObjectCallMethodObjArgs callMethodSetState) {
662-
PTuple tuple = factory.createTuple(new Object[]{factory.createBytes(PythonUtils.EMPTY_BYTE_ARRAY), cookie.decFlags});
661+
PTuple tuple = factory.createTuple(new Object[]{factory.createEmptyBytes(), cookie.decFlags});
663662
callMethodSetState.execute(frame, inliningTarget, self.getDecoder(), T_SETSTATE, tuple);
664663

665664
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PicklerNodes.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import static com.oracle.graal.python.nodes.statement.AbstractImportNode.importModule;
5555
import static com.oracle.graal.python.runtime.exception.PythonErrorType.AttributeError;
5656
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
57-
import static com.oracle.graal.python.util.PythonUtils.EMPTY_BYTE_ARRAY;
5857
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
5958
import static com.oracle.graal.python.util.PythonUtils.tsLiteral;
6059

@@ -391,7 +390,7 @@ protected Object decode(VirtualFrame frame, Object value, TruffleString encoding
391390

392391
protected Object escapeDecode(VirtualFrame frame, PythonObjectFactory factory, byte[] data, int offset, int len) {
393392
if (len == 0) {
394-
return factory.createBytes(EMPTY_BYTE_ARRAY);
393+
return factory.createEmptyBytes();
395394
}
396395
return escapeDecode(frame, PythonUtils.arrayCopyOfRange(data, offset, offset + len));
397396
}

0 commit comments

Comments
 (0)