Commit 50a1d89a authored by Russ Cox's avatar Russ Cox

fmt: rename buffer.WriteByte to writeByte

Renaming the method makes clear, both to readers and to vet,
that this method is not the implementation of io.ByteWriter.

Working toward making the tree vet-safe instead of having
so many exceptions in cmd/vet/all/whitelist.

For #31916.

Change-Id: I79da062ca6469b62a6b9e284c6cf2413c7425249
Reviewed-on: https://go-review.googlesource.com/c/go/+/176109
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: default avatarAustin Clements <austin@google.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent a44c3edb
...@@ -23,9 +23,8 @@ cmd/compile/internal/gc/testdata/short_test.go: unreachable code ...@@ -23,9 +23,8 @@ cmd/compile/internal/gc/testdata/short_test.go: unreachable code
// These cases are basically ok. // These cases are basically ok.
// Errors are handled reasonably and there's no clear need for interface satisfaction. // Errors are handled reasonably and there's no clear need for interface satisfaction.
// Except for the runtime/pprof case, the API is not exported. // Except for the runtime/pprof case, the API is not exported.
fmt/print.go: method WriteByte(c byte) should have signature WriteByte(byte) error
// Also non-standard, but this method is on an unexported type, so it's // Also on-standard, but this method is on an unexported type, so it's
// irrelevant. // irrelevant.
encoding/gob/encode.go: method WriteByte(c byte) should have signature WriteByte(byte) error encoding/gob/encode.go: method WriteByte(c byte) should have signature WriteByte(byte) error
......
...@@ -156,10 +156,10 @@ loop: ...@@ -156,10 +156,10 @@ loop:
break break
} }
if w.fmt.needColon || !p.fmt.plusV { if w.fmt.needColon || !p.fmt.plusV {
w.buf.WriteByte(':') w.buf.writeByte(':')
w.fmt.needColon = false w.fmt.needColon = false
} }
w.buf.WriteString(sep) w.buf.writeString(sep)
w.fmt.inDetail = false w.fmt.inDetail = false
w.fmt.needNewline = false w.fmt.needNewline = false
} }
...@@ -195,24 +195,24 @@ func (p *errPPState) Write(b []byte) (n int, err error) { ...@@ -195,24 +195,24 @@ func (p *errPPState) Write(b []byte) (n int, err error) {
for i, c := range b { for i, c := range b {
if p.fmt.needNewline { if p.fmt.needNewline {
if p.fmt.inDetail && p.fmt.needColon { if p.fmt.inDetail && p.fmt.needColon {
p.buf.WriteByte(':') p.buf.writeByte(':')
p.fmt.needColon = false p.fmt.needColon = false
} }
p.buf.Write(detailSep) p.buf.write(detailSep)
p.fmt.needNewline = false p.fmt.needNewline = false
} }
if c == '\n' { if c == '\n' {
p.buf.Write(b[k:i]) p.buf.write(b[k:i])
k = i + 1 k = i + 1
p.fmt.needNewline = true p.fmt.needNewline = true
} }
} }
p.buf.Write(b[k:]) p.buf.write(b[k:])
if !p.fmt.inDetail { if !p.fmt.inDetail {
p.fmt.needColon = true p.fmt.needColon = true
} }
} else if !p.fmt.inDetail { } else if !p.fmt.inDetail {
p.buf.Write(b) p.buf.write(b)
} }
return len(b), nil return len(b), nil
......
...@@ -94,17 +94,17 @@ func (f *fmt) writePadding(n int) { ...@@ -94,17 +94,17 @@ func (f *fmt) writePadding(n int) {
// pad appends b to f.buf, padded on left (!f.minus) or right (f.minus). // pad appends b to f.buf, padded on left (!f.minus) or right (f.minus).
func (f *fmt) pad(b []byte) { func (f *fmt) pad(b []byte) {
if !f.widPresent || f.wid == 0 { if !f.widPresent || f.wid == 0 {
f.buf.Write(b) f.buf.write(b)
return return
} }
width := f.wid - utf8.RuneCount(b) width := f.wid - utf8.RuneCount(b)
if !f.minus { if !f.minus {
// left padding // left padding
f.writePadding(width) f.writePadding(width)
f.buf.Write(b) f.buf.write(b)
} else { } else {
// right padding // right padding
f.buf.Write(b) f.buf.write(b)
f.writePadding(width) f.writePadding(width)
} }
} }
...@@ -112,17 +112,17 @@ func (f *fmt) pad(b []byte) { ...@@ -112,17 +112,17 @@ func (f *fmt) pad(b []byte) {
// padString appends s to f.buf, padded on left (!f.minus) or right (f.minus). // padString appends s to f.buf, padded on left (!f.minus) or right (f.minus).
func (f *fmt) padString(s string) { func (f *fmt) padString(s string) {
if !f.widPresent || f.wid == 0 { if !f.widPresent || f.wid == 0 {
f.buf.WriteString(s) f.buf.writeString(s)
return return
} }
width := f.wid - utf8.RuneCountInString(s) width := f.wid - utf8.RuneCountInString(s)
if !f.minus { if !f.minus {
// left padding // left padding
f.writePadding(width) f.writePadding(width)
f.buf.WriteString(s) f.buf.writeString(s)
} else { } else {
// right padding // right padding
f.buf.WriteString(s) f.buf.writeString(s)
f.writePadding(width) f.writePadding(width)
} }
} }
...@@ -574,9 +574,9 @@ func (f *fmt) fmtFloat(v float64, size int, verb rune, prec int) { ...@@ -574,9 +574,9 @@ func (f *fmt) fmtFloat(v float64, size int, verb rune, prec int) {
// If we're zero padding to the left we want the sign before the leading zeros. // If we're zero padding to the left we want the sign before the leading zeros.
// Achieve this by writing the sign out and then padding the unsigned number. // Achieve this by writing the sign out and then padding the unsigned number.
if f.zero && f.widPresent && f.wid > len(num) { if f.zero && f.widPresent && f.wid > len(num) {
f.buf.WriteByte(num[0]) f.buf.writeByte(num[0])
f.writePadding(f.wid - len(num)) f.writePadding(f.wid - len(num))
f.buf.Write(num[1:]) f.buf.write(num[1:])
return return
} }
f.pad(num) f.pad(num)
......
This diff is collapsed.
...@@ -457,7 +457,7 @@ func (s *ss) token(skipSpace bool, f func(rune) bool) []byte { ...@@ -457,7 +457,7 @@ func (s *ss) token(skipSpace bool, f func(rune) bool) []byte {
s.UnreadRune() s.UnreadRune()
break break
} }
s.buf.WriteRune(r) s.buf.writeRune(r)
} }
return s.buf return s.buf
} }
...@@ -483,7 +483,7 @@ func (s *ss) consume(ok string, accept bool) bool { ...@@ -483,7 +483,7 @@ func (s *ss) consume(ok string, accept bool) bool {
} }
if indexRune(ok, r) >= 0 { if indexRune(ok, r) >= 0 {
if accept { if accept {
s.buf.WriteRune(r) s.buf.writeRune(r)
} }
return true return true
} }
...@@ -850,20 +850,20 @@ func (s *ss) quotedString() string { ...@@ -850,20 +850,20 @@ func (s *ss) quotedString() string {
if r == quote { if r == quote {
break break
} }
s.buf.WriteRune(r) s.buf.writeRune(r)
} }
return string(s.buf) return string(s.buf)
case '"': case '"':
// Double-quoted: Include the quotes and let strconv.Unquote do the backslash escapes. // Double-quoted: Include the quotes and let strconv.Unquote do the backslash escapes.
s.buf.WriteByte('"') s.buf.writeByte('"')
for { for {
r := s.mustReadRune() r := s.mustReadRune()
s.buf.WriteRune(r) s.buf.writeRune(r)
if r == '\\' { if r == '\\' {
// In a legal backslash escape, no matter how long, only the character // In a legal backslash escape, no matter how long, only the character
// immediately after the escape can itself be a backslash or quote. // immediately after the escape can itself be a backslash or quote.
// Thus we only need to protect the first character after the backslash. // Thus we only need to protect the first character after the backslash.
s.buf.WriteRune(s.mustReadRune()) s.buf.writeRune(s.mustReadRune())
} else if r == '"' { } else if r == '"' {
break break
} }
...@@ -922,7 +922,7 @@ func (s *ss) hexString() string { ...@@ -922,7 +922,7 @@ func (s *ss) hexString() string {
if !ok { if !ok {
break break
} }
s.buf.WriteByte(b) s.buf.writeByte(b)
} }
if len(s.buf) == 0 { if len(s.buf) == 0 {
s.errorString("no hex data for %x string") s.errorString("no hex data for %x string")
......
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