RFR: Minor fixes, microoptimizations and cleanup

Sergey Ponomarev github.com+415502+stokito at openjdk.java.net
Tue Oct 6 14:56:24 UTC 2020


On Thu, 1 Oct 2020 07:18:02 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

>> I already signed Oracle contributor agreement and I'm JCP member so my changes can be accepted.
>
> jol-core/src/main/java/org/openjdk/jol/info/FieldLayout.java line 103:
> 
>> 101:         String cl = hostClass();
>> 102:         int idx = cl.lastIndexOf(".");
>> 103:         return idx != -1 && idx < cl.length() ? cl.substring(idx + 1) : cl;
> 
> Took me a while to recognize the ternary statement here. Should at least have parentheses?
> 
>  return (idx != -1 && idx < cl.length()) ? cl.substring(idx + 1) : cl;
> 
> Or maybe don't do this at all, and leave the if block:
> 
> if (idx != -1 && idx < cl.length()) {
>   return cl.substring(idx + 1)
> } else {
>   return cl;
> }

right, btw the idx is always less than cl.length so the `idx < cl.length()` may be eleminated

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

PR: https://git.openjdk.java.net/jol/pull/3


More information about the jol-dev mailing list