On Thu, 12 May 2022 09:00:37 GMT, Pavel Rappo <[email protected]> wrote:
>> This is what I mean:
>>
>> jshell> long codeLengthOf = (long)Integer.MAX_VALUE + 1
>> codeLengthOf ==> 2147483648
>>
>> jshell> int bufferLen = 0
>> bufferLen ==> 0
>>
>> jshell> bufferLen + codeLengthOf <= 64
>> $3 ==> false
>>
>> jshell> bufferLen + (int)codeLengthOf <= 64
>> $4 ==> true
>
> Yes, inserting explicit casts seems less clean than changing `codeLengthOf`
> to this:
>
> private static int codeLengthOf(char c) {
> return (int) (codes[c] & 0x00000000ffffffffL);
> }
>
> There are 256 elements in constant `long[] codes`. One could easily check
> that each element when ANDed with `0x00000000ffffffffL` results in a value
> that fits into the first 31 bits of `int`.
OK - I will change codeLengthOf as suggested. It was not immediately obvious
to me that the values would fit in the first 31 bits.
-------------
PR: https://git.openjdk.java.net/jdk/pull/8656