Skip to content

Commit 70e1edd

Browse files
committed
replace new byte[0] with PythonUtils.EMPTY_BYTES_ARRAY
1 parent 99f8d62 commit 70e1edd

File tree

13 files changed

+28
-20
lines changed

13 files changed

+28
-20
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ArrayModuleBuiltins.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import com.oracle.graal.python.nodes.util.CastToByteNode;
5050
import com.oracle.graal.python.runtime.exception.PException;
5151
import com.oracle.graal.python.runtime.sequence.PSequence;
52+
import com.oracle.graal.python.util.PythonUtils;
5253
import com.oracle.truffle.api.CompilerDirectives;
5354
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5455
import com.oracle.truffle.api.dsl.Cached;
@@ -274,13 +275,12 @@ private PArray makeEmptyArray(Object cls, char type) {
274275
switch (type) {
275276
case 'c':
276277
case 'b':
277-
return factory().createArray(cls, new byte[0]);
278278
case 'B':
279-
return factory().createArray(cls, new byte[0]);
279+
return factory().createArray(cls, PythonUtils.EMPTY_BYTE_ARRAY);
280280
case 'i':
281-
return factory().createArray(cls, new int[0]);
281+
return factory().createArray(cls, PythonUtils.EMPTY_INT_ARRAY);
282282
case 'd':
283-
return factory().createArray(cls, new double[0]);
283+
return factory().createArray(cls, PythonUtils.EMPTY_DOUBLE_ARRAY);
284284
default:
285285
return null;
286286
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public abstract static class ByteArrayNode extends PythonBuiltinNode {
276276
@Specialization
277277
public Object createByteArray(Object cls, @SuppressWarnings("unused") Object source, @SuppressWarnings("unused") Object encoding, @SuppressWarnings("unused") Object errors) {
278278
// data filled in subsequent __init__ call - see BytesBuiltins.InitNode
279-
return factory().createByteArray(cls, new byte[0]);
279+
return factory().createByteArray(cls, PythonUtils.EMPTY_BYTE_ARRAY);
280280
}
281281
}
282282

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
8282
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
8383
import com.oracle.graal.python.runtime.PythonContext;
84+
import com.oracle.graal.python.util.PythonUtils;
8485
import com.oracle.truffle.api.Assumption;
8586
import com.oracle.truffle.api.CompilerDirectives;
8687
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -612,7 +613,7 @@ private byte[] readBytes() {
612613
index += len;
613614
return bytes;
614615
} else {
615-
return new byte[0];
616+
return PythonUtils.EMPTY_BYTE_ARRAY;
616617
}
617618
}
618619

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ protected List<byte[]> splitDelimiter(byte[] bytes, byte[] sep, int maxsplit) {
16481648
if (begin < offset) {
16491649
result.add(copyOfRange(bytes, begin, offset));
16501650
} else {
1651-
result.add(new byte[0]);
1651+
result.add(PythonUtils.EMPTY_BYTE_ARRAY);
16521652
}
16531653
begin = offset + sep.length;
16541654
offset = begin - 1;
@@ -1756,7 +1756,7 @@ protected List<byte[]> splitDelimiter(byte[] bytes, byte[] sep, int maxsplit) {
17561756
if (end > offset) {
17571757
result.add(0, copyOfRange(bytes, offset + 1, end));
17581758
} else {
1759-
result.add(0, new byte[0]);
1759+
result.add(0, PythonUtils.EMPTY_BYTE_ARRAY);
17601760
}
17611761
end = offset;
17621762
if (--countSplit == 0) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ public abstract static class ConvertToByteObjectBytesNode extends Node {
541541

542542
@Specialization(guards = {"isNoValue(source)", "isNoValue(encoding)", "isNoValue(errors)"})
543543
byte[] bytearray(@SuppressWarnings("unused") PNone source, @SuppressWarnings("unused") PNone encoding, @SuppressWarnings("unused") PNone errors) {
544-
return new byte[0];
544+
return PythonUtils.EMPTY_BYTE_ARRAY;
545545
}
546546

547547
@Specialization(guards = {"lib.canBeIndex(capObj)", "isNoValue(encoding)", "isNoValue(errors)"})

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/PySequenceArrayWrapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import com.oracle.graal.python.runtime.sequence.storage.EmptySequenceStorage;
6767
import com.oracle.graal.python.runtime.sequence.storage.NativeSequenceStorage;
6868
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
69+
import com.oracle.graal.python.util.PythonUtils;
6970
import com.oracle.truffle.api.Assumption;
7071
import com.oracle.truffle.api.CompilerAsserts;
7172
import com.oracle.truffle.api.CompilerDirectives;
@@ -447,7 +448,7 @@ NativeSequenceStorage doNative(NativeSequenceStorage s) {
447448
NativeSequenceStorage doEmptyStorage(@SuppressWarnings("unused") EmptySequenceStorage s,
448449
@Shared("storageToNativeNode") @Cached SequenceStorageNodes.StorageToNativeNode storageToNativeNode) {
449450
// TODO(fa): not sure if that completely reflects semantics
450-
return storageToNativeNode.execute(new byte[0]);
451+
return storageToNativeNode.execute(PythonUtils.EMPTY_BYTE_ARRAY);
451452
}
452453

453454
protected static boolean isNative(SequenceStorage s) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeBuiltins.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
4141
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
4242
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
43+
import com.oracle.graal.python.util.PythonUtils;
4344
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
4445
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
4546
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -202,7 +203,7 @@ protected Object get(PCode self) {
202203
byte[] lnotab = self.getLnotab();
203204
if (lnotab == null) {
204205
// TODO: this is for the moment undefined (see co_code)
205-
lnotab = new byte[0];
206+
lnotab = PythonUtils.EMPTY_BYTE_ARRAY;
206207
}
207208
return factory().createBytes(lnotab);
208209
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ private static byte[] extractCodeString(RootNode rootNode) {
353353
return serializer.serialize(rootNode);
354354
}
355355
// no code for non-user functions
356-
return new byte[0];
356+
return PythonUtils.EMPTY_BYTE_ARRAY;
357357
}
358358

359359
public RootNode getRootNode() {
@@ -537,15 +537,15 @@ public String toString() {
537537
private static PTuple createTuple(Object[] array, PythonObjectFactory factory) {
538538
Object[] data = array;
539539
if (data == null) {
540-
data = new Object[0];
540+
data = PythonUtils.EMPTY_OBJECT_ARRAY;
541541
}
542542
return factory.createTuple(data);
543543
}
544544

545545
private static PBytes createBytes(byte[] array, PythonObjectFactory factory) {
546546
byte[] bytes = array;
547547
if (bytes == null) {
548-
bytes = new byte[0];
548+
bytes = PythonUtils.EMPTY_BYTE_ARRAY;
549549
}
550550
return factory.createBytes(bytes);
551551
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/FrameBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ PCode get(VirtualFrame frame, PFrame self,
182182
}
183183
// TODO: frames: this just shouldn't happen anymore
184184
assert false : "should not be reached";
185-
return createCodeNode.execute(frame, PythonBuiltinClassType.PCode, -1, -1, -1, -1, -1, -1, new byte[0], PythonUtils.EMPTY_OBJECT_ARRAY, PythonUtils.EMPTY_OBJECT_ARRAY,
185+
return createCodeNode.execute(frame, PythonBuiltinClassType.PCode, -1, -1, -1, -1, -1, -1, PythonUtils.EMPTY_BYTE_ARRAY, PythonUtils.EMPTY_OBJECT_ARRAY, PythonUtils.EMPTY_OBJECT_ARRAY,
186186
PythonUtils.EMPTY_OBJECT_ARRAY, PythonUtils.EMPTY_OBJECT_ARRAY, PythonUtils.EMPTY_OBJECT_ARRAY,
187187
"<internal>",
188-
"<internal>", -1, new byte[0]);
188+
"<internal>", -1, PythonUtils.EMPTY_BYTE_ARRAY);
189189
}
190190

191191
public static GetCodeNode create() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/lzma/LZMADecompressorBuiltins.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
6666
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
6767
import com.oracle.graal.python.nodes.util.CastToByteNode;
68+
import com.oracle.graal.python.util.PythonUtils;
6869
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
6970
import com.oracle.truffle.api.dsl.Cached;
7071
import com.oracle.truffle.api.dsl.Fallback;
@@ -184,7 +185,7 @@ abstract static class UnusedDataNode extends PythonUnaryBuiltinNode {
184185
@Specialization
185186
PBytes doUnusedData(@SuppressWarnings("unused") PLZMADecompressor self) {
186187
// TODO implement
187-
return factory().createBytes(new byte[0]);
188+
return factory().createBytes(PythonUtils.EMPTY_BYTE_ARRAY);
188189
}
189190

190191
}

0 commit comments

Comments
 (0)