From 89a48014f0ddbb09e9f901f8f8d1d57e2242f4f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20Hoffst=C3=A4tte?= Date: Tue, 25 Mar 2014 10:19:25 +0100 Subject: [PATCH] Let ByteArray/BigByteArray.get() indicate whether a byte[] was materialized. --- src/main/java/org/elasticsearch/common/util/BigArrays.java | 3 ++- src/main/java/org/elasticsearch/common/util/BigByteArray.java | 4 +++- src/main/java/org/elasticsearch/common/util/ByteArray.java | 4 +++- .../org/elasticsearch/test/cache/recycler/MockBigArrays.java | 4 ++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/elasticsearch/common/util/BigArrays.java b/src/main/java/org/elasticsearch/common/util/BigArrays.java index 3bfcccedf2f..6bf3eae8c04 100644 --- a/src/main/java/org/elasticsearch/common/util/BigArrays.java +++ b/src/main/java/org/elasticsearch/common/util/BigArrays.java @@ -127,11 +127,12 @@ public class BigArrays extends AbstractComponent { } @Override - public void get(long index, int len, BytesRef ref) { + public boolean get(long index, int len, BytesRef ref) { assert indexIsInt(index); ref.bytes = array; ref.offset = (int) index; ref.length = len; + return false; } @Override diff --git a/src/main/java/org/elasticsearch/common/util/BigByteArray.java b/src/main/java/org/elasticsearch/common/util/BigByteArray.java index c2de9ad3e75..405dd78808e 100644 --- a/src/main/java/org/elasticsearch/common/util/BigByteArray.java +++ b/src/main/java/org/elasticsearch/common/util/BigByteArray.java @@ -65,7 +65,7 @@ final class BigByteArray extends AbstractBigArray implements ByteArray { } @Override - public void get(long index, int len, BytesRef ref) { + public boolean get(long index, int len, BytesRef ref) { assert index + len <= size(); int pageIndex = pageIndex(index); final int indexInPage = indexInPage(index); @@ -73,6 +73,7 @@ final class BigByteArray extends AbstractBigArray implements ByteArray { ref.bytes = pages[pageIndex]; ref.offset = indexInPage; ref.length = len; + return false; } else { ref.bytes = new byte[len]; ref.offset = 0; @@ -84,6 +85,7 @@ final class BigByteArray extends AbstractBigArray implements ByteArray { System.arraycopy(pages[pageIndex], 0, ref.bytes, ref.length, copyLength); ref.length += copyLength; } while (ref.length < len); + return true; } } diff --git a/src/main/java/org/elasticsearch/common/util/ByteArray.java b/src/main/java/org/elasticsearch/common/util/ByteArray.java index 07629e3b913..719701a0182 100644 --- a/src/main/java/org/elasticsearch/common/util/ByteArray.java +++ b/src/main/java/org/elasticsearch/common/util/ByteArray.java @@ -38,8 +38,10 @@ public interface ByteArray extends BigArray { /** * Get a reference to a slice. + * + * @return true when a byte[] was materialized, false otherwise. */ - public abstract void get(long index, int len, BytesRef ref); + public abstract boolean get(long index, int len, BytesRef ref); /** * Bulk set. diff --git a/src/test/java/org/elasticsearch/test/cache/recycler/MockBigArrays.java b/src/test/java/org/elasticsearch/test/cache/recycler/MockBigArrays.java index 5c78a617276..ec05c689c2b 100644 --- a/src/test/java/org/elasticsearch/test/cache/recycler/MockBigArrays.java +++ b/src/test/java/org/elasticsearch/test/cache/recycler/MockBigArrays.java @@ -289,8 +289,8 @@ public class MockBigArrays extends BigArrays { } @Override - public void get(long index, int len, BytesRef ref) { - in.get(index, len, ref); + public boolean get(long index, int len, BytesRef ref) { + return in.get(index, len, ref); } @Override