From b46cc6d57e61de1a5e4096dcc3496065c3c8d3cd Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 6 Jul 2019 17:42:29 +0200 Subject: [PATCH] repository: Don't sort one element pack lists When loading a blob, restic first looks up pack files containing the blob. To avoid unnecessary work an already cached pack file is preferred. However, if there is only a single pack file to choose from (which is the normal case) sorting the one-element list won't change anything. Therefore avoid the unnecessary cache check in that case. --- internal/repository/repository.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/repository/repository.go b/internal/repository/repository.go index 3457f54d6..e39e728c7 100644 --- a/internal/repository/repository.go +++ b/internal/repository/repository.go @@ -111,6 +111,11 @@ func (r *Repository) sortCachedPacks(blobs []restic.PackedBlob) []restic.PackedB return blobs } + // no need to sort a list with one element + if len(blobs) == 1 { + return blobs + } + cached := make([]restic.PackedBlob, 0, len(blobs)/2) noncached := make([]restic.PackedBlob, 0, len(blobs)/2)