mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8292698: Improve performance of DataInputStream
Reviewed-by: dfuchs
This commit is contained in:
parent
d3781ac8a3
commit
74a51ccc86
2 changed files with 84 additions and 27 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1994, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -57,8 +57,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 = new byte[80];
|
||||
private char[] chararr = new char[80];
|
||||
|
||||
/**
|
||||
* Reads some number of bytes from the contained input stream and
|
||||
|
@ -245,10 +245,7 @@ public class DataInputStream extends FilterInputStream implements DataInput {
|
|||
* @see java.io.FilterInputStream#in
|
||||
*/
|
||||
public final boolean readBoolean() throws IOException {
|
||||
int ch = in.read();
|
||||
if (ch < 0)
|
||||
throw new EOFException();
|
||||
return (ch != 0);
|
||||
return readUnsignedByte() != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -268,10 +265,7 @@ public class DataInputStream extends FilterInputStream implements DataInput {
|
|||
* @see java.io.FilterInputStream#in
|
||||
*/
|
||||
public final byte readByte() throws IOException {
|
||||
int ch = in.read();
|
||||
if (ch < 0)
|
||||
throw new EOFException();
|
||||
return (byte)(ch);
|
||||
return (byte) readUnsignedByte();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -315,11 +309,7 @@ public class DataInputStream extends FilterInputStream implements DataInput {
|
|||
* @see java.io.FilterInputStream#in
|
||||
*/
|
||||
public final short readShort() throws IOException {
|
||||
int ch1 = in.read();
|
||||
int ch2 = in.read();
|
||||
if ((ch1 | ch2) < 0)
|
||||
throw new EOFException();
|
||||
return (short)((ch1 << 8) + (ch2 << 0));
|
||||
return (short) readUnsignedShort();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -340,6 +330,7 @@ public class DataInputStream extends FilterInputStream implements DataInput {
|
|||
* @see java.io.FilterInputStream#in
|
||||
*/
|
||||
public final int readUnsignedShort() throws IOException {
|
||||
InputStream in = this.in;
|
||||
int ch1 = in.read();
|
||||
int ch2 = in.read();
|
||||
if ((ch1 | ch2) < 0)
|
||||
|
@ -365,11 +356,7 @@ public class DataInputStream extends FilterInputStream implements DataInput {
|
|||
* @see java.io.FilterInputStream#in
|
||||
*/
|
||||
public final char readChar() throws IOException {
|
||||
int ch1 = in.read();
|
||||
int ch2 = in.read();
|
||||
if ((ch1 | ch2) < 0)
|
||||
throw new EOFException();
|
||||
return (char)((ch1 << 8) + (ch2 << 0));
|
||||
return (char) readUnsignedShort();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -390,6 +377,7 @@ public class DataInputStream extends FilterInputStream implements DataInput {
|
|||
* @see java.io.FilterInputStream#in
|
||||
*/
|
||||
public final int readInt() throws IOException {
|
||||
InputStream in = this.in;
|
||||
int ch1 = in.read();
|
||||
int ch2 = in.read();
|
||||
int ch3 = in.read();
|
||||
|
@ -399,7 +387,7 @@ public class DataInputStream extends FilterInputStream implements DataInput {
|
|||
return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
|
||||
}
|
||||
|
||||
private byte readBuffer[] = new byte[8];
|
||||
private final byte[] readBuffer = new byte[8];
|
||||
|
||||
/**
|
||||
* See the general contract of the {@code readLong}
|
||||
|
@ -474,7 +462,7 @@ public class DataInputStream extends FilterInputStream implements DataInput {
|
|||
return Double.longBitsToDouble(readLong());
|
||||
}
|
||||
|
||||
private char lineBuffer[];
|
||||
private char[] lineBuffer;
|
||||
|
||||
/**
|
||||
* See the general contract of the {@code readLine}
|
||||
|
@ -505,7 +493,7 @@ public class DataInputStream extends FilterInputStream implements DataInput {
|
|||
*/
|
||||
@Deprecated
|
||||
public final String readLine() throws IOException {
|
||||
char buf[] = lineBuffer;
|
||||
char[] buf = lineBuffer;
|
||||
|
||||
if (buf == null) {
|
||||
buf = lineBuffer = new char[128];
|
||||
|
@ -634,7 +622,7 @@ loop: while (true) {
|
|||
if (count > utflen)
|
||||
throw new UTFDataFormatException(
|
||||
"malformed input: partial character at end");
|
||||
char2 = (int) bytearr[count-1];
|
||||
char2 = bytearr[count-1];
|
||||
if ((char2 & 0xC0) != 0x80)
|
||||
throw new UTFDataFormatException(
|
||||
"malformed input around byte " + count);
|
||||
|
@ -647,8 +635,8 @@ loop: while (true) {
|
|||
if (count > utflen)
|
||||
throw new UTFDataFormatException(
|
||||
"malformed input: partial character at end");
|
||||
char2 = (int) bytearr[count-2];
|
||||
char3 = (int) bytearr[count-1];
|
||||
char2 = bytearr[count-2];
|
||||
char3 = bytearr[count-1];
|
||||
if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
|
||||
throw new UTFDataFormatException(
|
||||
"malformed input around byte " + (count-1));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue