mirror of
https://github.com/restic/restic.git
synced 2025-11-15 13:44:42 +00:00
Simplify sortCachedPacksFirst test in internal/repository
The test now uses the fact that the sort is stable. It's not guaranteed to be, but the test is cleaner and more exhaustive. sortCachedPacksFirst no longer needs a return value.
This commit is contained in:
committed by
Michael Eischer
parent
03d23e6faa
commit
309598c237
@@ -116,15 +116,14 @@ type haver interface {
|
||||
}
|
||||
|
||||
// sortCachedPacksFirst moves all cached pack files to the front of blobs.
|
||||
// It overwrites blobs.
|
||||
func sortCachedPacksFirst(cache haver, blobs []restic.PackedBlob) []restic.PackedBlob {
|
||||
func sortCachedPacksFirst(cache haver, blobs []restic.PackedBlob) {
|
||||
if cache == nil {
|
||||
return blobs
|
||||
return
|
||||
}
|
||||
|
||||
// no need to sort a list with one element
|
||||
if len(blobs) == 1 {
|
||||
return blobs
|
||||
return
|
||||
}
|
||||
|
||||
cached := blobs[:0]
|
||||
@@ -138,7 +137,7 @@ func sortCachedPacksFirst(cache haver, blobs []restic.PackedBlob) []restic.Packe
|
||||
noncached = append(noncached, blob)
|
||||
}
|
||||
|
||||
return append(cached, noncached...)
|
||||
copy(blobs[len(cached):], noncached)
|
||||
}
|
||||
|
||||
// LoadBlob loads a blob of type t from the repository.
|
||||
@@ -154,7 +153,7 @@ func (r *Repository) LoadBlob(ctx context.Context, t restic.BlobType, id restic.
|
||||
}
|
||||
|
||||
// try cached pack files first
|
||||
blobs = sortCachedPacksFirst(r.Cache, blobs)
|
||||
sortCachedPacksFirst(r.Cache, blobs)
|
||||
|
||||
var lastError error
|
||||
for _, blob := range blobs {
|
||||
|
||||
Reference in New Issue
Block a user