From c220710fc5a66140e40b7d36d4952548253883a1 Mon Sep 17 00:00:00 2001 From: apocelipes Date: Fri, 3 Jan 2025 03:45:09 +0800 Subject: [PATCH] Prealloc msgs in multierr.Error (#1209) "msgs"'s length is known, preallocate it can save memories. Co-authored-by: Chris Roche --- templates/goshared/msg.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/goshared/msg.go b/templates/goshared/msg.go index 98657f495..f3030da12 100644 --- a/templates/goshared/msg.go +++ b/templates/goshared/msg.go @@ -95,7 +95,7 @@ type {{ multierrname . }} []error // Error returns a concatenation of all the error messages it wraps. func (m {{ multierrname . }}) Error() string { - var msgs []string + msgs := make([]string, 0, len(m)) for _, err := range m { msgs = append(msgs, err.Error()) }