Append efficiently appends lines together It allocates an additional 10000 lines if the original estimate is incorrect
(slice []Line, data ...Line)
| 81 | // It allocates an additional 10000 lines if the original estimate |
| 82 | // is incorrect |
| 83 | func Append(slice []Line, data ...Line) []Line { |
| 84 | l := len(slice) |
| 85 | if l+len(data) > cap(slice) { // reallocate |
| 86 | newSlice := make([]Line, (l+len(data))+10000) |
| 87 | copy(newSlice, slice) |
| 88 | slice = newSlice |
| 89 | } |
| 90 | slice = slice[0 : l+len(data)] |
| 91 | for i, c := range data { |
| 92 | slice[l+i] = c |
| 93 | } |
| 94 | return slice |
| 95 | } |
| 96 | |
| 97 | // NewLineArray returns a new line array from an array of bytes |
| 98 | func NewLineArray(size uint64, endings FileFormat, reader io.Reader) *LineArray { |