Skip to content

Commit 54bba84

Browse files
committed
Clean up Apply methods.
1 parent 0b8575d commit 54bba84

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Microsoft.Data.Analysis/PrimitiveColumnContainer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ public void AppendMany(T? value, long count)
180180
NullBitMapBuffers.Add(new DataFrameBuffer<byte>());
181181
}
182182

183-
184183
DataFrameBuffer<T> mutableLastBuffer = Buffers.GetOrCreateMutable(Buffers.Count - 1);
185184
int allocatable = (int)Math.Min(remaining, ReadOnlyDataFrameBuffer<T>.MaxCapacity);
186185
mutableLastBuffer.EnsureCapacity(allocatable);
@@ -213,9 +212,10 @@ public void AppendMany(T? value, long count)
213212

214213
public void ApplyElementwise(Func<T?, long, T?> func)
215214
{
215+
var bufferMaxCapacity = ReadOnlyDataFrameBuffer<T>.MaxCapacity;
216216
for (int b = 0; b < Buffers.Count; b++)
217217
{
218-
long prevLength = checked(Buffers[0].Length * b);
218+
long prevLength = checked(bufferMaxCapacity * b);
219219

220220
Span<T> mutableBuffer = Buffers.GetOrCreateMutable(b).Span;
221221
Span<byte> mutableNullBitMapBuffer = NullBitMapBuffers.GetOrCreateMutable(b).Span;
@@ -234,9 +234,10 @@ public void ApplyElementwise(Func<T?, long, T?> func)
234234
public void Apply<TResult>(Func<T?, TResult?> func, PrimitiveColumnContainer<TResult> resultContainer)
235235
where TResult : unmanaged
236236
{
237+
var bufferMaxCapacity = ReadOnlyDataFrameBuffer<T>.MaxCapacity;
237238
for (int b = 0; b < Buffers.Count; b++)
238239
{
239-
long prevLength = checked(Buffers[0].Length * b);
240+
long prevLength = checked(bufferMaxCapacity * b);
240241
var sourceBuffer = Buffers[b];
241242
var sourceNullBitMap = NullBitMapBuffers[b].ReadOnlySpan;
242243

@@ -245,7 +246,6 @@ public void Apply<TResult>(Func<T?, TResult?> func, PrimitiveColumnContainer<TRe
245246

246247
for (int i = 0; i < sourceBuffer.Length; i++)
247248
{
248-
long curIndex = i + prevLength;
249249
bool isValid = IsValid(sourceNullBitMap, i);
250250
TResult? value = func(isValid ? sourceBuffer[i] : null);
251251
mutableResultBuffer[i] = value.GetValueOrDefault();

0 commit comments

Comments
 (0)