Skip to content

Commit

Permalink
Optimize allocation in AppendRecordAttrsToAttrs (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzap authored Dec 18, 2024
1 parent 7caeb0b commit e6fb89c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e6fb89c

Please sign in to comment.