Skip to content

Commit

Permalink
rename and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ahrav committed Feb 5, 2024
1 parent 3e67392 commit d8e5589
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/writers/buffered_file_writer/bufferedfilewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ func (bp *bufferPool) get(ctx context.Context) *bytes.Buffer {
return buf
}

func (bp *bufferPool) growBufferWithSize(buf *bytes.Buffer, dataSize uint64) {
func (bp *bufferPool) growBufferWithSize(buf *bytes.Buffer, size int) {
// Grow the buffer to accommodate the new data.
requiredGrowth := int(dataSize - uint64(buf.Cap()))
buf.Grow(requiredGrowth)
buf.Grow(size)
}

func (bp *bufferPool) put(buf *bytes.Buffer) {
Expand Down Expand Up @@ -184,14 +183,15 @@ func (w *BufferedFileWriter) Write(ctx context.Context, data []byte) (int, error
"content_size", bufferLength,
)

if totalSizeNeeded > uint64(w.buf.Cap()) {
growSize := int(totalSizeNeeded - uint64(w.buf.Cap()))
if growSize > 0 {
ctx.Logger().V(4).Info(
"buffer size exceeded, getting new buffer",
"buffer size exceeded, growing buffer",
"current_size", bufferLength,
"new_size", totalSizeNeeded,
"grow_size", growSize,
)
// The current buffer cannot accommodate the new data; grow it.
w.bufPool.growBufferWithSize(w.buf, totalSizeNeeded)
w.bufPool.growBufferWithSize(w.buf, growSize)
}

return w.buf.Write(data)
Expand Down

0 comments on commit d8e5589

Please sign in to comment.