addLine adds a new line. flushed is a hint indicating whether the underlying writer was just flushed. If so, the previous line is not likely to be a good indicator of the new line's cells.
(flushed bool)
| 113 | // flushed is a hint indicating whether the underlying writer was just flushed. |
| 114 | // If so, the previous line is not likely to be a good indicator of the new line's cells. |
| 115 | func (b *Writer) addLine(flushed bool) { |
| 116 | // Grow slice instead of appending, |
| 117 | // as that gives us an opportunity |
| 118 | // to reuse an existing []cell. |
| 119 | if n := len(b.lines) + 1; n <= cap(b.lines) { |
| 120 | b.lines = b.lines[:n] |
| 121 | b.lines[n-1] = b.lines[n-1][:0] |
| 122 | } else { |
| 123 | b.lines = append(b.lines, nil) |
| 124 | } |
| 125 | |
| 126 | if !flushed { |
| 127 | // The previous line is probably a good indicator |
| 128 | // of how many cells the current line will have. |
| 129 | // If the current line's capacity is smaller than that, |
| 130 | // abandon it and make a new one. |
| 131 | if n := len(b.lines); n >= 2 { |
| 132 | if prev := len(b.lines[n-2]); prev > cap(b.lines[n-1]) { |
| 133 | b.lines[n-1] = make([]cell, 0, prev) |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | // Reset the current state. |
| 140 | func (b *Writer) reset() { |