From e6fb89c8e842fdd63ab627573a084c171b7afd94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zapletal?= Date: Wed, 18 Dec 2024 10:51:43 +0100 Subject: [PATCH] Optimize allocation in AppendRecordAttrsToAttrs (#18) --- attributes.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/attributes.go b/attributes.go index 62d907a..ceb357b 100644 --- a/attributes.go +++ b/attributes.go @@ -17,7 +17,8 @@ import ( type ReplaceAttrFn = func(groups []string, a slog.Attr) slog.Attr func AppendRecordAttrsToAttrs(attrs []slog.Attr, groups []string, record *slog.Record) []slog.Attr { - output := slices.Clone(attrs) + output := make([]slog.Attr, 0, len(attrs)+record.NumAttrs()) + output = append(output, attrs...) slices.Reverse(groups) record.Attrs(func(attr slog.Attr) bool {