From 5006dd8f3a1cb8fca017af77cebb9676ba08faa1 Mon Sep 17 00:00:00 2001 From: Lam Luong Date: Mon, 6 Nov 2023 09:00:06 +0700 Subject: [PATCH] Reduce allocations during readNativeFrames with frame channel --- read.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/read.go b/read.go index 337735f9..563c1a7d 100644 --- a/read.go +++ b/read.go @@ -256,9 +256,9 @@ func (r *reader) readPixelData(vl uint32, d *Dataset, fc chan<- *frame.Frame) (V if fc != nil { fc <- &f + } else { + image.Frames = append(image.Frames, &f) } - - image.Frames = append(image.Frames, &f) } image.IntentionallySkipped = r.opts.skipPixelData return &pixelDataValue{PixelDataInfo: image}, nil @@ -482,9 +482,10 @@ func (r *reader) readNativeFrames(parsedData *Dataset, fc chan<- *frame.Frame, v currentFrame.NativeData.Data[pixel] = buf[pixel*samplesPerPixel : (pixel+1)*samplesPerPixel] } } - image.Frames[frameIdx] = ¤tFrame if fc != nil { fc <- ¤tFrame // write the current frame to the frame channel + } else { + image.Frames[frameIdx] = ¤tFrame } } if skipFinalPaddingByte {