diff --git a/src/Microsoft.Data.Analysis/PrimitiveColumnContainer.cs b/src/Microsoft.Data.Analysis/PrimitiveColumnContainer.cs index 063a9b50af..df5a09c2a5 100644 --- a/src/Microsoft.Data.Analysis/PrimitiveColumnContainer.cs +++ b/src/Microsoft.Data.Analysis/PrimitiveColumnContainer.cs @@ -257,17 +257,10 @@ public void Apply(Func func, PrimitiveColumnContainer buffer = Buffers[b]; - long prevLength = checked(Buffers[0].Length * b); - DataFrameBuffer mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); - Buffers[b] = mutableBuffer; - Span span = mutableBuffer.Span; - DataFrameBuffer mutableNullBitMapBuffer = DataFrameBuffer.GetMutableBuffer(NullBitMapBuffers[b]); - NullBitMapBuffers[b] = mutableNullBitMapBuffer; - Span nullBitMapSpan = mutableNullBitMapBuffer.Span; + ReadOnlyDataFrameBuffer sourceBuffer = Buffers[b]; + ReadOnlySpan sourceNullBitMap = NullBitMapBuffers[b].ReadOnlySpan; ReadOnlyDataFrameBuffer resultBuffer = resultContainer.Buffers[b]; - long resultPrevLength = checked(resultContainer.Buffers[0].Length * b); DataFrameBuffer resultMutableBuffer = DataFrameBuffer.GetMutableBuffer(resultBuffer); resultContainer.Buffers[b] = resultMutableBuffer; Span resultSpan = resultMutableBuffer.Span; @@ -275,13 +268,12 @@ public void Apply(Func func, PrimitiveColumnContainer resultNullBitMapSpan = resultMutableNullBitMapBuffer.Span; - for (int i = 0; i < span.Length; i++) + for (int i = 0; i < Buffers[b].Length; i++) { - long curIndex = i + prevLength; - bool isValid = IsValid(nullBitMapSpan, i); - TResult? value = func(isValid ? span[i] : default(T?)); + bool isValid = IsValid(sourceNullBitMap, i); + TResult? value = func(isValid ? sourceBuffer[i] : default(T?)); resultSpan[i] = value.GetValueOrDefault(); - SetValidityBit(resultNullBitMapSpan, i, value != null); + resultContainer.SetValidityBit(resultNullBitMapSpan, i, value != null); } } }