Skip to content

Commit

Permalink
Merge pull request #1700 from owncloud/preallocate-slices
Browse files Browse the repository at this point in the history
pre allocate slices
  • Loading branch information
butonic authored Feb 23, 2021
2 parents cf53115 + 1088faf commit 52ebb7c
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions glauth/pkg/server/glauth/ocis.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func attribute(name string, values ...string) *ldap.EntryAttribute {
}

func (h ocisHandler) mapAccounts(accounts []*accounts.Account) []*ldap.Entry {
var entries []*ldap.Entry
entries := make([]*ldap.Entry, 0, len(accounts))
for i := range accounts {
attrs := []*ldap.EntryAttribute{
attribute("objectClass", "posixAccount", "inetOrgPerson", "organizationalPerson", "Person", "top"),
Expand Down Expand Up @@ -314,7 +314,7 @@ func (h ocisHandler) mapAccounts(accounts []*accounts.Account) []*ldap.Entry {
}

func (h ocisHandler) mapGroups(groups []*accounts.Group) []*ldap.Entry {
var entries []*ldap.Entry
entries := make([]*ldap.Entry, 0, len(groups))
for i := range groups {
attrs := []*ldap.EntryAttribute{
attribute("objectClass", "posixGroup", "groupOfNames", "top"),
Expand Down
2 changes: 1 addition & 1 deletion graph/pkg/service/v0/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (g Graph) GetGroups(w http.ResponseWriter, r *http.Request) {
return
}

var groups []*msgraph.Group
groups := make([]*msgraph.Group, 0, len(result.Entries))

for _, group := range result.Entries {
groups = append(
Expand Down
2 changes: 1 addition & 1 deletion graph/pkg/service/v0/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (g Graph) GetUsers(w http.ResponseWriter, r *http.Request) {
return
}

var users []*msgraph.User
users := make([]*msgraph.User, 0, len(result.Entries))

for _, user := range result.Entries {
users = append(
Expand Down
2 changes: 1 addition & 1 deletion ocis-pkg/conversions/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

// StringToSliceString splits a string into a slice string according to separator
func StringToSliceString(src string, sep string) []string {
var parts []string
parsed := strings.Split(src, sep)
parts := make([]string, 0, len(parsed))
for _, v := range parsed {
parts = append(parts, strings.TrimSpace(v))
}
Expand Down
2 changes: 1 addition & 1 deletion ocis-pkg/conversions/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestStringToSliceString(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
s := StringToSliceString(tt.input, tt.separator)
for i, v := range tt.out {
if tt.out[i] != v {
if s[i] != v {
t.Errorf("got %q, want %q", s, tt.out)
}
}
Expand Down
2 changes: 1 addition & 1 deletion ocis-pkg/indexer/index/disk/non_unique.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (idx *NonUnique) Lookup(v string) ([]string, error) {
return []string{}, err
}

var ids []string = nil
ids := make([]string, 0, len(fi))
for _, f := range fi {
ids = append(ids, f.Name())
}
Expand Down
2 changes: 1 addition & 1 deletion thumbnails/pkg/thumbnail/resolutions.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Resolutions []image.Rectangle

// ParseResolutions creates an instance of Resolutions from resolution strings.
func ParseResolutions(strs []string) (Resolutions, error) {
var rs Resolutions
rs := make(Resolutions, 0, len(strs))
for _, s := range strs {
r, err := ParseResolution(s)
if err != nil {
Expand Down

0 comments on commit 52ebb7c

Please sign in to comment.