mirror of
https://github.com/status-im/consul.git
synced 2025-01-22 11:40:06 +00:00
agent: add len, cap while initializing arrays
This commit is contained in:
parent
4d35816bee
commit
2083b7b04d
@ -1793,7 +1793,7 @@ func sanitize(name string, v reflect.Value) reflect.Value {
|
||||
return reflect.ValueOf(m)
|
||||
|
||||
case isArray(typ) || isSlice(typ):
|
||||
ma := make([]interface{}, 0)
|
||||
ma := make([]interface{}, 0, v.Len())
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
ma = append(ma, sanitize(fmt.Sprintf("%s[%d]", name, i), v.Index(i)).Interface())
|
||||
}
|
||||
|
@ -739,7 +739,7 @@ func (s *Store) Services(ws memdb.WatchSet, entMeta *structs.EnterpriseMeta) (ui
|
||||
// Generate the output structure.
|
||||
var results = make(structs.Services)
|
||||
for service, tags := range unique {
|
||||
results[service] = make([]string, 0)
|
||||
results[service] = make([]string, 0, len(tags))
|
||||
for tag := range tags {
|
||||
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.
|
||||
var results = make(structs.Services)
|
||||
for service, tags := range unique {
|
||||
results[service] = make([]string, 0)
|
||||
results[service] = make([]string, 0, len(tags))
|
||||
for tag := range tags {
|
||||
results[service] = append(results[service], tag)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user