mirror of
https://github.com/distribution/distribution.git
synced 2025-09-24 20:46:52 +00:00
Merge pull request #4037 from milosgajdos/enable-prealloc
Enable prealloc linter
This commit is contained in:
@@ -441,6 +441,11 @@ func (app *App) register(routeName string, dispatch dispatchFunc) {
|
||||
// configureEvents prepares the event sink for action.
|
||||
func (app *App) configureEvents(configuration *configuration.Configuration) {
|
||||
// Configure all of the endpoint sinks.
|
||||
// NOTE(milosgajdos): we are disabling the linter here as
|
||||
// if an endpoint is disabled we continue with the evaluation
|
||||
// of the next one so we do not know the exact size the slice
|
||||
// should have at the time the iteration starts
|
||||
// nolint:prealloc
|
||||
var sinks []events.Sink
|
||||
for _, endpoint := range configuration.Notifications.Endpoints {
|
||||
if endpoint.Disabled {
|
||||
|
@@ -49,7 +49,7 @@ func (m *mockTagStore) All(ctx context.Context) ([]string, error) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
var tags []string
|
||||
tags := make([]string, 0, len(m.mapping))
|
||||
for tag := range m.mapping {
|
||||
tags = append(tags, tag)
|
||||
}
|
||||
|
@@ -416,7 +416,7 @@ func directDescendants(blobs []string, prefix string) []string {
|
||||
}
|
||||
}
|
||||
|
||||
var keys []string
|
||||
keys := make([]string, 0, len(out))
|
||||
for k := range out {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
|
@@ -97,8 +97,12 @@ func (d *dir) list(p string) ([]string, error) {
|
||||
return nil, errIsNotDir
|
||||
}
|
||||
|
||||
var children []string
|
||||
for _, child := range n.(*dir).children {
|
||||
// NOTE(milosgajdos): this is safe to do because
|
||||
// n can only be *dir due to the compile time check
|
||||
dirChildren := n.(*dir).children
|
||||
|
||||
children := make([]string, 0, len(dirChildren))
|
||||
for _, child := range dirChildren {
|
||||
children = append(children, child.path())
|
||||
}
|
||||
|
||||
|
@@ -1456,7 +1456,7 @@ func (w *writer) Commit() error {
|
||||
}
|
||||
w.committed = true
|
||||
|
||||
var completedUploadedParts completedParts
|
||||
completedUploadedParts := make(completedParts, 0, len(w.parts))
|
||||
for _, part := range w.parts {
|
||||
completedUploadedParts = append(completedUploadedParts, &s3.CompletedPart{
|
||||
ETag: part.ETag,
|
||||
|
@@ -500,7 +500,7 @@ func TestWalk(t *testing.T) {
|
||||
}
|
||||
|
||||
// create file structure matching fileset above
|
||||
var created []string
|
||||
created := make([]string, 0, len(fileset))
|
||||
for _, p := range fileset {
|
||||
err := drvr.PutContent(context.Background(), p, []byte("content "+p))
|
||||
if err != nil {
|
||||
|
@@ -24,25 +24,24 @@ type tagStore struct {
|
||||
|
||||
// All returns all tags
|
||||
func (ts *tagStore) All(ctx context.Context) ([]string, error) {
|
||||
var tags []string
|
||||
|
||||
pathSpec, err := pathFor(manifestTagPathSpec{
|
||||
name: ts.repository.Named().Name(),
|
||||
})
|
||||
if err != nil {
|
||||
return tags, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
entries, err := ts.blobStore.driver.List(ctx, pathSpec)
|
||||
if err != nil {
|
||||
switch err := err.(type) {
|
||||
case storagedriver.PathNotFoundError:
|
||||
return tags, distribution.ErrRepositoryUnknown{Name: ts.repository.Named().Name()}
|
||||
return nil, distribution.ErrRepositoryUnknown{Name: ts.repository.Named().Name()}
|
||||
default:
|
||||
return tags, err
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
tags := make([]string, 0, len(entries))
|
||||
for _, entry := range entries {
|
||||
_, filename := path.Split(entry)
|
||||
tags = append(tags, filename)
|
||||
|
Reference in New Issue
Block a user