Skip to content

Commit

Permalink
Remove unnecessary memory allocation (#11)
Browse files Browse the repository at this point in the history
Creating a 0 length slice is less efficient than a nil slice pointer.
  • Loading branch information
maruel authored Sep 19, 2024
1 parent 804146f commit 14fd0ac
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ func (h *FanoutHandler) Enabled(ctx context.Context, l slog.Level) bool {

// Implements slog.Handler
func (h *FanoutHandler) Handle(ctx context.Context, r slog.Record) error {
// We initialize this with a capacity of 0 to optimize for the path where there are no errors
errs := make([]error, 0, 0)
var errs []error
for i := range h.handlers {
if h.handlers[i].Enabled(ctx, r.Level) {
err := try(func() error {
Expand Down

0 comments on commit 14fd0ac

Please sign in to comment.