diff --git a/pkg/services/ngalert/sender/notifier.go b/pkg/services/ngalert/sender/notifier.go index 22f82099e7a..0e901a8608d 100644 --- a/pkg/services/ngalert/sender/notifier.go +++ b/pkg/services/ngalert/sender/notifier.go @@ -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 { diff --git a/pkg/util/xorm/dialect_postgres.go b/pkg/util/xorm/dialect_postgres.go index e3a8e75d022..d726faacbb0 100644 --- a/pkg/util/xorm/dialect_postgres.go +++ b/pkg/util/xorm/dialect_postgres.go @@ -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]) } diff --git a/pkg/util/xorm/helpers.go b/pkg/util/xorm/helpers.go index 3c2333e4ffb..a3229c4dc12 100644 --- a/pkg/util/xorm/helpers.go +++ b/pkg/util/xorm/helpers.go @@ -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, "") } diff --git a/pkg/util/xorm/statement.go b/pkg/util/xorm/statement.go index 96c6fb681b9..e58903dea3e 100644 --- a/pkg/util/xorm/statement.go +++ b/pkg/util/xorm/statement.go @@ -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)