Skip to content

Commit

Permalink
perf: use slices.Sort instead of sort.Strings
Browse files Browse the repository at this point in the history
Signed-off-by: Shiwei Zhang <shizh@microsoft.com>
  • Loading branch information
shizhMSFT committed Mar 19, 2024
1 parent 8cbf8dd commit a1d93c0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion content/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (s *Store) Tags(ctx context.Context, last string, fn func(tags []string) er
s.sync.RLock()
defer s.sync.RUnlock()

return listTags(ctx, s.tagResolver, last, fn)
return listTags(s.tagResolver, last, fn)
}

// ensureOCILayoutFile ensures the `oci-layout` file.
Expand Down
8 changes: 4 additions & 4 deletions content/oci/readonlyoci.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"fmt"
"io"
"io/fs"
"sort"
"slices"

"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
Expand Down Expand Up @@ -125,7 +125,7 @@ func (s *ReadOnlyStore) Predecessors(ctx context.Context, node ocispec.Descripto
//
// See also `Tags()` in the package `registry`.
func (s *ReadOnlyStore) Tags(ctx context.Context, last string, fn func(tags []string) error) error {
return listTags(ctx, s.tagResolver, last, fn)
return listTags(s.tagResolver, last, fn)
}

// validateOCILayoutFile validates the `oci-layout` file.
Expand Down Expand Up @@ -216,7 +216,7 @@ func resolveBlob(fsys fs.FS, dgst string) (ocispec.Descriptor, error) {
// list.
//
// See also `Tags()` in the package `registry`.
func listTags(ctx context.Context, tagResolver *resolver.Memory, last string, fn func(tags []string) error) error {
func listTags(tagResolver *resolver.Memory, last string, fn func(tags []string) error) error {
var tags []string

tagMap := tagResolver.Map()
Expand All @@ -229,7 +229,7 @@ func listTags(ctx context.Context, tagResolver *resolver.Memory, last string, fn
}
tags = append(tags, tag)
}
sort.Strings(tags)
slices.Sort(tags)

return fn(tags)
}
Expand Down
7 changes: 3 additions & 4 deletions registry/remote/auth/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package auth
import (
"context"
"slices"
"sort"
"strings"

"oras.land/oras-go/v2/registry"
Expand Down Expand Up @@ -276,14 +275,14 @@ func CleanScopes(scopes []string) []string {
}
actions = append(actions, action)
}
sort.Strings(actions)
slices.Sort(actions)
scope := resourceType + ":" + resourceName + ":" + strings.Join(actions, ",")
result = append(result, scope)
}
}

// sort and return
sort.Strings(result)
slices.Sort(result)
return result
}

Expand All @@ -302,7 +301,7 @@ func cleanActions(actions []string) []string {
}

// slow path
sort.Strings(actions)
slices.Sort(actions)
n := 0
for i := 0; i < len(actions); i++ {
if actions[i] == "*" {
Expand Down

0 comments on commit a1d93c0

Please sign in to comment.