Merge pull request #1665 from jkroepke/BuildFQName

Optimize BuildFQName function
This commit is contained in:
Bartlomiej Plotka 2024-11-01 20:13:02 +01:00 committed by GitHub
commit d3f28401b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 8 deletions

View File

@ -108,15 +108,23 @@ func BuildFQName(namespace, subsystem, name string) string {
if name == "" { if name == "" {
return "" return ""
} }
switch {
case namespace != "" && subsystem != "": sb := strings.Builder{}
return strings.Join([]string{namespace, subsystem, name}, "_") sb.Grow(len(namespace) + len(subsystem) + len(name) + 2)
case namespace != "":
return strings.Join([]string{namespace, name}, "_") if namespace != "" {
case subsystem != "": sb.WriteString(namespace)
return strings.Join([]string{subsystem, name}, "_") sb.WriteString("_")
} }
return name
if subsystem != "" {
sb.WriteString(subsystem)
sb.WriteString("_")
}
sb.WriteString(name)
return sb.String()
} }
type invalidMetric struct { type invalidMetric struct {