RFR: 8321637: Simplify if statement in ArraysSupport::hugeLength

John Jiang jjiang at openjdk.org
Tue Dec 19 03:57:44 UTC 2023


On Tue, 19 Dec 2023 03:44:26 GMT, Stuart Marks <smarks at openjdk.org> wrote:

>> It looks the `else-if` and `else` clauses in method `ArraysSupport::hugeLength` could be simplified by `Math::max`.
>
> This change would make the code shorter, but in my opinion, it obscures what's going on. This code tries to be very careful about avoiding problems caused by integer overflow/wraparound, and in order to do that, it needs to make sure that the full range of int values is handled properly. With the explicit if/else code, this is clear. Using Math.max() instead tends to make this obscure.
> 
> This came up previously; see
> 
> https://github.com/openjdk/jdk/pull/1617#discussion_r536260884

@stuart-marks 
Thanks for your clarification!

Just closed this PR and JBS.

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

PR Comment: https://git.openjdk.org/jdk/pull/17043#issuecomment-1862076153


More information about the core-libs-dev mailing list