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

Stuart Marks smarks at openjdk.org
Tue Dec 19 03:46:36 UTC 2023


On Sat, 9 Dec 2023 23:19:52 GMT, John Jiang <jjiang 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

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

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


More information about the core-libs-dev mailing list