From b6bda01c33d27afa1df6bdc2dc9f3e352cc8d16d Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 2 Jul 2017 16:07:20 +0200 Subject: [PATCH] contentenc: MergeBlocks: short-circuit the trivial case Saves 3% for the tar extract benchmark because we skip the allocation. --- internal/contentenc/content.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/contentenc/content.go b/internal/contentenc/content.go index 188b4e2..5d0ff49 100644 --- a/internal/contentenc/content.go +++ b/internal/contentenc/content.go @@ -277,6 +277,10 @@ func (be *ContentEnc) doEncryptBlock(plaintext []byte, blockNo uint64, fileID [] // MergeBlocks - Merge newData into oldData at offset // New block may be bigger than both newData and oldData func (be *ContentEnc) MergeBlocks(oldData []byte, newData []byte, offset int) []byte { + // Fastpath for small-file creation + if len(oldData) == 0 && offset == 0 { + return newData + } // Make block of maximum size out := make([]byte, be.plainBS)