Perfomance: Preallocate slices (#61580)

This commit is contained in:
Denis Limarev
2023-01-17 11:50:17 +00:00
committed by GitHub
parent d2a5b9b289
commit e6dee8a723
13 changed files with 20 additions and 17 deletions
@@ -403,7 +403,7 @@ func (am *Alertmanager) buildIntegrationsMap(receivers []*apimodels.PostableApiR
// buildReceiverIntegrations builds a list of integration notifiers off of a receiver config.
func (am *Alertmanager) buildReceiverIntegrations(receiver *apimodels.PostableApiReceiver, tmpl *alerting.Template) ([]*alerting.Integration, error) {
var integrations []*alerting.Integration
integrations := make([]*alerting.Integration, 0, len(receiver.GrafanaManagedReceivers))
for i, r := range receiver.GrafanaManagedReceivers {
n, err := am.buildReceiverIntegration(r, tmpl)
if err != nil {
+1 -1
View File
@@ -130,7 +130,7 @@ func (am *Alertmanager) GetReceivers(ctx context.Context) []apimodels.Receiver {
am.reloadConfigMtx.RLock()
defer am.reloadConfigMtx.RUnlock()
var apiReceivers []apimodels.Receiver
apiReceivers := make([]apimodels.Receiver, 0, len(am.Base.GetReceivers()))
for _, rcv := range am.Base.GetReceivers() {
// Build integrations slice for each receiver.
integrations := make([]*models.Integration, 0, len(rcv.Integrations()))