From de66483ba1d472dc40775856e92fecf46ab5c89e Mon Sep 17 00:00:00 2001 From: Andrzej Stencel Date: Mon, 16 Dec 2024 13:40:42 +0100 Subject: [PATCH] perf: inline `convertToken` function --- pkg/stanza/operator/input/file/input.go | 27 ++++++++++--------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/pkg/stanza/operator/input/file/input.go b/pkg/stanza/operator/input/file/input.go index 03ec5ccb3e52..55727f918ba7 100644 --- a/pkg/stanza/operator/input/file/input.go +++ b/pkg/stanza/operator/input/file/input.go @@ -55,30 +55,25 @@ func (i *Input) emitBatch(ctx context.Context, tokens []emit.Token) error { func (i *Input) convertTokens(tokens []emit.Token) ([]*entry.Entry, error) { entries := make([]*entry.Entry, 0, len(tokens)) var errs []error + for _, token := range tokens { if len(token.Body) == 0 { continue } - entry, err := i.convertToken(token) + + ent, err := i.NewEntry(i.toBody(token.Body)) if err != nil { - errs = append(errs, err) + errs = append(errs, fmt.Errorf("create entry: %w", err)) continue } - entries = append(entries, entry) - } - return entries, errors.Join(errs...) -} -func (i *Input) convertToken(token emit.Token) (*entry.Entry, error) { - ent, err := i.NewEntry(i.toBody(token.Body)) - if err != nil { - return nil, fmt.Errorf("create entry: %w", err) - } - - for k, v := range token.Attributes { - if err := ent.Set(entry.NewAttributeField(k), v); err != nil { - i.Logger().Error("set attribute", zap.Error(err)) + for k, v := range token.Attributes { + if err := ent.Set(entry.NewAttributeField(k), v); err != nil { + i.Logger().Error("set attribute", zap.Error(err)) + } } + + entries = append(entries, ent) } - return ent, nil + return entries, errors.Join(errs...) }