1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-02-09 13:37:12 +02:00

Improve memory allocation while parsing tags

This commit is contained in:
Sam Xie 2020-06-08 10:45:48 +08:00
parent e2ab0e0b98
commit a242bd7df2

View File

@ -103,8 +103,8 @@ func WithProcessFromEnv() Option {
// is an environment variable and `defaultValue` is the value to use in case the env var is not set // is an environment variable and `defaultValue` is the value to use in case the env var is not set
func parseTags(sTags string) []kv.KeyValue { func parseTags(sTags string) []kv.KeyValue {
pairs := strings.Split(sTags, ",") pairs := strings.Split(sTags, ",")
tags := make([]kv.KeyValue, 0) tags := make([]kv.KeyValue, len(pairs))
for _, p := range pairs { for i, p := range pairs {
field := strings.SplitN(p, "=", 2) field := strings.SplitN(p, "=", 2)
k, v := strings.TrimSpace(field[0]), strings.TrimSpace(field[1]) k, v := strings.TrimSpace(field[0]), strings.TrimSpace(field[1])
@ -117,7 +117,7 @@ func parseTags(sTags string) []kv.KeyValue {
} }
} }
tags = append(tags, parseKeyValue(k, v)) tags[i] = parseKeyValue(k, v)
} }
return tags return tags