prune: Reduce memory allocations while repacking

The slicing operator `slice[low:high]` default to 0 for the lower bound and
len(slice) for the upper bound when either or both are not specified.
Fix the code to use `cap(slice)` to check for the slice capacity.
This commit is contained in:
Michael Eischer 2020-03-31 14:58:48 +02:00
parent 7042bafea5
commit 367449dede

View file

@ -57,8 +57,7 @@ func Repack(ctx context.Context, repo restic.Repository, packs restic.IDSet, kee
debug.Log(" process blob %v", h)
buf = buf[:]
if uint(len(buf)) < entry.Length {
if uint(cap(buf)) < entry.Length {
buf = make([]byte, entry.Length)
}
buf = buf[:entry.Length]