diff options
author | Jakob Unterwurzacher | 2017-07-02 16:07:20 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2017-07-02 16:23:24 +0200 |
commit | b6bda01c33d27afa1df6bdc2dc9f3e352cc8d16d (patch) | |
tree | 40d36f4073c9f501f3ec7f79f00517f504f921a9 /internal/contentenc/content.go | |
parent | 52ab0462a42c22ccf07d0cc110590fc7db957182 (diff) |
contentenc: MergeBlocks: short-circuit the trivial case
Saves 3% for the tar extract benchmark because we skip the allocation.
Diffstat (limited to 'internal/contentenc/content.go')
-rw-r--r-- | internal/contentenc/content.go | 4 |
1 files changed, 4 insertions, 0 deletions
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) |