From 5555728c727866c251aa2f3dce2a2f30983165b8 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Wed, 10 Feb 2021 12:03:13 -0800 Subject: [PATCH] logtail/filch: use bufio.ScanLines splitLines here is identical to bufio.ScanLines, except that bufio.ScanLines removes \r in addition to \n. Trailing carriage returns shouldn't matter for our uses. Since bufio.ScanLines is the default for a new bufio.Scanner, we can delete the calls to Split too. --- logtail/filch/filch.go | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/logtail/filch/filch.go b/logtail/filch/filch.go index 07d9b6203..00863ae4d 100644 --- a/logtail/filch/filch.go +++ b/logtail/filch/filch.go @@ -8,7 +8,6 @@ import ( "bufio" - "bytes" "fmt" "io" "os" @@ -53,7 +52,6 @@ func (f *Filch) TryReadLine() ([]byte, error) { return nil, err } f.altscan = bufio.NewScanner(f.alt) - f.altscan.Split(splitLines) return f.scan() } @@ -188,7 +186,6 @@ func New(filePrefix string, opts Options) (f *Filch, err error) { } if f.recovered > 0 { f.altscan = bufio.NewScanner(f.alt) - f.altscan.Split(splitLines) } f.OrigStderr = nil @@ -228,16 +225,3 @@ func moveContents(dst, src *os.File) (err error) { } return nil } - -func splitLines(data []byte, atEOF bool) (advance int, token []byte, err error) { - if atEOF && len(data) == 0 { - return 0, nil, nil - } - if i := bytes.IndexByte(data, '\n'); i >= 0 { - return i + 1, data[0 : i+1], nil - } - if atEOF { - return len(data), data, nil - } - return 0, nil, nil -}