< prev index next >
src/java.base/share/classes/java/io/PrintStream.java
Print this page
rev 53030 : 8215412: Optimize PrintStream.println methods
Reviewed-by: TBD
*** 595,604 ****
--- 595,627 ----
catch (IOException x) {
trouble = true;
}
}
+ private void writeln(char buf[]) {
+ try {
+ synchronized (this) {
+ ensureOpen();
+ textOut.write(buf);
+ textOut.newLine();
+ textOut.flushBuffer();
+ charOut.flushBuffer();
+ if (autoFlush) {
+ for (int i = 0; i < buf.length; i++)
+ if (buf[i] == '\n')
+ out.flush();
+ }
+ }
+ }
+ catch (InterruptedIOException x) {
+ Thread.currentThread().interrupt();
+ }
+ catch (IOException x) {
+ trouble = true;
+ }
+ }
+
private void write(String s) {
try {
synchronized (this) {
ensureOpen();
textOut.write(s);
*** 614,623 ****
--- 637,666 ----
catch (IOException x) {
trouble = true;
}
}
+ private void writeln(String s) {
+ try {
+ synchronized (this) {
+ ensureOpen();
+ textOut.write(s);
+ textOut.newLine();
+ textOut.flushBuffer();
+ charOut.flushBuffer();
+ if (autoFlush)
+ out.flush();
+ }
+ }
+ catch (InterruptedIOException x) {
+ Thread.currentThread().interrupt();
+ }
+ catch (IOException x) {
+ trouble = true;
+ }
+ }
+
private void newLine() {
try {
synchronized (this) {
ensureOpen();
textOut.newLine();
*** 778,889 ****
* {@link #println()}.
*
* @param x The {@code boolean} to be printed
*/
public void println(boolean x) {
! synchronized (this) {
! print(x);
! newLine();
! }
}
/**
* Prints a character and then terminate the line. This method behaves as
* though it invokes {@link #print(char)} and then
* {@link #println()}.
*
* @param x The {@code char} to be printed.
*/
public void println(char x) {
! synchronized (this) {
! print(x);
! newLine();
! }
}
/**
* Prints an integer and then terminate the line. This method behaves as
* though it invokes {@link #print(int)} and then
* {@link #println()}.
*
* @param x The {@code int} to be printed.
*/
public void println(int x) {
! synchronized (this) {
! print(x);
! newLine();
! }
}
/**
* Prints a long and then terminate the line. This method behaves as
* though it invokes {@link #print(long)} and then
* {@link #println()}.
*
* @param x a The {@code long} to be printed.
*/
public void println(long x) {
! synchronized (this) {
! print(x);
! newLine();
! }
}
/**
* Prints a float and then terminate the line. This method behaves as
* though it invokes {@link #print(float)} and then
* {@link #println()}.
*
* @param x The {@code float} to be printed.
*/
public void println(float x) {
! synchronized (this) {
! print(x);
! newLine();
! }
}
/**
* Prints a double and then terminate the line. This method behaves as
* though it invokes {@link #print(double)} and then
* {@link #println()}.
*
* @param x The {@code double} to be printed.
*/
public void println(double x) {
! synchronized (this) {
! print(x);
! newLine();
! }
}
/**
* Prints an array of characters and then terminate the line. This method
* behaves as though it invokes {@link #print(char[])} and
* then {@link #println()}.
*
* @param x an array of chars to print.
*/
public void println(char x[]) {
! synchronized (this) {
! print(x);
! newLine();
! }
}
/**
* Prints a String and then terminate the line. This method behaves as
* though it invokes {@link #print(String)} and then
* {@link #println()}.
*
* @param x The {@code String} to be printed.
*/
public void println(String x) {
! synchronized (this) {
! print(x);
! newLine();
! }
}
/**
* Prints an Object and then terminate the line. This method calls
* at first String.valueOf(x) to get the printed object's string value,
--- 821,908 ----
* {@link #println()}.
*
* @param x The {@code boolean} to be printed
*/
public void println(boolean x) {
! writeln(String.valueOf(x));
}
/**
* Prints a character and then terminate the line. This method behaves as
* though it invokes {@link #print(char)} and then
* {@link #println()}.
*
* @param x The {@code char} to be printed.
*/
public void println(char x) {
! writeln(String.valueOf(x));
}
/**
* Prints an integer and then terminate the line. This method behaves as
* though it invokes {@link #print(int)} and then
* {@link #println()}.
*
* @param x The {@code int} to be printed.
*/
public void println(int x) {
! writeln(String.valueOf(x));
}
/**
* Prints a long and then terminate the line. This method behaves as
* though it invokes {@link #print(long)} and then
* {@link #println()}.
*
* @param x a The {@code long} to be printed.
*/
public void println(long x) {
! writeln(String.valueOf(x));
}
/**
* Prints a float and then terminate the line. This method behaves as
* though it invokes {@link #print(float)} and then
* {@link #println()}.
*
* @param x The {@code float} to be printed.
*/
public void println(float x) {
! writeln(String.valueOf(x));
}
/**
* Prints a double and then terminate the line. This method behaves as
* though it invokes {@link #print(double)} and then
* {@link #println()}.
*
* @param x The {@code double} to be printed.
*/
public void println(double x) {
! writeln(String.valueOf(x));
}
/**
* Prints an array of characters and then terminate the line. This method
* behaves as though it invokes {@link #print(char[])} and
* then {@link #println()}.
*
* @param x an array of chars to print.
*/
public void println(char x[]) {
! writeln(x);
}
/**
* Prints a String and then terminate the line. This method behaves as
* though it invokes {@link #print(String)} and then
* {@link #println()}.
*
* @param x The {@code String} to be printed.
*/
public void println(String x) {
! writeln(String.valueOf(x));
}
/**
* Prints an Object and then terminate the line. This method calls
* at first String.valueOf(x) to get the printed object's string value,
*** 892,906 ****
* {@link #println()}.
*
* @param x The {@code Object} to be printed.
*/
public void println(Object x) {
! String s = String.valueOf(x);
! synchronized (this) {
! print(s);
! newLine();
! }
}
/**
* A convenience method to write a formatted string to this output stream
--- 911,921 ----
* {@link #println()}.
*
* @param x The {@code Object} to be printed.
*/
public void println(Object x) {
! println(String.valueOf(x));
}
/**
* A convenience method to write a formatted string to this output stream
< prev index next >