Skip to content

Commit

Permalink
Update Marshal.java
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Feb 1, 2024
1 parent 22f43e6 commit ea1c4fe
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/overrun/marshal/Marshal.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public static MemorySegment marshal(SegmentAllocator allocator, MemorySegment @N
* @return the segment
*/
public static MemorySegment marshal(SegmentAllocator allocator, String @Nullable [] arr) {
return marshal(allocator, arr, SegmentAllocator::allocateFrom);
return marshal(allocator, arr, Marshal::marshal);
}

/**
Expand All @@ -325,7 +325,7 @@ public static MemorySegment marshal(SegmentAllocator allocator, String @Nullable
* @return the segment
*/
public static MemorySegment marshal(SegmentAllocator allocator, String @Nullable [] arr, Charset charset) {
return marshal(allocator, arr, (segmentAllocator, str) -> segmentAllocator.allocateFrom(str, charset));
return marshal(allocator, arr, (segmentAllocator, str) -> marshal(segmentAllocator, str, charset));
}

/**
Expand All @@ -339,7 +339,8 @@ public static MemorySegment marshal(SegmentAllocator allocator, CEnum @Nullable
if (arr == null) return MemorySegment.NULL;
final MemorySegment segment = allocator.allocate(JAVA_INT, arr.length);
for (int i = 0; i < arr.length; i++) {
vh_intArray.set(segment, (long) i, arr[i].value());
final CEnum cEnum = arr[i];
vh_intArray.set(segment, (long) i, cEnum != null ? cEnum.value() : 0);
}
return segment;
}
Expand All @@ -352,7 +353,7 @@ public static MemorySegment marshal(SegmentAllocator allocator, CEnum @Nullable
* @return the segment
*/
public static MemorySegment marshal(SegmentAllocator allocator, @Nullable Addressable @Nullable [] arr) {
return marshal(allocator, arr, (_, addressable) -> addressable != null ? addressable.segment() : MemorySegment.NULL);
return marshal(allocator, arr, (_, addressable) -> Marshal.marshal(addressable));
}

/**
Expand All @@ -363,6 +364,6 @@ public static MemorySegment marshal(SegmentAllocator allocator, @Nullable Addres
* @return the segment
*/
public static MemorySegment marshal(Arena arena, Upcall @Nullable [] arr) {
return marshal(arena, arr, (arena1, upcall) -> upcall.stub(arena1));
return marshal(arena, arr, Marshal::marshal);
}
}

0 comments on commit ea1c4fe

Please sign in to comment.