[#1239] util/attributes: Remove excessive slice copy during parsing
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
2ad8016d75
commit
6936195afa
1 changed files with 4 additions and 9 deletions
|
@ -28,7 +28,7 @@ func ParseV2Attributes(attrs []string, excl []string) ([]netmap.NodeAttribute, e
|
||||||
}
|
}
|
||||||
|
|
||||||
cache := make(map[string]*netmap.NodeAttribute, len(attrs))
|
cache := make(map[string]*netmap.NodeAttribute, len(attrs))
|
||||||
result := make([]*netmap.NodeAttribute, 0, len(attrs))
|
result := make([]netmap.NodeAttribute, 0, len(attrs))
|
||||||
|
|
||||||
for i := range attrs {
|
for i := range attrs {
|
||||||
line := strings.Trim(attrs[i], pairSeparator)
|
line := strings.Trim(attrs[i], pairSeparator)
|
||||||
|
@ -59,9 +59,9 @@ func ParseV2Attributes(attrs []string, excl []string) ([]netmap.NodeAttribute, e
|
||||||
}
|
}
|
||||||
|
|
||||||
if !present {
|
if !present {
|
||||||
attribute = netmap.NewNodeAttribute()
|
result = append(result, netmap.NodeAttribute{})
|
||||||
|
attribute = &result[len(result)-1]
|
||||||
cache[key] = attribute
|
cache[key] = attribute
|
||||||
result = append(result, attribute)
|
|
||||||
|
|
||||||
// replace non-printable symbols with escaped symbols without escape character
|
// replace non-printable symbols with escaped symbols without escape character
|
||||||
key = replaceEscaping(key, true)
|
key = replaceEscaping(key, true)
|
||||||
|
@ -82,12 +82,7 @@ func ParseV2Attributes(attrs []string, excl []string) ([]netmap.NodeAttribute, e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nresult := make([]netmap.NodeAttribute, len(result))
|
return result, nil
|
||||||
for i := range result {
|
|
||||||
nresult[i] = *result[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
return nresult, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func replaceEscaping(target string, rollback bool) (s string) {
|
func replaceEscaping(target string, rollback bool) (s string) {
|
||||||
|
|
Loading…
Reference in a new issue