Performance optimization (#1481)

There are redundant steps
This commit is contained in:
assassins 2021-07-29 00:26:20 +08:00 committed by GitHub
parent e20ec090b2
commit a483044557
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -90,13 +90,13 @@ func templateAnnotations(annotations map[string]string, data AlertTplData, funcs
eg := new(utils.ErrGroup)
r := make(map[string]string, len(annotations))
for key, text := range annotations {
r[key] = text
buf.Reset()
builder.Reset()
builder.Grow(len(tplHeader) + len(text))
builder.WriteString(tplHeader)
builder.WriteString(text)
if err := templateAnnotation(&buf, builder.String(), data, funcs); err != nil {
r[key] = text
eg.Add(fmt.Errorf("key %q, template %q: %w", key, text, err))
continue
}