Skip to content

Commit 7526d59

Browse files
committed
[cache] Use slice.ContainsFunc
cleaner than a basic for loop Signed-off-by: Baptiste Girard-Carrabin <[email protected]>
1 parent 622757e commit 7526d59

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

cache/remote.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,11 @@ func getAvailableBlobs(ctx context.Context, cs content.Store, chain *solver.Remo
119119
// Looping over the list is preferable:
120120
// 1. to avoid using a map, which don't preserve the order of descriptors,
121121
// 2. descs will have a length the number of compression variants for a blob, which is usually very small
122-
for _, d := range descs {
123-
if d.Digest == desc.Digest {
124-
return true // already seen this descriptor
125-
}
122+
if !slices.ContainsFunc(descs, func(d ocispecs.Descriptor) bool {
123+
return d.Digest == desc.Digest
124+
}) {
125+
descs = append(descs, desc)
126126
}
127-
descs = append(descs, desc)
128127
return true
129128
}); err != nil {
130129
bklog.G(ctx).WithError(err).Warn("failed to walk variant blob") // is not a critical error at this moment.

0 commit comments

Comments
 (0)