On Sun, 6 Oct 2024 15:07:02 GMT, Claes Redestad <redes...@openjdk.org> wrote:
>> src/java.base/share/classes/java/util/zip/ZipUtils.java line 175: >> >>> 173: public static final int get16(byte[] b, int off) { >>> 174: Preconditions.checkIndex(off, b.length, >>> Preconditions.AIOOBE_FORMATTER); >>> 175: Preconditions.checkIndex(off + 1, b.length, >>> Preconditions.AIOOBE_FORMATTER); >> >> Please use `Preconditions.checkFromIndexSize`, which should be less overhead: >> Suggestion: >> >> Preconditions.checkFromIndexSize(off, 2, b.length, >> Preconditions.AIOOBE_FORMATTER); >> >> Similarly for other methods. > > It's actually not less overhead in my tests, since `checkIndex` is intrinsic > and mostly disappears, while with `checkFromIndexSize` performance gets > significantly worse (on par with baseline). It's on my todo to investigate > this in-depth but I think `checkFromIndexSize` needs to be given similar > intrinsification treatment as `checkIndex`. Actually if we trust the input index to be nonnegative, we can just check our end index for out of bounds too. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/21377#discussion_r1789127887