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

Maurizio Cimadamore mcimadamore at openjdk.org
Fri Jul 22 15:54:12 UTC 2022


On Fri, 22 Jul 2022 15:41:50 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

>> As discussed in [1], it would be useful if the `MemorySegment` class provided a static mismatch method, similarly to what we have provided for `copy`.
>> 
>> This patch adds that method, and rewrites the existing instance `mismatch` method to be based on that new static method.
>> It then adds new tests to cover the new static method.
>> 
>> [1] - https://mail.openjdk.org/pipermail/panama-dev/2022-June/017099.html
>
> src/java.base/share/classes/java/lang/foreign/MemorySegment.java line 2015:
> 
>> 2013:      * @see MemorySegment#mismatch(MemorySegment)
>> 2014:      */
>> 2015:     static long mismatch(MemorySegment srcSegment, long srcOffset, MemorySegment dstSegment, long dstOffset, long bytes) {
> 
> Should we make the signature the same as that for Arrays.mismatch e.g.:
> 
>     public static int mismatch(byte[] a, int aFromIndex, int aToIndex,
>                                byte[] b, int bFromIndex, int bToIndex) {
> 
> ?
> It's tempting to make both mismatch methods static.

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.

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

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


More information about the panama-dev mailing list