Commit f2b5f750 authored by Robert Griesemer's avatar Robert Griesemer

text/tabwriter: remove internal use of bytes.Buffer (cleanup)

Noticed that we can simply use a []byte slice while investigating
a separate issue. Did the obvious simplification.

Change-Id: I921ebbb42135b5f1a10109236ceb9ae6e94ae7e2
Reviewed-on: https://go-review.googlesource.com/104757
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent b9a36568
......@@ -12,7 +12,6 @@
package tabwriter
import (
"bytes"
"io"
"unicode/utf8"
)
......@@ -99,7 +98,7 @@ type Writer struct {
flags uint
// current state
buf bytes.Buffer // collected text excluding tabs or line breaks
buf []byte // collected text excluding tabs or line breaks
pos int // buffer position up to which cell.width of incomplete cell has been computed
cell cell // current incomplete cell; cell.width is up to buf[pos] excluding ignored sections
endChar byte // terminating char of escaped sequence (Escape for escapes, '>', ';' for HTML tags/entities, or 0)
......@@ -111,7 +110,7 @@ func (b *Writer) addLine() { b.lines = append(b.lines, []cell{}) }
// Reset the current state.
func (b *Writer) reset() {
b.buf.Reset()
b.buf = b.buf[:0]
b.pos = 0
b.cell = cell{}
b.endChar = 0
......@@ -212,7 +211,7 @@ func (b *Writer) dump() {
for i, line := range b.lines {
print("(", i, ") ")
for _, c := range line {
print("[", string(b.buf.Bytes()[pos:pos+c.size]), "]")
print("[", string(b.buf[pos:pos+c.size]), "]")
pos += c.size
}
print("\n")
......@@ -294,7 +293,7 @@ func (b *Writer) writeLines(pos0 int, line0, line1 int) (pos int) {
// non-empty cell
useTabs = false
if b.flags&AlignRight == 0 { // align left
b.write0(b.buf.Bytes()[pos : pos+c.size])
b.write0(b.buf[pos : pos+c.size])
pos += c.size
if j < len(b.widths) {
b.writePadding(c.width, b.widths[j], false)
......@@ -303,7 +302,7 @@ func (b *Writer) writeLines(pos0 int, line0, line1 int) (pos int) {
if j < len(b.widths) {
b.writePadding(c.width, b.widths[j], false)
}
b.write0(b.buf.Bytes()[pos : pos+c.size])
b.write0(b.buf[pos : pos+c.size])
pos += c.size
}
}
......@@ -312,7 +311,7 @@ func (b *Writer) writeLines(pos0 int, line0, line1 int) (pos int) {
if i+1 == len(b.lines) {
// last buffered line - we don't have a newline, so just write
// any outstanding buffered data
b.write0(b.buf.Bytes()[pos : pos+b.cell.size])
b.write0(b.buf[pos : pos+b.cell.size])
pos += b.cell.size
} else {
// not the last line - write newline
......@@ -387,14 +386,14 @@ func (b *Writer) format(pos0 int, line0, line1 int) (pos int) {
// Append text to current cell.
func (b *Writer) append(text []byte) {
b.buf.Write(text)
b.buf = append(b.buf, text...)
b.cell.size += len(text)
}
// Update the cell width.
func (b *Writer) updateWidth() {
b.cell.width += utf8.RuneCount(b.buf.Bytes()[b.pos:b.buf.Len()])
b.pos = b.buf.Len()
b.cell.width += utf8.RuneCount(b.buf[b.pos:])
b.pos = len(b.buf)
}
// To escape a text segment, bracket it with Escape characters.
......@@ -434,7 +433,7 @@ func (b *Writer) endEscape() {
case ';':
b.cell.width++ // entity, count as one rune
}
b.pos = b.buf.Len()
b.pos = len(b.buf)
b.endChar = 0
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment