On Fri, 8 Sep 2023 14:17:29 GMT, Aggelos Biboudis <abimpou...@openjdk.org> 
wrote:

> This is the first draft of a patch for Primitive types in patterns, 
> instanceof, and switch (Preview).
> 
> Draft spec here: 
> https://cr.openjdk.org/~abimpoudis/instanceof/instanceof-20230913/specs/instanceof-jls.html

src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 45:

> 43:      *
> 44:      * */
> 45:     public static boolean byte_char(byte n)    {return n == (char) n;}

This method doesn't buy you anything more than `int_char(int)`, so I wonder if 
it is useful.
(The bytecode instructions are exactly the same.)

src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 53:

> 51:      *
> 52:      * */
> 53:     public static boolean short_byte(short n)  {return n == 
> (short)(byte)(n);}

Here, too, I wonder if this method is useful, given that `int_byte(int)` gives 
the same outcomes and its bytecode is one instruction shorter.

src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 61:

> 59:      *
> 60:      * */
> 61:     public static boolean short_char(short n)  {return n == (char)(n);}

Similarly, usages can be replaced by `int_char(int)`.

src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 69:

> 67:      *
> 68:      * */
> 69:     public static boolean char_byte(char n)    {return n == (byte)(n);}

Usages can be replaced by `int_byte(int)`.

src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 77:

> 75:      *
> 76:      * */
> 77:     public static boolean char_short(char n)   {return n == (short)(n);}

Can be replaced by `int_short(int)`.

src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 85:

> 83:      *
> 84:      * */
> 85:     public static boolean int_byte(int n)      {return n == 
> (int)(byte)(n);}

Suggestion:

    public static boolean int_byte(int n)      {return n == (int)(byte)n;}

Just for consistency with other methods.

src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 93:

> 91:      *
> 92:      * */
> 93:     public static boolean int_short(int n)     {return n == 
> (int)(short)(n);}

Suggestion:

    public static boolean int_short(int n)     {return n == (int)(short)n;}

src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 101:

> 99:      *
> 100:      * */
> 101:     public static boolean int_char(int n)      {return n == (char)(n);}

Suggestion:

    public static boolean int_char(int n)      {return n == (int)(char)n;}

src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 117:

> 115:      *
> 116:      * */
> 117:     public static boolean long_byte(long n)    {return n == 
> (long)(byte)(n);}

Suggestion:

    public static boolean long_byte(long n)    {return n == (long)(byte)n;}

src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 125:

> 123:      *
> 124:      * */
> 125:     public static boolean long_short(long n)   {return n == 
> (long)(short)(n);}

Suggestion:

    public static boolean long_short(long n)   {return n == (long)(short)n;}

src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 133:

> 131:      *
> 132:      * */
> 133:     public static boolean long_char(long n)    {return n == (char)(n);}

Suggestion:

    public static boolean long_char(long n)    {return n == (long)(char)n;}

for consistency.

src/java.base/share/classes/java/lang/runtime/ExactnessMethods.java line 141:

> 139:      *
> 140:      * */
> 141:     public static boolean long_int(long n)     {return n == 
> (long)(int)(n);}

Suggestion:

    public static boolean long_int(long n)     {return n == (long)(int)n;}

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15638#discussion_r1337239197
PR Review Comment: https://git.openjdk.org/jdk/pull/15638#discussion_r1337251147
PR Review Comment: https://git.openjdk.org/jdk/pull/15638#discussion_r1337257370
PR Review Comment: https://git.openjdk.org/jdk/pull/15638#discussion_r1337259180
PR Review Comment: https://git.openjdk.org/jdk/pull/15638#discussion_r1337221803
PR Review Comment: https://git.openjdk.org/jdk/pull/15638#discussion_r1337221156
PR Review Comment: https://git.openjdk.org/jdk/pull/15638#discussion_r1337220474
PR Review Comment: https://git.openjdk.org/jdk/pull/15638#discussion_r1337219930
PR Review Comment: https://git.openjdk.org/jdk/pull/15638#discussion_r1337217930
PR Review Comment: https://git.openjdk.org/jdk/pull/15638#discussion_r1337217515
PR Review Comment: https://git.openjdk.org/jdk/pull/15638#discussion_r1337216448
PR Review Comment: https://git.openjdk.org/jdk/pull/15638#discussion_r1337268643

Reply via email to