On Tue, 23 Jan 2024 15:52:29 GMT, Alan Bateman <al...@openjdk.org> wrote:

> Would it be possible to list further examples where this might be used? 
> Asking because I'm wondering about the usability and maintainability of 
> if-then-else code.

A similar thing is already used in JDK: 
https://github.com/openjdk/jdk/blob/2a01c798d346656a0ee3553c0964feab75b5dfb6/src/java.base/share/classes/java/lang/invoke/Invokers.java#L622-L624

Extending this for more common use allows doing things like optimizing 
`Integer.toString(int)`:


     @Stable
     static final String[] CONST_STRINGS = {"-1", "0", "1"};

     @IntrinsicCandidate
     public static String toString(int i) {
        if (isCompileConstant(i) && (i >= -1) && (i <= 1)) {
            return CONST_STRINGS[i + 1];
        }
        ...

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

PR Comment: https://git.openjdk.org/jdk/pull/17527#issuecomment-1906379544

Reply via email to