On Fri, 20 May 2022 22:18:42 GMT, liach <d...@openjdk.java.net> wrote:

>> Simplify opcode handling, use `final` in `PrimitiveTypeInfo`, and replace 
>> the hash map with a simple lookup, similar to what's done in 
>> [JDK-8284880](https://bugs.openjdk.java.net/browse/JDK-8284880) (#8242)
>
> liach has updated the pull request incrementally with one additional commit 
> since the last revision:
> 
>   Convert PrimitiveTypeInfo to an enum

> > Did you consider switch (class) {...} in PrimitiveTypeInfo.get?
> 
> I don't think we can switch on class instances yet. Even with preview 
> enabled, best I can get is (for type incompatibility of `Class<?>` and 
> `Class<Integer>`, etc.)
> 
> ```java
>               return switch (cl) {
>                   case Class<?> e && e == int.class -> 1;
>                   case Class<?> e && e == long.class -> 2;
>                   case Class<?> e && e == boolean.class -> 3;
>                   case Class<?> e && e == short.class -> 4;
>                   case Class<?> e && e == byte.class -> 5;
>                   case Class<?> e && e == char.class -> 6;
>                   case Class<?> e && e == float.class -> 7;
>                   case Class<?> e && e == double.class -> 8;
>                   default -> 0;
>               };
> ```
> 
> to avoid type incompatibility; this is in turn implemented by a bootstrap 
> method and a loop, which is of course obviously much slower.

Not necessarily recommending this coding idiom, but if you screened on 
Class.isPrimitive() being true (taking care to avoid void.class), you could 
switch on the string presentations on the class such as getName or 
getSimpleName.

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

PR: https://git.openjdk.java.net/jdk/pull/8801

Reply via email to