agent: add len, cap while initializing arrays

pull/7565/head
Emre Savcı 2020-04-01 11:54:51 +03:00 committed by GitHub
parent 4d35816bee
commit 2083b7b04d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -1793,7 +1793,7 @@ func sanitize(name string, v reflect.Value) reflect.Value {
return reflect.ValueOf(m) return reflect.ValueOf(m)
case isArray(typ) || isSlice(typ): case isArray(typ) || isSlice(typ):
ma := make([]interface{}, 0) ma := make([]interface{}, 0, v.Len())
for i := 0; i < v.Len(); i++ { for i := 0; i < v.Len(); i++ {
ma = append(ma, sanitize(fmt.Sprintf("%s[%d]", name, i), v.Index(i)).Interface()) ma = append(ma, sanitize(fmt.Sprintf("%s[%d]", name, i), v.Index(i)).Interface())
} }

View File

@ -739,7 +739,7 @@ func (s *Store) Services(ws memdb.WatchSet, entMeta *structs.EnterpriseMeta) (ui
// Generate the output structure. // Generate the output structure.
var results = make(structs.Services) var results = make(structs.Services)
for service, tags := range unique { for service, tags := range unique {
results[service] = make([]string, 0) results[service] = make([]string, 0, len(tags))
for tag := range tags { for tag := range tags {
results[service] = append(results[service], tag) results[service] = append(results[service], tag)
} }
@ -837,7 +837,7 @@ func (s *Store) ServicesByNodeMeta(ws memdb.WatchSet, filters map[string]string,
// Generate the output structure. // Generate the output structure.
var results = make(structs.Services) var results = make(structs.Services)
for service, tags := range unique { for service, tags := range unique {
results[service] = make([]string, 0) results[service] = make([]string, 0, len(tags))
for tag := range tags { for tag := range tags {
results[service] = append(results[service], tag) results[service] = append(results[service], tag)
} }