On Mon, 6 May 2024 21:45:12 GMT, Pavel Rappo <pra...@openjdk.org> wrote:

> Please review this PR which introduces the `java.io.IO` top-level class and 
> three methods to `java.io.Console` for [Implicitly Declared Classes and 
> Instance Main Methods (Third Preview)].
> 
> This PR has been obtained as `git merge --squash` of a now obsolete [draft 
> PR].
> 
> [Implicitly Declared Classes and Instance Main Methods (Third Preview)]: 
> https://bugs.openjdk.org/browse/JDK-8323335
> [draft PR]: https://github.com/openjdk/jdk/pull/18921

Otherwise looks good.

src/java.base/share/classes/jdk/internal/io/JdkConsoleImpl.java line 74:

> 72: 
> 73:     @Override
> 74:     public String readln(String prompt) {

this code can be simplified using an early return (and the body of the 
try/catch can be reduced so it is more clear which statement can cause the 
IOException)

        synchronized (writeLock) {
            synchronized(readLock) {
                if (!prompt.isEmpty()) {
                    pw.print(prompt);
                    pw.flush(); // automatic flushing does not cover print
                }
               char[] array;
                try {
                    array = readline(false);
                } catch (IOException x) {
                    throw new IOError(x);
                }
                if (array != null) {
                    return new String(array);
                }
            }
        }
        return null;

src/jdk.internal.le/share/classes/jdk/internal/org/jline/JdkConsoleProviderImpl.java
 line 88:

> 86:         @Override
> 87:         public JdkConsole println(Object obj) {
> 88:             writer().println(obj);

the result of 'writer()' can be stored in a local variable (printing code are 
not JITed as often as the rest of the codes)

-------------

PR Comment: https://git.openjdk.org/jdk/pull/19112#issuecomment-2097502361
PR Review Comment: https://git.openjdk.org/jdk/pull/19112#discussion_r1591846059
PR Review Comment: https://git.openjdk.org/jdk/pull/19112#discussion_r1591847579

Reply via email to