[foreign-memaccess+abi] RFR: 8290880: Add static MemorySegment::mismatch method

Maurizio Cimadamore mcimadamore at openjdk.org
Fri Jul 22 16:33:20 UTC 2022


On Fri, 22 Jul 2022 16:16:46 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

>> Note that `Arrays.mismatch` seems to compute the `length` of the mismatch using some fixed formula, and then calls `ArraysSupport::vectorized` mismatch with a single length parameter. So it seems to me that a version that accepts a `length` parameter is "more primitive" (users can then fill with what they want).
>> 
>> As for making "both" methods static, I assume you mean `MemorySegment::mismatch` (the instance method). While doable, the same argument applies to `copyFrom`. I think we settled to have both variants as they will likely be used in different ways.
>
> Re: static vs instance, apologies I don't mean to reopen that discussion.
> 
> IIRC the motivation for the signatures in `Arrays` was in part because that is the pattern used by all the other methods. You are right that the underlying primitive is passing in a common length, which is what the supporting internal mismatch methods use, but it may not be as helpful to require the user to compute the minimum length. To be honest I am torn between keeping close to the `copy` signature or using absolute ranges :-)

One advantage to push the length computation inside is that explaining what the instance method does become trivial. An option could be to expose both, but seems like overkill. I think I'm fine with exposing the Arrays signature - after all the user can always get what he wants either way. That would at least make the API point consistent with Arrays.mismatch (in the same way MemorySegment::copy is consistent with System::arraycopy).

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

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


More information about the panama-dev mailing list