mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 10:58:55 +00:00
repository: Improve buffer pooling
This commit is contained in:
parent
4c00efd4bf
commit
a56b8fad87
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
var bufPool = sync.Pool{
|
var bufPool = sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() interface{} {
|
||||||
return make([]byte, chunker.MinSize)
|
return make([]byte, chunker.MaxSize/3)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,11 +214,11 @@ func (r *Repository) SaveAndEncrypt(ctx context.Context, t restic.BlobType, data
|
|||||||
|
|
||||||
// get buf from the pool
|
// get buf from the pool
|
||||||
ciphertext := getBuf()
|
ciphertext := getBuf()
|
||||||
defer freeBuf(ciphertext)
|
|
||||||
|
|
||||||
ciphertext = ciphertext[:0]
|
ciphertext = ciphertext[:0]
|
||||||
nonce := crypto.NewRandomNonce()
|
nonce := crypto.NewRandomNonce()
|
||||||
ciphertext = append(ciphertext, nonce...)
|
ciphertext = append(ciphertext, nonce...)
|
||||||
|
defer freeBuf(ciphertext)
|
||||||
|
|
||||||
// encrypt blob
|
// encrypt blob
|
||||||
ciphertext = r.key.Seal(ciphertext, nonce, data, nil)
|
ciphertext = r.key.Seal(ciphertext, nonce, data, nil)
|
||||||
|
Loading…
Reference in New Issue
Block a user