mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8300236: Use VarHandle access in Data(Input | Output)Stream classes
Reviewed-by: rriggs, alanb
This commit is contained in:
parent
a5d8e12872
commit
74e1a8bfa8
11 changed files with 869 additions and 364 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1994, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1994, 2023, 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
|
||||
|
@ -25,6 +25,8 @@
|
|||
|
||||
package java.io;
|
||||
|
||||
import jdk.internal.util.ByteArray;
|
||||
|
||||
/**
|
||||
* A data output stream lets an application write primitive Java data
|
||||
* types to an output stream in a portable way. An application can
|
||||
|
@ -170,8 +172,7 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput {
|
|||
* @see java.io.FilterOutputStream#out
|
||||
*/
|
||||
public final void writeShort(int v) throws IOException {
|
||||
writeBuffer[0] = (byte)(v >>> 8);
|
||||
writeBuffer[1] = (byte)(v >>> 0);
|
||||
ByteArray.setUnsignedShort(writeBuffer, 0, v);
|
||||
out.write(writeBuffer, 0, 2);
|
||||
incCount(2);
|
||||
}
|
||||
|
@ -186,8 +187,7 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput {
|
|||
* @see java.io.FilterOutputStream#out
|
||||
*/
|
||||
public final void writeChar(int v) throws IOException {
|
||||
writeBuffer[0] = (byte)(v >>> 8);
|
||||
writeBuffer[1] = (byte)(v >>> 0);
|
||||
ByteArray.setUnsignedShort(writeBuffer, 0, v);
|
||||
out.write(writeBuffer, 0, 2);
|
||||
incCount(2);
|
||||
}
|
||||
|
@ -202,10 +202,7 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput {
|
|||
* @see java.io.FilterOutputStream#out
|
||||
*/
|
||||
public final void writeInt(int v) throws IOException {
|
||||
writeBuffer[0] = (byte)(v >>> 24);
|
||||
writeBuffer[1] = (byte)(v >>> 16);
|
||||
writeBuffer[2] = (byte)(v >>> 8);
|
||||
writeBuffer[3] = (byte)(v >>> 0);
|
||||
ByteArray.setInt(writeBuffer, 0, v);
|
||||
out.write(writeBuffer, 0, 4);
|
||||
incCount(4);
|
||||
}
|
||||
|
@ -220,14 +217,7 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput {
|
|||
* @see java.io.FilterOutputStream#out
|
||||
*/
|
||||
public final void writeLong(long v) throws IOException {
|
||||
writeBuffer[0] = (byte)(v >>> 56);
|
||||
writeBuffer[1] = (byte)(v >>> 48);
|
||||
writeBuffer[2] = (byte)(v >>> 40);
|
||||
writeBuffer[3] = (byte)(v >>> 32);
|
||||
writeBuffer[4] = (byte)(v >>> 24);
|
||||
writeBuffer[5] = (byte)(v >>> 16);
|
||||
writeBuffer[6] = (byte)(v >>> 8);
|
||||
writeBuffer[7] = (byte)(v >>> 0);
|
||||
ByteArray.setLong(writeBuffer, 0, v);
|
||||
out.write(writeBuffer, 0, 8);
|
||||
incCount(8);
|
||||
}
|
||||
|
@ -246,7 +236,9 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput {
|
|||
* @see java.lang.Float#floatToIntBits(float)
|
||||
*/
|
||||
public final void writeFloat(float v) throws IOException {
|
||||
writeInt(Float.floatToIntBits(v));
|
||||
ByteArray.setFloat(writeBuffer, 0, v);
|
||||
out.write(writeBuffer, 0, 4);
|
||||
incCount(4);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -263,7 +255,9 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput {
|
|||
* @see java.lang.Double#doubleToLongBits(double)
|
||||
*/
|
||||
public final void writeDouble(double v) throws IOException {
|
||||
writeLong(Double.doubleToLongBits(v));
|
||||
ByteArray.setDouble(writeBuffer, 0, v);
|
||||
out.write(writeBuffer, 0, 8);
|
||||
incCount(8);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -301,8 +295,7 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput {
|
|||
int len = s.length();
|
||||
for (int i = 0 ; i < len ; i++) {
|
||||
int v = s.charAt(i);
|
||||
writeBuffer[0] = (byte)(v >>> 8);
|
||||
writeBuffer[1] = (byte)(v >>> 0);
|
||||
ByteArray.setUnsignedShort(writeBuffer, 0, v);
|
||||
out.write(writeBuffer, 0, 2);
|
||||
}
|
||||
incCount(len * 2);
|
||||
|
@ -379,9 +372,8 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput {
|
|||
}
|
||||
|
||||
int count = 0;
|
||||
bytearr[count++] = (byte) ((utflen >>> 8) & 0xFF);
|
||||
bytearr[count++] = (byte) ((utflen >>> 0) & 0xFF);
|
||||
|
||||
ByteArray.setUnsignedShort(bytearr, count, utflen);
|
||||
count += 2;
|
||||
int i = 0;
|
||||
for (i = 0; i < strlen; i++) { // optimized for initial run of ASCII
|
||||
int c = str.charAt(i);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue