chore(perf): Pre-allocate where possible (enable prealloc linter) (#88952)

* chore(perf): Pre-allocate where possible (enable prealloc linter)

Signed-off-by: Dave Henderson <dave.henderson@grafana.com>

* fix TestAlertManagers_buildRedactedAMs

Signed-off-by: Dave Henderson <dave.henderson@grafana.com>

* prealloc a slice that appeared after rebase

Signed-off-by: Dave Henderson <dave.henderson@grafana.com>

---------

Signed-off-by: Dave Henderson <dave.henderson@grafana.com>
This commit is contained in:
Dave Henderson
2024-06-14 14:16:36 -04:00
committed by GitHub
parent e53e6e7caa
commit 6262c56132
43 changed files with 211 additions and 140 deletions
+5 -3
View File
@@ -48,11 +48,13 @@ func SplitString(str string) []string {
return res
}
var result []string
matches := stringListItemMatcher.FindAllString(str, -1)
for _, match := range matches {
result = append(result, strings.Trim(match, "\""))
result := make([]string, len(matches))
for i, match := range matches {
result[i] = strings.Trim(match, "\"")
}
return result
}
+7 -3
View File
@@ -30,22 +30,26 @@ func TlsCiphersToIDs(names []string) ([]uint16, error) {
// no ciphers specified, use defaults
return nil, nil
}
var ids []uint16
var missing []string
ciphers := tls.CipherSuites()
var cipherMap = make(map[string]uint16, len(ciphers))
cipherMap := make(map[string]uint16, len(ciphers))
for _, cipher := range ciphers {
cipherMap[cipher.Name] = cipher.ID
}
missing := []string{}
ids := make([]uint16, 0, len(names))
for _, name := range names {
name = strings.ToUpper(name)
id, ok := cipherMap[name]
if !ok {
missing = append(missing, name)
continue
}
ids = append(ids, id)
}