On Tue, 29 Aug 2023 22:04:40 GMT, Phil Race <p...@openjdk.org> wrote:
> 8318364: Add an FFM-based implementation of harfbuzz OpenType layout src/java.desktop/share/classes/sun/font/HBShaper.java line 110: > 108: > 109: private static VarHandle getVarHandle(StructLayout struct, String > name) { > 110: VarHandle h = struct.varHandle(PathElement.groupElement(name)); Note that, strictly speaking, these combiners are _not_ required. If you just call `MemoryLayout::varHandle`, you get back a var handle that takes a `MemorySegment` and a `long` offset. So, you can, if you want, adapt the var handle so that the offset parameter becomes something else. But you could also just leave the var handle as is. Then, in the loop that is doing the access, you can do this: for (int i = 0 ; i < limit ; i++) { x_offsetHandle.get(segment, PositionLayout.scale(0, i)); y_offsetHandle.get(segment, PositionLayout.scale(0, i)); ... } That is, use the offset hole to your advantage, to pass the struct base offset (obtained by scaling the enclosing struct layout by the value of the loop induction variable). (That said, I understand that working with logical indices is a common operation, and that this is made a bit harder by the recent API changes. We should consider, as @JornVernee mentioned, adding back a more general `MemoryLayout::arrayElementVarHandle` which will give you the var handle you need - with coordinates `MemorySegment` and `long` - a logical index, not an offset). ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/15476#discussion_r1364702729