mirror of
https://github.com/restic/restic.git
synced 2025-08-12 17:18:05 +00:00
FindUsedBlobs: merge seen into blobs BlobSet
The seen BlobSet always contained a subset of the entries in blobs. Thus use blobs instead and avoid the memory overhead of the second set. Suggested-by: Alexander Weiss <alex@weissfam.de>
This commit is contained in:
@@ -3,9 +3,8 @@ package restic
|
||||
import "context"
|
||||
|
||||
// FindUsedBlobs traverses the tree ID and adds all seen blobs (trees and data
|
||||
// blobs) to the set blobs. The tree blobs in the `seen` BlobSet will not be visited
|
||||
// again.
|
||||
func FindUsedBlobs(ctx context.Context, repo Repository, treeID ID, blobs BlobSet, seen BlobSet) error {
|
||||
// blobs) to the set blobs. Already seen tree blobs will not be visited again.
|
||||
func FindUsedBlobs(ctx context.Context, repo Repository, treeID ID, blobs BlobSet) error {
|
||||
blobs.Insert(BlobHandle{ID: treeID, Type: TreeBlob})
|
||||
|
||||
tree, err := repo.LoadTree(ctx, treeID)
|
||||
@@ -22,13 +21,11 @@ func FindUsedBlobs(ctx context.Context, repo Repository, treeID ID, blobs BlobSe
|
||||
case "dir":
|
||||
subtreeID := *node.Subtree
|
||||
h := BlobHandle{ID: subtreeID, Type: TreeBlob}
|
||||
if seen.Has(h) {
|
||||
if blobs.Has(h) {
|
||||
continue
|
||||
}
|
||||
|
||||
seen.Insert(h)
|
||||
|
||||
err := FindUsedBlobs(ctx, repo, subtreeID, blobs, seen)
|
||||
err := FindUsedBlobs(ctx, repo, subtreeID, blobs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -93,7 +93,7 @@ func TestFindUsedBlobs(t *testing.T) {
|
||||
|
||||
for i, sn := range snapshots {
|
||||
usedBlobs := restic.NewBlobSet()
|
||||
err := restic.FindUsedBlobs(context.TODO(), repo, *sn.Tree, usedBlobs, restic.NewBlobSet())
|
||||
err := restic.FindUsedBlobs(context.TODO(), repo, *sn.Tree, usedBlobs)
|
||||
if err != nil {
|
||||
t.Errorf("FindUsedBlobs returned error: %v", err)
|
||||
continue
|
||||
@@ -127,9 +127,8 @@ func BenchmarkFindUsedBlobs(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
seen := restic.NewBlobSet()
|
||||
blobs := restic.NewBlobSet()
|
||||
err := restic.FindUsedBlobs(context.TODO(), repo, *sn.Tree, blobs, seen)
|
||||
err := restic.FindUsedBlobs(context.TODO(), repo, *sn.Tree, blobs)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user