diff --git a/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/BooleanArrayExpansionKernel.java b/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/BooleanArrayExpansionKernel.java index 26f2556670e..8b7660f1918 100644 --- a/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/BooleanArrayExpansionKernel.java +++ b/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/BooleanArrayExpansionKernel.java @@ -19,7 +19,7 @@ import io.deephaven.chunk.WritableObjectChunk; import io.deephaven.chunk.attributes.Any; import io.deephaven.chunk.attributes.ChunkPositions; -import io.deephaven.chunk.sized.SizedBooleanChunk; +import io.deephaven.util.datastructures.LongSizedDataStructure; public class BooleanArrayExpansionKernel implements ArrayExpansionKernel { private final static boolean[] ZERO_LEN_ARRAY = new boolean[0]; @@ -33,24 +33,29 @@ public WritableChunk expand(final ObjectChunk source } final ObjectChunk typedSource = source.asObjectChunk(); - final SizedBooleanChunk resultWrapper = new SizedBooleanChunk<>(); + + long totalSize = 0; + for (int i = 0; i < typedSource.size(); ++i) { + final boolean[] row = typedSource.get(i); + totalSize += row == null ? 0 : row.length; + } + final WritableBooleanChunk result = WritableBooleanChunk.makeWritableChunk( + LongSizedDataStructure.intSize("ExpansionKernel", totalSize)); int lenWritten = 0; perElementLengthDest.setSize(source.size() + 1); for (int i = 0; i < typedSource.size(); ++i) { final boolean[] row = typedSource.get(i); - final int len = row == null ? 0 : row.length; perElementLengthDest.set(i, lenWritten); - final WritableBooleanChunk result = resultWrapper.ensureCapacityPreserve(lenWritten + len); - for (int j = 0; j < len; ++j) { - result.set(lenWritten + j, row[j]); + if (row == null) { + continue; } - lenWritten += len; - result.setSize(lenWritten); + result.copyFromArray(row, 0, lenWritten, row.length); + lenWritten += row.length; } perElementLengthDest.set(typedSource.size(), lenWritten); - return resultWrapper.get(); + return result; } @Override @@ -77,15 +82,13 @@ public WritableObjectChunk contract( int lenRead = 0; for (int i = 0; i < itemsInBatch; ++i) { - final int ROW_LEN = perElementLengthDest.get(i + 1) - perElementLengthDest.get(i); - if (ROW_LEN == 0) { + final int rowLen = perElementLengthDest.get(i + 1) - perElementLengthDest.get(i); + if (rowLen == 0) { result.set(outOffset + i, ZERO_LEN_ARRAY); } else { - final boolean[] row = new boolean[ROW_LEN]; - for (int j = 0; j < ROW_LEN; ++j) { - row[j] = typedSource.get(lenRead + j); - } - lenRead += ROW_LEN; + final boolean[] row = new boolean[rowLen]; + typedSource.copyToArray(lenRead, row,0, rowLen); + lenRead += rowLen; result.set(outOffset + i, row); } } diff --git a/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/ByteArrayExpansionKernel.java b/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/ByteArrayExpansionKernel.java index 867c60b2462..54e08de0987 100644 --- a/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/ByteArrayExpansionKernel.java +++ b/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/ByteArrayExpansionKernel.java @@ -19,7 +19,7 @@ import io.deephaven.chunk.WritableObjectChunk; import io.deephaven.chunk.attributes.Any; import io.deephaven.chunk.attributes.ChunkPositions; -import io.deephaven.chunk.sized.SizedByteChunk; +import io.deephaven.util.datastructures.LongSizedDataStructure; public class ByteArrayExpansionKernel implements ArrayExpansionKernel { private final static byte[] ZERO_LEN_ARRAY = new byte[0]; @@ -33,24 +33,29 @@ public WritableChunk expand(final ObjectChunk source } final ObjectChunk typedSource = source.asObjectChunk(); - final SizedByteChunk resultWrapper = new SizedByteChunk<>(); + + long totalSize = 0; + for (int i = 0; i < typedSource.size(); ++i) { + final byte[] row = typedSource.get(i); + totalSize += row == null ? 0 : row.length; + } + final WritableByteChunk result = WritableByteChunk.makeWritableChunk( + LongSizedDataStructure.intSize("ExpansionKernel", totalSize)); int lenWritten = 0; perElementLengthDest.setSize(source.size() + 1); for (int i = 0; i < typedSource.size(); ++i) { final byte[] row = typedSource.get(i); - final int len = row == null ? 0 : row.length; perElementLengthDest.set(i, lenWritten); - final WritableByteChunk result = resultWrapper.ensureCapacityPreserve(lenWritten + len); - for (int j = 0; j < len; ++j) { - result.set(lenWritten + j, row[j]); + if (row == null) { + continue; } - lenWritten += len; - result.setSize(lenWritten); + result.copyFromArray(row, 0, lenWritten, row.length); + lenWritten += row.length; } perElementLengthDest.set(typedSource.size(), lenWritten); - return resultWrapper.get(); + return result; } @Override @@ -77,15 +82,13 @@ public WritableObjectChunk contract( int lenRead = 0; for (int i = 0; i < itemsInBatch; ++i) { - final int ROW_LEN = perElementLengthDest.get(i + 1) - perElementLengthDest.get(i); - if (ROW_LEN == 0) { + final int rowLen = perElementLengthDest.get(i + 1) - perElementLengthDest.get(i); + if (rowLen == 0) { result.set(outOffset + i, ZERO_LEN_ARRAY); } else { - final byte[] row = new byte[ROW_LEN]; - for (int j = 0; j < ROW_LEN; ++j) { - row[j] = typedSource.get(lenRead + j); - } - lenRead += ROW_LEN; + final byte[] row = new byte[rowLen]; + typedSource.copyToArray(lenRead, row,0, rowLen); + lenRead += rowLen; result.set(outOffset + i, row); } } diff --git a/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/CharArrayExpansionKernel.java b/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/CharArrayExpansionKernel.java index b1f203773e7..bbdacc7b62c 100644 --- a/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/CharArrayExpansionKernel.java +++ b/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/CharArrayExpansionKernel.java @@ -14,7 +14,7 @@ import io.deephaven.chunk.WritableObjectChunk; import io.deephaven.chunk.attributes.Any; import io.deephaven.chunk.attributes.ChunkPositions; -import io.deephaven.chunk.sized.SizedCharChunk; +import io.deephaven.util.datastructures.LongSizedDataStructure; public class CharArrayExpansionKernel implements ArrayExpansionKernel { private final static char[] ZERO_LEN_ARRAY = new char[0]; @@ -28,24 +28,29 @@ public WritableChunk expand(final ObjectChunk source } final ObjectChunk typedSource = source.asObjectChunk(); - final SizedCharChunk resultWrapper = new SizedCharChunk<>(); + + long totalSize = 0; + for (int i = 0; i < typedSource.size(); ++i) { + final char[] row = typedSource.get(i); + totalSize += row == null ? 0 : row.length; + } + final WritableCharChunk result = WritableCharChunk.makeWritableChunk( + LongSizedDataStructure.intSize("ExpansionKernel", totalSize)); int lenWritten = 0; perElementLengthDest.setSize(source.size() + 1); for (int i = 0; i < typedSource.size(); ++i) { final char[] row = typedSource.get(i); - final int len = row == null ? 0 : row.length; perElementLengthDest.set(i, lenWritten); - final WritableCharChunk result = resultWrapper.ensureCapacityPreserve(lenWritten + len); - for (int j = 0; j < len; ++j) { - result.set(lenWritten + j, row[j]); + if (row == null) { + continue; } - lenWritten += len; - result.setSize(lenWritten); + result.copyFromArray(row, 0, lenWritten, row.length); + lenWritten += row.length; } perElementLengthDest.set(typedSource.size(), lenWritten); - return resultWrapper.get(); + return result; } @Override @@ -72,15 +77,13 @@ public WritableObjectChunk contract( int lenRead = 0; for (int i = 0; i < itemsInBatch; ++i) { - final int ROW_LEN = perElementLengthDest.get(i + 1) - perElementLengthDest.get(i); - if (ROW_LEN == 0) { + final int rowLen = perElementLengthDest.get(i + 1) - perElementLengthDest.get(i); + if (rowLen == 0) { result.set(outOffset + i, ZERO_LEN_ARRAY); } else { - final char[] row = new char[ROW_LEN]; - for (int j = 0; j < ROW_LEN; ++j) { - row[j] = typedSource.get(lenRead + j); - } - lenRead += ROW_LEN; + final char[] row = new char[rowLen]; + typedSource.copyToArray(lenRead, row,0, rowLen); + lenRead += rowLen; result.set(outOffset + i, row); } } diff --git a/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/DoubleArrayExpansionKernel.java b/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/DoubleArrayExpansionKernel.java index 8d20e5db78f..66b295e0cfc 100644 --- a/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/DoubleArrayExpansionKernel.java +++ b/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/DoubleArrayExpansionKernel.java @@ -19,7 +19,7 @@ import io.deephaven.chunk.WritableObjectChunk; import io.deephaven.chunk.attributes.Any; import io.deephaven.chunk.attributes.ChunkPositions; -import io.deephaven.chunk.sized.SizedDoubleChunk; +import io.deephaven.util.datastructures.LongSizedDataStructure; public class DoubleArrayExpansionKernel implements ArrayExpansionKernel { private final static double[] ZERO_LEN_ARRAY = new double[0]; @@ -33,24 +33,29 @@ public WritableChunk expand(final ObjectChunk source } final ObjectChunk typedSource = source.asObjectChunk(); - final SizedDoubleChunk resultWrapper = new SizedDoubleChunk<>(); + + long totalSize = 0; + for (int i = 0; i < typedSource.size(); ++i) { + final double[] row = typedSource.get(i); + totalSize += row == null ? 0 : row.length; + } + final WritableDoubleChunk result = WritableDoubleChunk.makeWritableChunk( + LongSizedDataStructure.intSize("ExpansionKernel", totalSize)); int lenWritten = 0; perElementLengthDest.setSize(source.size() + 1); for (int i = 0; i < typedSource.size(); ++i) { final double[] row = typedSource.get(i); - final int len = row == null ? 0 : row.length; perElementLengthDest.set(i, lenWritten); - final WritableDoubleChunk result = resultWrapper.ensureCapacityPreserve(lenWritten + len); - for (int j = 0; j < len; ++j) { - result.set(lenWritten + j, row[j]); + if (row == null) { + continue; } - lenWritten += len; - result.setSize(lenWritten); + result.copyFromArray(row, 0, lenWritten, row.length); + lenWritten += row.length; } perElementLengthDest.set(typedSource.size(), lenWritten); - return resultWrapper.get(); + return result; } @Override @@ -77,15 +82,13 @@ public WritableObjectChunk contract( int lenRead = 0; for (int i = 0; i < itemsInBatch; ++i) { - final int ROW_LEN = perElementLengthDest.get(i + 1) - perElementLengthDest.get(i); - if (ROW_LEN == 0) { + final int rowLen = perElementLengthDest.get(i + 1) - perElementLengthDest.get(i); + if (rowLen == 0) { result.set(outOffset + i, ZERO_LEN_ARRAY); } else { - final double[] row = new double[ROW_LEN]; - for (int j = 0; j < ROW_LEN; ++j) { - row[j] = typedSource.get(lenRead + j); - } - lenRead += ROW_LEN; + final double[] row = new double[rowLen]; + typedSource.copyToArray(lenRead, row,0, rowLen); + lenRead += rowLen; result.set(outOffset + i, row); } } diff --git a/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/FloatArrayExpansionKernel.java b/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/FloatArrayExpansionKernel.java index 5174c00cfb0..e2160931b34 100644 --- a/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/FloatArrayExpansionKernel.java +++ b/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/FloatArrayExpansionKernel.java @@ -19,7 +19,7 @@ import io.deephaven.chunk.WritableObjectChunk; import io.deephaven.chunk.attributes.Any; import io.deephaven.chunk.attributes.ChunkPositions; -import io.deephaven.chunk.sized.SizedFloatChunk; +import io.deephaven.util.datastructures.LongSizedDataStructure; public class FloatArrayExpansionKernel implements ArrayExpansionKernel { private final static float[] ZERO_LEN_ARRAY = new float[0]; @@ -33,24 +33,29 @@ public WritableChunk expand(final ObjectChunk source } final ObjectChunk typedSource = source.asObjectChunk(); - final SizedFloatChunk resultWrapper = new SizedFloatChunk<>(); + + long totalSize = 0; + for (int i = 0; i < typedSource.size(); ++i) { + final float[] row = typedSource.get(i); + totalSize += row == null ? 0 : row.length; + } + final WritableFloatChunk result = WritableFloatChunk.makeWritableChunk( + LongSizedDataStructure.intSize("ExpansionKernel", totalSize)); int lenWritten = 0; perElementLengthDest.setSize(source.size() + 1); for (int i = 0; i < typedSource.size(); ++i) { final float[] row = typedSource.get(i); - final int len = row == null ? 0 : row.length; perElementLengthDest.set(i, lenWritten); - final WritableFloatChunk result = resultWrapper.ensureCapacityPreserve(lenWritten + len); - for (int j = 0; j < len; ++j) { - result.set(lenWritten + j, row[j]); + if (row == null) { + continue; } - lenWritten += len; - result.setSize(lenWritten); + result.copyFromArray(row, 0, lenWritten, row.length); + lenWritten += row.length; } perElementLengthDest.set(typedSource.size(), lenWritten); - return resultWrapper.get(); + return result; } @Override @@ -77,15 +82,13 @@ public WritableObjectChunk contract( int lenRead = 0; for (int i = 0; i < itemsInBatch; ++i) { - final int ROW_LEN = perElementLengthDest.get(i + 1) - perElementLengthDest.get(i); - if (ROW_LEN == 0) { + final int rowLen = perElementLengthDest.get(i + 1) - perElementLengthDest.get(i); + if (rowLen == 0) { result.set(outOffset + i, ZERO_LEN_ARRAY); } else { - final float[] row = new float[ROW_LEN]; - for (int j = 0; j < ROW_LEN; ++j) { - row[j] = typedSource.get(lenRead + j); - } - lenRead += ROW_LEN; + final float[] row = new float[rowLen]; + typedSource.copyToArray(lenRead, row,0, rowLen); + lenRead += rowLen; result.set(outOffset + i, row); } } diff --git a/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/IntArrayExpansionKernel.java b/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/IntArrayExpansionKernel.java index 9f1bcdad1af..420de818d1f 100644 --- a/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/IntArrayExpansionKernel.java +++ b/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/IntArrayExpansionKernel.java @@ -19,7 +19,7 @@ import io.deephaven.chunk.WritableObjectChunk; import io.deephaven.chunk.attributes.Any; import io.deephaven.chunk.attributes.ChunkPositions; -import io.deephaven.chunk.sized.SizedIntChunk; +import io.deephaven.util.datastructures.LongSizedDataStructure; public class IntArrayExpansionKernel implements ArrayExpansionKernel { private final static int[] ZERO_LEN_ARRAY = new int[0]; @@ -33,24 +33,29 @@ public WritableChunk expand(final ObjectChunk source } final ObjectChunk typedSource = source.asObjectChunk(); - final SizedIntChunk resultWrapper = new SizedIntChunk<>(); + + long totalSize = 0; + for (int i = 0; i < typedSource.size(); ++i) { + final int[] row = typedSource.get(i); + totalSize += row == null ? 0 : row.length; + } + final WritableIntChunk result = WritableIntChunk.makeWritableChunk( + LongSizedDataStructure.intSize("ExpansionKernel", totalSize)); int lenWritten = 0; perElementLengthDest.setSize(source.size() + 1); for (int i = 0; i < typedSource.size(); ++i) { final int[] row = typedSource.get(i); - final int len = row == null ? 0 : row.length; perElementLengthDest.set(i, lenWritten); - final WritableIntChunk result = resultWrapper.ensureCapacityPreserve(lenWritten + len); - for (int j = 0; j < len; ++j) { - result.set(lenWritten + j, row[j]); + if (row == null) { + continue; } - lenWritten += len; - result.setSize(lenWritten); + result.copyFromArray(row, 0, lenWritten, row.length); + lenWritten += row.length; } perElementLengthDest.set(typedSource.size(), lenWritten); - return resultWrapper.get(); + return result; } @Override @@ -77,15 +82,13 @@ public WritableObjectChunk contract( int lenRead = 0; for (int i = 0; i < itemsInBatch; ++i) { - final int ROW_LEN = perElementLengthDest.get(i + 1) - perElementLengthDest.get(i); - if (ROW_LEN == 0) { + final int rowLen = perElementLengthDest.get(i + 1) - perElementLengthDest.get(i); + if (rowLen == 0) { result.set(outOffset + i, ZERO_LEN_ARRAY); } else { - final int[] row = new int[ROW_LEN]; - for (int j = 0; j < ROW_LEN; ++j) { - row[j] = typedSource.get(lenRead + j); - } - lenRead += ROW_LEN; + final int[] row = new int[rowLen]; + typedSource.copyToArray(lenRead, row,0, rowLen); + lenRead += rowLen; result.set(outOffset + i, row); } } diff --git a/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/LongArrayExpansionKernel.java b/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/LongArrayExpansionKernel.java index e2e4f9c744c..4a5b8106641 100644 --- a/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/LongArrayExpansionKernel.java +++ b/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/LongArrayExpansionKernel.java @@ -19,7 +19,7 @@ import io.deephaven.chunk.WritableObjectChunk; import io.deephaven.chunk.attributes.Any; import io.deephaven.chunk.attributes.ChunkPositions; -import io.deephaven.chunk.sized.SizedLongChunk; +import io.deephaven.util.datastructures.LongSizedDataStructure; public class LongArrayExpansionKernel implements ArrayExpansionKernel { private final static long[] ZERO_LEN_ARRAY = new long[0]; @@ -33,24 +33,29 @@ public WritableChunk expand(final ObjectChunk source } final ObjectChunk typedSource = source.asObjectChunk(); - final SizedLongChunk resultWrapper = new SizedLongChunk<>(); + + long totalSize = 0; + for (int i = 0; i < typedSource.size(); ++i) { + final long[] row = typedSource.get(i); + totalSize += row == null ? 0 : row.length; + } + final WritableLongChunk result = WritableLongChunk.makeWritableChunk( + LongSizedDataStructure.intSize("ExpansionKernel", totalSize)); int lenWritten = 0; perElementLengthDest.setSize(source.size() + 1); for (int i = 0; i < typedSource.size(); ++i) { final long[] row = typedSource.get(i); - final int len = row == null ? 0 : row.length; perElementLengthDest.set(i, lenWritten); - final WritableLongChunk result = resultWrapper.ensureCapacityPreserve(lenWritten + len); - for (int j = 0; j < len; ++j) { - result.set(lenWritten + j, row[j]); + if (row == null) { + continue; } - lenWritten += len; - result.setSize(lenWritten); + result.copyFromArray(row, 0, lenWritten, row.length); + lenWritten += row.length; } perElementLengthDest.set(typedSource.size(), lenWritten); - return resultWrapper.get(); + return result; } @Override @@ -77,15 +82,13 @@ public WritableObjectChunk contract( int lenRead = 0; for (int i = 0; i < itemsInBatch; ++i) { - final int ROW_LEN = perElementLengthDest.get(i + 1) - perElementLengthDest.get(i); - if (ROW_LEN == 0) { + final int rowLen = perElementLengthDest.get(i + 1) - perElementLengthDest.get(i); + if (rowLen == 0) { result.set(outOffset + i, ZERO_LEN_ARRAY); } else { - final long[] row = new long[ROW_LEN]; - for (int j = 0; j < ROW_LEN; ++j) { - row[j] = typedSource.get(lenRead + j); - } - lenRead += ROW_LEN; + final long[] row = new long[rowLen]; + typedSource.copyToArray(lenRead, row,0, rowLen); + lenRead += rowLen; result.set(outOffset + i, row); } } diff --git a/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/ObjectArrayExpansionKernel.java b/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/ObjectArrayExpansionKernel.java index 55569999ac1..d4d1dd68678 100644 --- a/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/ObjectArrayExpansionKernel.java +++ b/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/ObjectArrayExpansionKernel.java @@ -8,13 +8,12 @@ import io.deephaven.chunk.attributes.ChunkPositions; import io.deephaven.datastructures.util.CollectionUtil; import io.deephaven.chunk.Chunk; -import io.deephaven.chunk.ChunkType; import io.deephaven.chunk.IntChunk; import io.deephaven.chunk.ObjectChunk; import io.deephaven.chunk.WritableChunk; import io.deephaven.chunk.WritableIntChunk; import io.deephaven.chunk.WritableObjectChunk; -import io.deephaven.chunk.sized.SizedChunk; +import io.deephaven.util.datastructures.LongSizedDataStructure; import java.lang.reflect.Array; @@ -34,24 +33,29 @@ public WritableChunk expand(final ObjectChunk source } final ObjectChunk typedSource = source.asObjectChunk(); - final SizedChunk resultWrapper = new SizedChunk<>(ChunkType.Object); + + long totalSize = 0; + for (int i = 0; i < typedSource.size(); ++i) { + final T[] row = typedSource.get(i); + totalSize += row == null ? 0 : row.length; + } + final WritableObjectChunk result = WritableObjectChunk.makeWritableChunk( + LongSizedDataStructure.intSize("ExpansionKernel", totalSize)); int lenWritten = 0; perElementLengthDest.setSize(source.size() + 1); for (int i = 0; i < typedSource.size(); ++i) { final T[] row = typedSource.get(i); - final int len = row == null ? 0 : row.length; perElementLengthDest.set(i, lenWritten); - final WritableObjectChunk result = resultWrapper.ensureCapacityPreserve(lenWritten + len).asWritableObjectChunk(); - for (int j = 0; j < len; ++j) { - result.set(lenWritten + j, row[j]); + if (row == null) { + continue; } - lenWritten += len; - result.setSize(lenWritten); + result.copyFromArray(row, 0, lenWritten, row.length); + lenWritten += row.length; } perElementLengthDest.set(typedSource.size(), lenWritten); - return resultWrapper.get(); + return result; } @Override @@ -78,15 +82,13 @@ public WritableObjectChunk contract( int lenRead = 0; for (int i = 0; i < itemsInBatch; ++i) { - final int ROW_LEN = perElementLengthDest.get(i + 1) - perElementLengthDest.get(i); - if (ROW_LEN == 0) { + final int rowLen = perElementLengthDest.get(i + 1) - perElementLengthDest.get(i); + if (rowLen == 0) { result.set(outOffset + i, CollectionUtil.ZERO_LENGTH_OBJECT_ARRAY); } else { - final Object[] row = (Object[])Array.newInstance(componentType, ROW_LEN); - for (int j = 0; j < ROW_LEN; ++j) { - row[j] = typedSource.get(lenRead + j); - } - lenRead += ROW_LEN; + final Object[] row = (Object[])Array.newInstance(componentType, rowLen); + typedSource.copyToArray(lenRead, row, 0, rowLen ); + lenRead += rowLen; result.set(outOffset + i, row); } } diff --git a/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/ShortArrayExpansionKernel.java b/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/ShortArrayExpansionKernel.java index 8bbf844cb80..c0349365859 100644 --- a/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/ShortArrayExpansionKernel.java +++ b/extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/array/ShortArrayExpansionKernel.java @@ -19,7 +19,7 @@ import io.deephaven.chunk.WritableObjectChunk; import io.deephaven.chunk.attributes.Any; import io.deephaven.chunk.attributes.ChunkPositions; -import io.deephaven.chunk.sized.SizedShortChunk; +import io.deephaven.util.datastructures.LongSizedDataStructure; public class ShortArrayExpansionKernel implements ArrayExpansionKernel { private final static short[] ZERO_LEN_ARRAY = new short[0]; @@ -33,24 +33,29 @@ public WritableChunk expand(final ObjectChunk source } final ObjectChunk typedSource = source.asObjectChunk(); - final SizedShortChunk resultWrapper = new SizedShortChunk<>(); + + long totalSize = 0; + for (int i = 0; i < typedSource.size(); ++i) { + final short[] row = typedSource.get(i); + totalSize += row == null ? 0 : row.length; + } + final WritableShortChunk result = WritableShortChunk.makeWritableChunk( + LongSizedDataStructure.intSize("ExpansionKernel", totalSize)); int lenWritten = 0; perElementLengthDest.setSize(source.size() + 1); for (int i = 0; i < typedSource.size(); ++i) { final short[] row = typedSource.get(i); - final int len = row == null ? 0 : row.length; perElementLengthDest.set(i, lenWritten); - final WritableShortChunk result = resultWrapper.ensureCapacityPreserve(lenWritten + len); - for (int j = 0; j < len; ++j) { - result.set(lenWritten + j, row[j]); + if (row == null) { + continue; } - lenWritten += len; - result.setSize(lenWritten); + result.copyFromArray(row, 0, lenWritten, row.length); + lenWritten += row.length; } perElementLengthDest.set(typedSource.size(), lenWritten); - return resultWrapper.get(); + return result; } @Override @@ -77,15 +82,13 @@ public WritableObjectChunk contract( int lenRead = 0; for (int i = 0; i < itemsInBatch; ++i) { - final int ROW_LEN = perElementLengthDest.get(i + 1) - perElementLengthDest.get(i); - if (ROW_LEN == 0) { + final int rowLen = perElementLengthDest.get(i + 1) - perElementLengthDest.get(i); + if (rowLen == 0) { result.set(outOffset + i, ZERO_LEN_ARRAY); } else { - final short[] row = new short[ROW_LEN]; - for (int j = 0; j < ROW_LEN; ++j) { - row[j] = typedSource.get(lenRead + j); - } - lenRead += ROW_LEN; + final short[] row = new short[rowLen]; + typedSource.copyToArray(lenRead, row,0, rowLen); + lenRead += rowLen; result.set(outOffset + i, row); } }