From 9f9c6736abe01c844bf72552d7fae5fe8a479a40 Mon Sep 17 00:00:00 2001 From: Viktor Lofgren Date: Tue, 17 Sep 2024 13:49:02 +0200 Subject: [PATCH] (index) Use MemorySegment.copy for LongArray->LongArray transfers --- .../java/nu/marginalia/array/page/SegmentLongArray.java | 8 +++++--- .../java/nu/marginalia/array/page/UnsafeLongArray.java | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/code/libraries/array/java/nu/marginalia/array/page/SegmentLongArray.java b/code/libraries/array/java/nu/marginalia/array/page/SegmentLongArray.java index 5c63e5c3..76e2b213 100644 --- a/code/libraries/array/java/nu/marginalia/array/page/SegmentLongArray.java +++ b/code/libraries/array/java/nu/marginalia/array/page/SegmentLongArray.java @@ -182,9 +182,11 @@ public class SegmentLongArray implements LongArray { if (destEndL > size()) throw new IndexOutOfBoundsException("Destination array too small"); - for (long i = destStartL; i < destEndL; i++) { - set(i, source.get(sourceStartL + i - destStartL)); - } + MemorySegment.copy( + source.getMemorySegment(), JAVA_LONG, sourceStartL, + segment, JAVA_LONG, destStartL, + destEndL - destStartL + ); } @Override diff --git a/code/libraries/array/java/nu/marginalia/array/page/UnsafeLongArray.java b/code/libraries/array/java/nu/marginalia/array/page/UnsafeLongArray.java index 509fb829..36e9f32e 100644 --- a/code/libraries/array/java/nu/marginalia/array/page/UnsafeLongArray.java +++ b/code/libraries/array/java/nu/marginalia/array/page/UnsafeLongArray.java @@ -283,9 +283,11 @@ public class UnsafeLongArray implements LongArray { if (destEndL > size()) throw new IndexOutOfBoundsException("Destination array too small"); - for (long i = destStartL; i < destEndL; i++) { - set(i, source.get(sourceStartL + i - destStartL)); - } + MemorySegment.copy( + source.getMemorySegment(), JAVA_LONG, sourceStartL, + segment, JAVA_LONG, destStartL, + destEndL - destStartL + ); } }