From 367449dede18a74d52cdf97c3c755c7d422caccc Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Tue, 31 Mar 2020 14:58:48 +0200 Subject: [PATCH] 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. --- internal/repository/repack.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/repository/repack.go b/internal/repository/repack.go index 1d8426e48..1a579d00b 100644 --- a/internal/repository/repack.go +++ b/internal/repository/repack.go @@ -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]