On Tue, 2 Apr 2024 15:04:40 GMT, Per Minborg <pminb...@openjdk.org> wrote:

> This PR proposes to add an internal layout transformer that could be used to 
> transform MemoryLayout entities. For example, it would be possible to convert 
> a struct layout to use network order ((big-endian) instead of native byte 
> order (often little-endian). Another application is to remove naming 
> recursively for composite layouts when caching shapes etc.

src/java.base/share/classes/jdk/internal/foreign/layout/LayoutTransformers.java 
line 83:

> 81:          * @param layout to transform
> 82:          */
> 83:         MemoryLayout transform(T layout);

Not too sure about having a distinction between transform and deepTransform, at 
least not for the use cases we have so far. I'd say just keep the semantics of 
deepTransform, so that this becomes a functional interface?

src/java.base/share/classes/jdk/internal/foreign/layout/LayoutTransformers.java 
line 179:

> 177:         private static <T extends MemoryLayout> MemoryLayout 
> transformFlat(LayoutTransformer<T> transformer, MemoryLayout l) {
> 178:             LayoutTransformerImpl<T> t = (LayoutTransformerImpl<T>) 
> transformer;
> 179:             return switch (t.type) {

Why the big switch here? Aren't all arms just passing the layouts to the 
transform? As the method is already unchecked, perhaps simplifying the code and 
using e.g. raw types might be a better option, as it would make the code more 
readable.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/18582#discussion_r1567116664
PR Review Comment: https://git.openjdk.org/jdk/pull/18582#discussion_r1567114126

Reply via email to