mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8300979: Lazily initialize (byte, char)arr in java.io.DataInputStream
Reviewed-by: alanb
This commit is contained in:
parent
cddaf686e1
commit
60640a216d
1 changed files with 6 additions and 3 deletions
|
@ -46,6 +46,9 @@ import java.util.Objects;
|
|||
*/
|
||||
public class DataInputStream extends FilterInputStream implements DataInput {
|
||||
|
||||
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
|
||||
private static final char[] EMPTY_CHAR_ARRAY = new char[0];
|
||||
|
||||
/**
|
||||
* Creates a DataInputStream that uses the specified
|
||||
* underlying InputStream.
|
||||
|
@ -61,8 +64,8 @@ public class DataInputStream extends FilterInputStream implements DataInput {
|
|||
/**
|
||||
* working arrays initialized on demand by readUTF
|
||||
*/
|
||||
private byte[] bytearr = new byte[80];
|
||||
private char[] chararr = new char[80];
|
||||
private byte[] bytearr = EMPTY_BYTE_ARRAY;
|
||||
private char[] chararr = EMPTY_CHAR_ARRAY;
|
||||
|
||||
/**
|
||||
* Reads some number of bytes from the contained input stream and
|
||||
|
@ -573,7 +576,7 @@ loop: while (true) {
|
|||
byte[] bytearr = null;
|
||||
char[] chararr = null;
|
||||
if (in instanceof DataInputStream dis) {
|
||||
if (dis.bytearr.length < utflen){
|
||||
if (dis.bytearr.length < utflen) {
|
||||
dis.bytearr = new byte[utflen*2];
|
||||
dis.chararr = new char[utflen*2];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue