Skip to content

Commit 5006dd8

Browse files
committed
Reduce allocations during readNativeFrames with frame channel
1 parent 8f1f151 commit 5006dd8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

read.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ func (r *reader) readPixelData(vl uint32, d *Dataset, fc chan<- *frame.Frame) (V
256256

257257
if fc != nil {
258258
fc <- &f
259+
} else {
260+
image.Frames = append(image.Frames, &f)
259261
}
260-
261-
image.Frames = append(image.Frames, &f)
262262
}
263263
image.IntentionallySkipped = r.opts.skipPixelData
264264
return &pixelDataValue{PixelDataInfo: image}, nil
@@ -482,9 +482,10 @@ func (r *reader) readNativeFrames(parsedData *Dataset, fc chan<- *frame.Frame, v
482482
currentFrame.NativeData.Data[pixel] = buf[pixel*samplesPerPixel : (pixel+1)*samplesPerPixel]
483483
}
484484
}
485-
image.Frames[frameIdx] = &currentFrame
486485
if fc != nil {
487486
fc <- &currentFrame // write the current frame to the frame channel
487+
} else {
488+
image.Frames[frameIdx] = &currentFrame
488489
}
489490
}
490491
if skipFinalPaddingByte {

0 commit comments

Comments
 (0)