From dc3f290c7d06921e95aeb2dd089844a82163a8f0 Mon Sep 17 00:00:00 2001 From: stczwd Date: Sun, 15 May 2022 22:13:11 +0800 Subject: [PATCH] supports skipping bounds check for setBytes and getBytes of ArrowBuf --- .../java/org/apache/arrow/memory/ArrowBuf.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/ArrowBuf.java b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/ArrowBuf.java index d7827073ea2..173d0a52dc4 100644 --- a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/ArrowBuf.java +++ b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/ArrowBuf.java @@ -692,12 +692,14 @@ private static boolean isOutOfBounds(long index, long length, long capacity) { } private void checkIndex(long index, long fieldLength) { - // check reference count - this.ensureAccessible(); - // check bounds - if (isOutOfBounds(index, fieldLength, this.capacity())) { - throw new IndexOutOfBoundsException(String.format("index: %d, length: %d (expected: range(0, %d))", - index, fieldLength, this.capacity())); + if (BoundsChecking.BOUNDS_CHECKING_ENABLED) { + // check reference count + this.ensureAccessible(); + // check bounds + if (isOutOfBounds(index, fieldLength, this.capacity())) { + throw new IndexOutOfBoundsException(String.format("index: %d, length: %d (expected: range(0, %d))", + index, fieldLength, this.capacity())); + } } }