RFR: 8299982: (bf) Buffer.checkIndex(int, int) should use Preconditions.checkIndex(int, int, BiFunction) [v2]
Brian Burkhalter
bpb at openjdk.org
Thu Jan 26 17:51:17 UTC 2023
On Thu, 26 Jan 2023 09:46:18 GMT, Uwe Schindler <uschindler at openjdk.org> wrote:
>> I was hoping the 3rd parameter to Preconditions.checkIndex would be constant. It looks like it's a capturing lambda ("this" is captured because of the access to the position/limit fields). Hmm, maybe start out simple with a constant, otherwise this change is going to require much wider startup and performance testing.
>
> In the original code it just has `throw new IndexOutOfBoundsException();`, so why not make it non-capturing lambda by just returning the same, e.g., `(x, y) -> new IndexOutOfBoundsException()`
> Hmm, maybe start out simple with a constant, otherwise this change is going to require much wider startup and performance testing.
Something like?
@ForceInline
final int checkIndex(int i, int nb) { // package-private
return Preconditions.checkIndex(i, limit - nb + 1,
(x, y) -> new IndexOutOfBoundsException());
}
-------------
PR: https://git.openjdk.org/jdk/pull/12174
More information about the nio-dev
mailing list