mirror of
https://github.com/octoleo/restic.git
synced 2025-01-22 22:58:26 +00:00
repository: Reduce buffer reallocations in ForAllIndexes
Previously the buffer was grown incrementally inside `repo.LoadUnpacked`. But we can do better as we already know how large the index will be. Allocate a bit more memory to increase the chance that the buffer can be reused in the future.
This commit is contained in:
parent
77b1980d8e
commit
7a992fc794
@ -52,6 +52,10 @@ func ForAllIndexes(ctx context.Context, repo restic.Repository,
|
||||
var idx *Index
|
||||
oldFormat := false
|
||||
|
||||
if cap(buf) < int(fi.Size) {
|
||||
// overallocate a bit
|
||||
buf = make([]byte, fi.Size+128*1024)
|
||||
}
|
||||
buf, err = repo.LoadUnpacked(ctx, restic.IndexFile, fi.ID, buf[:0])
|
||||
if err == nil {
|
||||
idx, oldFormat, err = DecodeIndex(buf, fi.ID)
|
||||
|
Loading…
x
Reference in New Issue
Block a user