Merge pull request #1700 from owncloud/preallocate-slices

pre allocate slices
This commit is contained in:
Jörn Friedrich Dreyer authored and GitHub committed 2021-02-23 09:55:52 +01:00
commit 52ebb7c611
7 files changed
+8 -8

No files matched your search

+2 -2
View File
@@ -275,7 +275,7 @@ func attribute(name string, values ...string) *ldap.EntryAttribute {
} }
func (h ocisHandler) mapAccounts(accounts []*accounts.Account) []*ldap.Entry { func (h ocisHandler) mapAccounts(accounts []*accounts.Account) []*ldap.Entry {
var entries []*ldap.Entry entries := make([]*ldap.Entry, 0, len(accounts))
for i := range accounts { for i := range accounts {
attrs := []*ldap.EntryAttribute{ attrs := []*ldap.EntryAttribute{
attribute("objectClass", "posixAccount", "inetOrgPerson", "organizationalPerson", "Person", "top"), attribute("objectClass", "posixAccount", "inetOrgPerson", "organizationalPerson", "Person", "top"),
@@ -314,7 +314,7 @@ func (h ocisHandler) mapAccounts(accounts []*accounts.Account) []*ldap.Entry {
} }
func (h ocisHandler) mapGroups(groups []*accounts.Group) []*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 { for i := range groups {
attrs := []*ldap.EntryAttribute{ attrs := []*ldap.EntryAttribute{
attribute("objectClass", "posixGroup", "groupOfNames", "top"), attribute("objectClass", "posixGroup", "groupOfNames", "top"),
+1 -1
View File
@@ -53,7 +53,7 @@ func (g Graph) GetGroups(w http.ResponseWriter, r *http.Request) {
return return
} }
var groups []*msgraph.Group groups := make([]*msgraph.Group, 0, len(result.Entries))
for _, group := range result.Entries { for _, group := range result.Entries {
groups = append( groups = append(
+1 -1
View File
@@ -76,7 +76,7 @@ func (g Graph) GetUsers(w http.ResponseWriter, r *http.Request) {
return return
} }
var users []*msgraph.User users := make([]*msgraph.User, 0, len(result.Entries))
for _, user := range result.Entries { for _, user := range result.Entries {
users = append( users = append(
+1 -1
View File
@@ -7,8 +7,8 @@ import (
// StringToSliceString splits a string into a slice string according to separator // StringToSliceString splits a string into a slice string according to separator
func StringToSliceString(src string, sep string) []string { func StringToSliceString(src string, sep string) []string {
var parts []string
parsed := strings.Split(src, sep) parsed := strings.Split(src, sep)
parts := make([]string, 0, len(parsed))
for _, v := range parsed { for _, v := range parsed {
parts = append(parts, strings.TrimSpace(v)) parts = append(parts, strings.TrimSpace(v))
} }
+1 -1
View File
@@ -26,7 +26,7 @@ func TestStringToSliceString(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
s := StringToSliceString(tt.input, tt.separator) s := StringToSliceString(tt.input, tt.separator)
for i, v := range tt.out { for i, v := range tt.out {
if tt.out[i] != v { if s[i] != v {
t.Errorf("got %q, want %q", s, tt.out) t.Errorf("got %q, want %q", s, tt.out)
} }
} }
+1 -1
View File
@@ -83,7 +83,7 @@ func (idx *NonUnique) Lookup(v string) ([]string, error) {
return []string{}, err return []string{}, err
} }
var ids []string = nil ids := make([]string, 0, len(fi))
for _, f := range fi { for _, f := range fi {
ids = append(ids, f.Name()) ids = append(ids, f.Name())
} }
+1 -1
View File
@@ -36,7 +36,7 @@ type Resolutions []image.Rectangle
// ParseResolutions creates an instance of Resolutions from resolution strings. // ParseResolutions creates an instance of Resolutions from resolution strings.
func ParseResolutions(strs []string) (Resolutions, error) { func ParseResolutions(strs []string) (Resolutions, error) {
var rs Resolutions rs := make(Resolutions, 0, len(strs))
for _, s := range strs { for _, s := range strs {
r, err := ParseResolution(s) r, err := ParseResolution(s)
if err != nil { if err != nil {