Skip to content

Commit

Permalink
parse: Emit: pass a pointer to line with a request to not modify it
Browse files Browse the repository at this point in the history
  • Loading branch information
jrockway committed Jun 23, 2022
1 parent 7ed8fe3 commit 4c5aa37
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions pkg/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func ReadLog(r io.Reader, w io.Writer, ins *InputSchema, outs *OutputSchema, fil
outs.noMessage = ins.NoMessageKey
outs.suppressionConfigured = true
}
outs.Emit(*toEmit, buf)
outs.Emit(toEmit, buf)
}

// Copying the buffer to the output writer is handled in defer.
Expand Down Expand Up @@ -471,9 +471,8 @@ func (s *InputSchema) ReadLine(l *line) error {
return retErr
}

// Emit emits a formatted line to the provided buffer. The provided line object may not be used
// again until reinitialized.
func (s *OutputSchema) Emit(l line, w *bytes.Buffer) {
// Emit emits a formatted line to the provided buffer. Emit must not mutate line.
func (s *OutputSchema) Emit(l *line, w *bytes.Buffer) {
// Is this a line separating unrelated contexts? If so, print a separator and do nothing else.
if l.isSeparator {
w.WriteString("---\n")
Expand Down
2 changes: 1 addition & 1 deletion pkg/parse/parse_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func FuzzEmit(f *testing.F) {
fields: fieldMap,
}
outbuf := new(bytes.Buffer)
outs.Emit(*l, outbuf)
outs.Emit(l, outbuf)
byts := outbuf.Bytes()
if len(byts) == 0 {
t.Fatal("no output produced")
Expand Down
2 changes: 1 addition & 1 deletion pkg/parse/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ func TestEmit(t *testing.T) {
PriorityFields: []string{"baz"},
state: test.state,
}
s.Emit(test.line, w)
s.Emit(&test.line, w)
if diff := cmp.Diff(w.String(), test.want); diff != "" {
t.Errorf("emitted output:\n%v", diff)
}
Expand Down

0 comments on commit 4c5aa37

Please sign in to comment.