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.
This commit is contained in:
Michael Eischer 2019-07-06 17:42:29 +02:00
parent a307797c11
commit b46cc6d57e
1 changed files with 5 additions and 0 deletions

View File

@ -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)