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:
+5
-3
@@ -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
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user