[foreign-memaccess+abi] RFR: Micro optimizations and tidy

Paul Sandoz psandoz at openjdk.org
Thu Aug 18 15:31:24 UTC 2022


On Thu, 18 Aug 2022 13:07:05 GMT, Per Minborg <duke at openjdk.org> wrote:

> This small PR adds some optimizations and tidies up some imports.

src/java.base/share/classes/java/lang/foreign/FunctionDescriptor.java line 83:

> 81:     public static FunctionDescriptor of(MemoryLayout resLayout, MemoryLayout... argLayouts) {
> 82:         Objects.requireNonNull(resLayout);
> 83:         assertVarargsNonNull(argLayouts);

This check is redundant, since it is performed by `List.of` (granted that the stack trace is different but i think that is ok for NPEs).

src/java.base/share/classes/java/lang/foreign/FunctionDescriptor.java line 108:

> 106:     public FunctionDescriptor asVariadic(MemoryLayout... variadicLayouts) {
> 107:         assertVarargsNonNull(variadicLayouts);
> 108:         return variadicLayouts.length == 0 ? this : new VariadicFunction(this, variadicLayouts);

We could change the VariadicFunction constructor to accept a List of non-null elements.

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

PR: https://git.openjdk.org/panama-foreign/pull/708


More information about the panama-dev mailing list