chore: preallocate slices where we have a good idea of requirements (#91596)

* chore: preallocate slices where we have a good idea of requirements

* pr feedback
This commit is contained in:
Kristin Laemmert 2024-08-07 08:34:52 -04:00 committed by GitHub
parent 9b652612bd
commit a117b090cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 6 additions and 6 deletions

View File

@ -540,7 +540,7 @@ func postPath(pre string, v config.AlertmanagerAPIVersion) string {
// AlertmanagerFromGroup extracts a list of alertmanagers from a target group
// and an associated AlertmanagerConfig.
func AlertmanagerFromGroup(tg *targetgroup.Group, cfg *config.AlertmanagerConfig) ([]alertmanager, []alertmanager, error) {
var res []alertmanager
res := make([]alertmanager, 0, len(tg.Targets))
var droppedAlertManagers []alertmanager
for _, tlset := range tg.Targets {

View File

@ -1096,10 +1096,10 @@ func (db *postgres) GetTables() ([]*core.Table, error) {
}
func getIndexColName(indexdef string) []string {
var colNames []string
cs := strings.Split(indexdef, "(")
for _, v := range strings.Split(strings.Split(cs[1], ")")[0], ",") {
splitNames := strings.Split(strings.Split(cs[1], ")")[0], ",")
colNames := make([]string, 0, len(splitNames))
for _, v := range splitNames {
colNames = append(colNames, strings.Split(strings.TrimLeft(v, " "), " ")[0])
}

View File

@ -191,7 +191,7 @@ func eraseAny(value string, strToErase ...string) string {
if len(strToErase) == 0 {
return value
}
var replaceSeq []string
replaceSeq := make([]string, 0, len(strToErase)*2)
for _, s := range strToErase {
replaceSeq = append(replaceSeq, s, "")
}

View File

@ -866,7 +866,7 @@ func (statement *Statement) genUniqueSQL() []string {
}
func (statement *Statement) genDelIndexSQL() []string {
var sqls []string
sqls := make([]string, 0, len(statement.RefTable.Indexes))
tbName := statement.TableName()
idxPrefixName := strings.Replace(tbName, `"`, "", -1)
idxPrefixName = strings.Replace(idxPrefixName, `.`, "_", -1)