Skip to content

Commit

Permalink
spotless + pull casting out of loops
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauernfeind committed Dec 16, 2024
1 parent 0400086 commit 1e68d61
Show file tree
Hide file tree
Showing 16 changed files with 108 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.deephaven.UncheckedDeephavenException;
import io.deephaven.base.verify.Assert;
import io.deephaven.chunk.Chunk;
import io.deephaven.chunk.ObjectChunk;
import io.deephaven.chunk.attributes.Values;
import io.deephaven.engine.rowset.RowSequence;
import io.deephaven.util.mutable.MutableInt;
Expand Down Expand Up @@ -42,8 +43,9 @@ protected int computeNullCount(
@NotNull final Context context,
@NotNull final RowSequence subset) {
final MutableInt nullCount = new MutableInt(0);
final ObjectChunk<Object, Values> objectChunk = context.getChunk().asObjectChunk();
subset.forAllRowKeys(row -> {
if (context.getChunk().asObjectChunk().isNull((int) row)) {
if (objectChunk.isNull((int) row)) {
nullCount.increment();
}
});
Expand All @@ -55,9 +57,8 @@ protected void writeValidityBufferInternal(
@NotNull final Context context,
@NotNull final RowSequence subset,
@NotNull final SerContext serContext) {
subset.forAllRowKeys(row -> {
serContext.setNextIsNull(context.getChunk().asObjectChunk().isNull((int) row));
});
final ObjectChunk<Object, Values> objectChunk = context.getChunk().asObjectChunk();
subset.forAllRowKeys(row -> serContext.setNextIsNull(objectChunk.isNull((int) row)));
}

@Override
Expand All @@ -73,9 +74,10 @@ protected void writePayload(
.subtract(BigInteger.ONE)
.negate();

final ObjectChunk<BigDecimal, Values> objectChunk = context.getChunk().asObjectChunk();
subset.forAllRowKeys(rowKey -> {
try {
BigDecimal value = context.getChunk().<BigDecimal>asObjectChunk().get((int) rowKey);
BigDecimal value = objectChunk.get((int) rowKey);

if (value.scale() != scale) {
value = value.setScale(decimalType.getScale(), RoundingMode.HALF_UP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public DrainableColumn getInputStream(
@Override
protected int computeNullCount(@NotNull Context context, @NotNull RowSequence subset) {
final MutableInt nullCount = new MutableInt(0);
final ByteChunk<Values> byteChunk = context.getChunk().asByteChunk();
subset.forAllRowKeys(row -> {
if (context.getChunk().asByteChunk().isNull((int) row)) {
if (byteChunk.isNull((int) row)) {
nullCount.increment();
}
});
Expand All @@ -53,9 +54,8 @@ protected int computeNullCount(@NotNull Context context, @NotNull RowSequence su
@Override
protected void writeValidityBufferInternal(@NotNull Context context, @NotNull RowSequence subset,
@NotNull SerContext serContext) {
subset.forAllRowKeys(row -> {
serContext.setNextIsNull(context.getChunk().asByteChunk().isNull((int) row));
});
final ByteChunk<Values> byteChunk = context.getChunk().asByteChunk();
subset.forAllRowKeys(row -> serContext.setNextIsNull(byteChunk.isNull((int) row)));
}

private class BooleanChunkInputStream extends BaseChunkInputStream<Context> {
Expand Down Expand Up @@ -106,8 +106,9 @@ public int drainTo(final OutputStream outputStream) throws IOException {
// write the payload buffer
// we cheat and re-use validity buffer serialization code
try (final SerContext serContext = new SerContext(dos)) {
final ByteChunk<Values> byteChunk = context.getChunk().asByteChunk();
subset.forAllRowKeys(row -> serContext.setNextIsNull(
context.getChunk().asByteChunk().get((int) row) != BooleanUtils.TRUE_BOOLEAN_AS_BYTE));
byteChunk.get((int) row) != BooleanUtils.TRUE_BOOLEAN_AS_BYTE));
}
bytesWritten += getNumLongsForBitPackOfSize(subset.intSize(DEBUG_NAME)) * (long) Long.BYTES;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ protected int computeNullCount(
@NotNull final Context context,
@NotNull final RowSequence subset) {
final MutableInt nullCount = new MutableInt(0);
final ByteChunk<Values> byteChunk = context.getChunk().asByteChunk();
subset.forAllRowKeys(row -> {
if (context.getChunk().asByteChunk().isNull((int) row)) {
if (byteChunk.isNull((int) row)) {
nullCount.increment();
}
});
Expand All @@ -80,9 +81,8 @@ protected void writeValidityBufferInternal(
@NotNull final Context context,
@NotNull final RowSequence subset,
@NotNull final SerContext serContext) {
subset.forAllRowKeys(row -> {
serContext.setNextIsNull(context.getChunk().asByteChunk().isNull((int) row));
});
final ByteChunk<Values> byteChunk = context.getChunk().asByteChunk();
subset.forAllRowKeys(row -> serContext.setNextIsNull(byteChunk.isNull((int) row)));
}

private class ByteChunkInputStream extends BaseChunkInputStream<Context> {
Expand Down Expand Up @@ -120,9 +120,10 @@ public int drainTo(final OutputStream outputStream) throws IOException {
bytesWritten += writeValidityBuffer(dos);

// write the payload buffer
final ByteChunk<Values> byteChunk = context.getChunk().asByteChunk();
subset.forAllRowKeys(row -> {
try {
dos.writeByte(context.getChunk().asByteChunk().get((int) row));
dos.writeByte(byteChunk.get((int) row));
} catch (final IOException e) {
throw new UncheckedDeephavenException(
"Unexpected exception while draining data to OutputStream: ", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ protected int computeNullCount(
@NotNull final Context context,
@NotNull final RowSequence subset) {
final MutableInt nullCount = new MutableInt(0);
final CharChunk<Values> charChunk = context.getChunk().asCharChunk();
subset.forAllRowKeys(row -> {
if (context.getChunk().asCharChunk().isNull((int) row)) {
if (charChunk.isNull((int) row)) {
nullCount.increment();
}
});
Expand All @@ -76,9 +77,8 @@ protected void writeValidityBufferInternal(
@NotNull final Context context,
@NotNull final RowSequence subset,
@NotNull final SerContext serContext) {
subset.forAllRowKeys(row -> {
serContext.setNextIsNull(context.getChunk().asCharChunk().isNull((int) row));
});
final CharChunk<Values> charChunk = context.getChunk().asCharChunk();
subset.forAllRowKeys(row -> serContext.setNextIsNull(charChunk.isNull((int) row)));
}

private class CharChunkInputStream extends BaseChunkInputStream<Context> {
Expand Down Expand Up @@ -116,9 +116,10 @@ public int drainTo(final OutputStream outputStream) throws IOException {
bytesWritten += writeValidityBuffer(dos);

// write the payload buffer
final CharChunk<Values> charChunk = context.getChunk().asCharChunk();
subset.forAllRowKeys(row -> {
try {
dos.writeChar(context.getChunk().asCharChunk().get((int) row));
dos.writeChar(charChunk.get((int) row));
} catch (final IOException e) {
throw new UncheckedDeephavenException(
"Unexpected exception while draining data to OutputStream: ", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1157,8 +1157,9 @@ protected void writePayload(
@NotNull final Context context,
@NotNull final DataOutput dos,
@NotNull final RowSequence subset) {
final ObjectChunk<byte[], Values> objectChunk = context.getChunk().asObjectChunk();
subset.forAllRowKeys(row -> {
final byte[] data = context.getChunk().<byte[]>asObjectChunk().get((int) row);
final byte[] data = objectChunk.get((int) row);
if (data.length != elementWidth) {
throw new IllegalArgumentException(String.format(
"Expected fixed size binary of %d bytes, but got %d bytes when serializing %s",
Expand Down Expand Up @@ -1235,8 +1236,9 @@ protected void writePayload(
@NotNull final Context context,
@NotNull final DataOutput dos,
@NotNull final RowSequence subset) {
final ObjectChunk<Duration, Values> objectChunk = context.getChunk().asObjectChunk();
subset.forAllRowKeys(row -> {
final Duration value = context.getChunk().<Duration>asObjectChunk().get((int) row);
final Duration value = objectChunk.get((int) row);
try {
if (value == null) {
dos.writeInt(0);
Expand Down Expand Up @@ -1304,8 +1306,9 @@ protected void writePayload(
@NotNull final Context context,
@NotNull final DataOutput dos,
@NotNull final RowSequence subset) {
final ObjectChunk<Period, Values> objectChunk = context.getChunk().asObjectChunk();
subset.forAllRowKeys(row -> {
final Period value = context.getChunk().<Period>asObjectChunk().get((int) row);
final Period value = objectChunk.get((int) row);
try {
if (value == null) {
dos.writeInt(0);
Expand All @@ -1331,8 +1334,9 @@ protected void writePayload(
@NotNull final Context context,
@NotNull final DataOutput dos,
@NotNull final RowSequence subset) {
final ObjectChunk<Period, Values> objectChunk = context.getChunk().asObjectChunk();
subset.forAllRowKeys(row -> {
final Period value = context.getChunk().<Period>asObjectChunk().get((int) row);
final Period value = objectChunk.get((int) row);
try {
if (value == null) {
dos.writeInt(0);
Expand Down Expand Up @@ -1381,9 +1385,10 @@ protected void writePayload(
@NotNull final Context context,
@NotNull final DataOutput dos,
@NotNull final RowSequence subset) {
final ObjectChunk<PeriodDuration, Values> objectChunk = context.getChunk().asObjectChunk();
subset.forAllRowKeys(row -> {
final PeriodDuration value =
context.getChunk().<PeriodDuration>asObjectChunk().get((int) row);
objectChunk.get((int) row);
try {
if (value == null) {
dos.writeInt(0);
Expand All @@ -1409,9 +1414,9 @@ protected void writePayload(
@NotNull final Context context,
@NotNull final DataOutput dos,
@NotNull final RowSequence subset) {
final ObjectChunk<PeriodDuration, Values> objectChunk = context.getChunk().asObjectChunk();
subset.forAllRowKeys(row -> {
final PeriodDuration value =
context.getChunk().<PeriodDuration>asObjectChunk().get((int) row);
final PeriodDuration value = objectChunk.get((int) row);
try {
if (value == null) {
dos.writeInt(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ protected int computeNullCount(
@NotNull final Context context,
@NotNull final RowSequence subset) {
final MutableInt nullCount = new MutableInt(0);
final DoubleChunk<Values> doubleChunk = context.getChunk().asDoubleChunk();
subset.forAllRowKeys(row -> {
if (context.getChunk().asDoubleChunk().isNull((int) row)) {
if (doubleChunk.isNull((int) row)) {
nullCount.increment();
}
});
Expand All @@ -80,9 +81,8 @@ protected void writeValidityBufferInternal(
@NotNull final Context context,
@NotNull final RowSequence subset,
@NotNull final SerContext serContext) {
subset.forAllRowKeys(row -> {
serContext.setNextIsNull(context.getChunk().asDoubleChunk().isNull((int) row));
});
final DoubleChunk<Values> doubleChunk = context.getChunk().asDoubleChunk();
subset.forAllRowKeys(row -> serContext.setNextIsNull(doubleChunk.isNull((int) row)));
}

private class DoubleChunkInputStream extends BaseChunkInputStream<Context> {
Expand Down Expand Up @@ -120,9 +120,10 @@ public int drainTo(final OutputStream outputStream) throws IOException {
bytesWritten += writeValidityBuffer(dos);

// write the payload buffer
final DoubleChunk<Values> doubleChunk = context.getChunk().asDoubleChunk();
subset.forAllRowKeys(row -> {
try {
dos.writeDouble(context.getChunk().asDoubleChunk().get((int) row));
dos.writeDouble(doubleChunk.get((int) row));
} catch (final IOException e) {
throw new UncheckedDeephavenException(
"Unexpected exception while draining data to OutputStream: ", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ protected int computeNullCount(
@NotNull final BaseChunkWriter.Context context,
@NotNull final RowSequence subset) {
final MutableInt nullCount = new MutableInt(0);
final ObjectChunk<Object, Values> objectChunk = context.getChunk().asObjectChunk();
subset.forAllRowKeys(row -> {
if (context.getChunk().asObjectChunk().isNull((int) row)) {
if (objectChunk.isNull((int) row)) {
nullCount.increment();
}
});
Expand All @@ -36,8 +37,7 @@ protected void writeValidityBufferInternal(
@NotNull final BaseChunkWriter.Context context,
@NotNull final RowSequence subset,
@NotNull final SerContext serContext) {
subset.forAllRowKeys(row -> {
serContext.setNextIsNull(context.getChunk().asObjectChunk().isNull((int) row));
});
final ObjectChunk<Object, Values> objectChunk = context.getChunk().asObjectChunk();
subset.forAllRowKeys(row -> serContext.setNextIsNull(objectChunk.isNull((int) row)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ protected int computeNullCount(
@NotNull final Context context,
@NotNull final RowSequence subset) {
final MutableInt nullCount = new MutableInt(0);
final FloatChunk<Values> floatChunk = context.getChunk().asFloatChunk();
subset.forAllRowKeys(row -> {
if (context.getChunk().asFloatChunk().isNull((int) row)) {
if (floatChunk.isNull((int) row)) {
nullCount.increment();
}
});
Expand All @@ -80,9 +81,8 @@ protected void writeValidityBufferInternal(
@NotNull final Context context,
@NotNull final RowSequence subset,
@NotNull final SerContext serContext) {
subset.forAllRowKeys(row -> {
serContext.setNextIsNull(context.getChunk().asFloatChunk().isNull((int) row));
});
final FloatChunk<Values> floatChunk = context.getChunk().asFloatChunk();
subset.forAllRowKeys(row -> serContext.setNextIsNull(floatChunk.isNull((int) row)));
}

private class FloatChunkInputStream extends BaseChunkInputStream<Context> {
Expand Down Expand Up @@ -120,9 +120,10 @@ public int drainTo(final OutputStream outputStream) throws IOException {
bytesWritten += writeValidityBuffer(dos);

// write the payload buffer
final FloatChunk<Values> floatChunk = context.getChunk().asFloatChunk();
subset.forAllRowKeys(row -> {
try {
dos.writeFloat(context.getChunk().asFloatChunk().get((int) row));
dos.writeFloat(floatChunk.get((int) row));
} catch (final IOException e) {
throw new UncheckedDeephavenException(
"Unexpected exception while draining data to OutputStream: ", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ protected int computeNullCount(
@NotNull final Context context,
@NotNull final RowSequence subset) {
final MutableInt nullCount = new MutableInt(0);
final IntChunk<Values> intChunk = context.getChunk().asIntChunk();
subset.forAllRowKeys(row -> {
if (context.getChunk().asIntChunk().isNull((int) row)) {
if (intChunk.isNull((int) row)) {
nullCount.increment();
}
});
Expand All @@ -80,9 +81,8 @@ protected void writeValidityBufferInternal(
@NotNull final Context context,
@NotNull final RowSequence subset,
@NotNull final SerContext serContext) {
subset.forAllRowKeys(row -> {
serContext.setNextIsNull(context.getChunk().asIntChunk().isNull((int) row));
});
final IntChunk<Values> intChunk = context.getChunk().asIntChunk();
subset.forAllRowKeys(row -> serContext.setNextIsNull(intChunk.isNull((int) row)));
}

private class IntChunkInputStream extends BaseChunkInputStream<Context> {
Expand Down Expand Up @@ -120,9 +120,10 @@ public int drainTo(final OutputStream outputStream) throws IOException {
bytesWritten += writeValidityBuffer(dos);

// write the payload buffer
final IntChunk<Values> intChunk = context.getChunk().asIntChunk();
subset.forAllRowKeys(row -> {
try {
dos.writeInt(context.getChunk().asIntChunk().get((int) row));
dos.writeInt(intChunk.get((int) row));
} catch (final IOException e) {
throw new UncheckedDeephavenException(
"Unexpected exception while draining data to OutputStream: ", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ protected int computeNullCount(
@NotNull final ChunkWriter.Context context,
@NotNull final RowSequence subset) {
final MutableInt nullCount = new MutableInt(0);
final ObjectChunk<Object, Values> objectChunk = context.getChunk().asObjectChunk();
subset.forAllRowKeys(row -> {
if (context.getChunk().asObjectChunk().isNull((int) row)) {
if (objectChunk.isNull((int) row)) {
nullCount.increment();
}
});
Expand All @@ -62,9 +63,8 @@ protected void writeValidityBufferInternal(
@NotNull final ChunkWriter.Context context,
@NotNull final RowSequence subset,
@NotNull final SerContext serContext) {
subset.forAllRowKeys(row -> {
serContext.setNextIsNull(context.getChunk().asObjectChunk().isNull((int) row));
});
final ObjectChunk<Object, Values> objectChunk = context.getChunk().asObjectChunk();
subset.forAllRowKeys(row -> serContext.setNextIsNull(objectChunk.isNull((int) row)));
}

@Override
Expand Down
Loading

0 comments on commit 1e68d61

Please sign in to comment.