Skip to content

Commit b6bda01

Browse files
committed
contentenc: MergeBlocks: short-circuit the trivial case
Saves 3% for the tar extract benchmark because we skip the allocation.
1 parent 52ab046 commit b6bda01

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

internal/contentenc/content.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ func (be *ContentEnc) doEncryptBlock(plaintext []byte, blockNo uint64, fileID []
277277
// MergeBlocks - Merge newData into oldData at offset
278278
// New block may be bigger than both newData and oldData
279279
func (be *ContentEnc) MergeBlocks(oldData []byte, newData []byte, offset int) []byte {
280+
// Fastpath for small-file creation
281+
if len(oldData) == 0 && offset == 0 {
282+
return newData
283+
}
280284

281285
// Make block of maximum size
282286
out := make([]byte, be.plainBS)

0 commit comments

Comments
 (0)