forked from TrueCloudLab/restic
Merge pull request #2602 from greatroar/no-bufpool
Remove sync.Pool from internal/repository
This commit is contained in:
commit
c50f91b7f9
3 changed files with 3 additions and 26 deletions
|
@ -1,21 +0,0 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/restic/chunker"
|
||||
)
|
||||
|
||||
var bufPool = sync.Pool{
|
||||
New: func() interface{} {
|
||||
return make([]byte, chunker.MaxSize/3)
|
||||
},
|
||||
}
|
||||
|
||||
func getBuf() []byte {
|
||||
return bufPool.Get().([]byte)
|
||||
}
|
||||
|
||||
func freeBuf(data []byte) {
|
||||
bufPool.Put(data)
|
||||
}
|
|
@ -225,13 +225,10 @@ func (r *Repository) SaveAndEncrypt(ctx context.Context, t restic.BlobType, data
|
|||
|
||||
debug.Log("save id %v (%v, %d bytes)", id, t, len(data))
|
||||
|
||||
// get buf from the pool
|
||||
ciphertext := getBuf()
|
||||
|
||||
ciphertext = ciphertext[:0]
|
||||
nonce := crypto.NewRandomNonce()
|
||||
|
||||
ciphertext := make([]byte, 0, restic.CiphertextLength(len(data)))
|
||||
ciphertext = append(ciphertext, nonce...)
|
||||
defer freeBuf(ciphertext)
|
||||
|
||||
// encrypt blob
|
||||
ciphertext = r.key.Seal(ciphertext, nonce, data, nil)
|
||||
|
|
|
@ -104,6 +104,7 @@ func BenchmarkSaveAndEncrypt(t *testing.B) {
|
|||
|
||||
id := restic.ID(sha256.Sum256(data))
|
||||
|
||||
t.ReportAllocs()
|
||||
t.ResetTimer()
|
||||
t.SetBytes(int64(size))
|
||||
|
||||
|
|
Loading…
Reference in a new issue