[foreign-preview] RFR: 8282070: Drop workaround from memory segment implementation
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Fri Feb 18 10:06:59 UTC 2022
On Thu, 17 Feb 2022 22:42:46 GMT, Radoslaw Smogura <duke at openjdk.java.net> wrote:
>> I get it, it's to allow creating 0-length chunks (I've thought in context of reading value).
>>
>> If we assume `length > 0`, then `this.length - length + 1 =< this.length`, (in case `this.len == 0 -> 0 <= 0`)
>
> I'm not sure if I missed some case, but if it's in if (`length > 0`), then one `checkIndex` is redundant? Unless we want to disallow slicing 0 length indices?
@rsmogura you are correct, the extra check is redundant now - we only need the second. I probably added before I had the check for `length > 0` and then left that there. Effectively, the second check is enough, because that checks that `offset >= 0`, and `length > 0` by construction (and we now that segment size must be `>= 0`). So I believe we should be ok.
@merykitty yes, this is implementing the same check in spirit as `checkFromIndexSize` - but unfortunately that is not a VM intrinsics, so we have to code around that.
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/644
More information about the panama-dev
mailing list