readLine is our own implementation of ReadBytes(). We try to use readSlice() as much as we can but we need to tolerate if an input line is longer than the buffer specified at Reader creation. Not using the more complicated slice of slices that Reader.ReadBytes() uses since it should not happen ofte
()
| 86 | // starting with 4x buffer size, which should get most cases with a single |
| 87 | // allocation. |
| 88 | func (r *reader) readLine() ([]byte, error) { |
| 89 | var d []byte |
| 90 | for { |
| 91 | f, err := r.readSlice() |
| 92 | if err != errBufferFull { |
| 93 | if d == nil { |
| 94 | return f, err |
| 95 | } |
| 96 | return append(d, f...), err |
| 97 | } |
| 98 | if d == nil { |
| 99 | d = make([]byte, 0, len(f)*4) |
| 100 | } |
| 101 | d = append(d, f...) |
| 102 | } |
| 103 | } |
no test coverage detected