mirror of
https://github.com/restic/restic.git
synced 2025-10-09 06:10:57 +00:00
Simplify ui.StdioWrapper.Write
Instead of looping to find line breaks, make it look for the last one.
This commit is contained in:
@@ -55,22 +55,12 @@ func (w *lineWriter) Write(data []byte) (n int, err error) {
|
||||
|
||||
// look for line breaks
|
||||
buf := w.buf.Bytes()
|
||||
skip := 0
|
||||
for i := 0; i < len(buf); {
|
||||
if buf[i] == '\n' {
|
||||
// found line
|
||||
w.print(string(buf[:i+1]))
|
||||
buf = buf[i+1:]
|
||||
skip += i + 1
|
||||
i = 0
|
||||
continue
|
||||
}
|
||||
|
||||
i++
|
||||
i := bytes.LastIndexByte(buf, '\n')
|
||||
if i != -1 {
|
||||
w.print(string(buf[:i+1]))
|
||||
w.buf.Next(i + 1)
|
||||
}
|
||||
|
||||
_ = w.buf.Next(skip)
|
||||
|
||||
return n, err
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user