This is an automated email from the ASF dual-hosted git repository.

andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git

commit 84b305ca59c764839779d29aa9f58559a63acf53
Author: Andy Seaborne <[email protected]>
AuthorDate: Sun Dec 14 22:12:25 2025 +0000

    ByteBufferLib - Clearly separate old for-reference code
---
 .../org/apache/jena/atlas/lib/ByteBufferLib.java   | 76 ++++++++++++----------
 1 file changed, 43 insertions(+), 33 deletions(-)

diff --git 
a/jena-base/src/main/java/org/apache/jena/atlas/lib/ByteBufferLib.java 
b/jena-base/src/main/java/org/apache/jena/atlas/lib/ByteBufferLib.java
index 2b57ae4aed..89266655b9 100644
--- a/jena-base/src/main/java/org/apache/jena/atlas/lib/ByteBufferLib.java
+++ b/jena-base/src/main/java/org/apache/jena/atlas/lib/ByteBufferLib.java
@@ -163,42 +163,52 @@ public class ByteBufferLib {
     }
 
     // --------
-    // For the record ...
-
-    /**
-     * Bulk copy, without using an intermediate byte[].
-     */
-    private final static void bbcopyOLD(ByteBuffer bb, int src, int dst, int 
length, int slotLen) {
-        if ( src == dst )
-            return ;
-
-        if ( allowArray && bb.hasArray() ) {
-            acopyArray(bb, src, dst, length, slotLen) ;
-            return ;
+    private static class Archive {
+        // --- For reference
+
+        // This is the original version of bbcopy.
+        // It operates without creating a temporary area (the srcBytes array 
above).
+        // but then the bulk operations can not be used.
+        // It splits the call into 2 cases:
+        // bbcopy1 (src < dst) and bbcopy2 (src > dst).
+
+        // Java execution capabilities have evolved.
+        // 2023-03 : This is slower than bbcopyBulk.
+        // https://github.com/apache/jena/pull/1800
+        // https://github.com/apache/jena/issue/1803
+
+        private final static void a_bbcopy(ByteBuffer bb, int src, int dst, 
int length, int slotLen) {
+            if ( src == dst )
+                return ;
+
+            if ( allowArray && bb.hasArray() ) {
+                acopyArray(bb, src, dst, length, slotLen) ;
+                return ;
+            }
+            // For non-array versions : beware of overlaps.
+            if ( src < dst )
+                a_bbcopy1(bb, src, dst, length, slotLen) ;
+            else
+                a_bbcopy2(bb, src, dst, length, slotLen) ;
         }
 
-        if ( src < dst )
-            bbcopy1(bb, src, dst, length, slotLen) ;
-        else
-            bbcopy2(bb, src, dst, length, slotLen) ;
-    }
-
-    private final static void bbcopy1(ByteBuffer bb, int src, int dst, int 
length, int slotLen) {
-        int bDst = dst * slotLen ;
-        int bSrc = src * slotLen ;
-        int bLen = length * slotLen ;
-        // src < dst so top dst is not in the overlap : work backwards
-        for ( int i = bLen - 1 ; i >= 0 ; i-- )
-            bb.put(bDst + i, bb.get(bSrc + i)) ;
-    }
+        private final static void a_bbcopy1(ByteBuffer bb, int src, int dst, 
int length, int slotLen) {
+            int bDst = dst * slotLen ;
+            int bSrc = src * slotLen ;
+            int bLen = length * slotLen ;
+            // src < dst so top dst is not in the overlap : work backwards
+            for ( int i = bLen - 1 ; i >= 0 ; i-- )
+                bb.put(bDst + i, bb.get(bSrc + i)) ;
+        }
 
-    private final static void bbcopy2(ByteBuffer bb, int src, int dst, int 
length, int slotLen) {
-        int bDst = dst * slotLen ;
-        int bSrc = src * slotLen ;
-        int bLen = length * slotLen ;
-        // src > dst so dst[0] is not in the overlap
-        for ( int i = 0 ; i < bLen ; i++ )
-            bb.put(bDst + i, bb.get(bSrc + i)) ;
+        private final static void a_bbcopy2(ByteBuffer bb, int src, int dst, 
int length, int slotLen) {
+            int bDst = dst * slotLen ;
+            int bSrc = src * slotLen ;
+            int bLen = length * slotLen ;
+            // src > dst so dst[0] is not in the overlap
+            for ( int i = 0 ; i < bLen ; i++ )
+                bb.put(bDst + i, bb.get(bSrc + i)) ;
+        }
     }
 
     // --------

Reply via email to