mirror of
https://github.com/golang/go
synced 2024-11-18 10:54:40 -07:00
all: use strings.Builder instead of bytes.Buffer
Change-Id: I6d7213d29ade591b8366d5640833bd5a20474165
GitHub-Last-Rev: 9419583287
GitHub-Pull-Request: golang/go#54834
Reviewed-on: https://go-review.googlesource.com/c/go/+/427814
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: hopehook <hopehook@golangcn.org>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
This commit is contained in:
parent
a0f05823e4
commit
7a86ef2ad8
@ -6,8 +6,8 @@
|
|||||||
package str
|
package str
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
@ -49,7 +49,7 @@ func ToFold(s string) string {
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
Slow:
|
Slow:
|
||||||
var buf bytes.Buffer
|
var b strings.Builder
|
||||||
for _, r := range s {
|
for _, r := range s {
|
||||||
// SimpleFold(x) cycles to the next equivalent rune > x
|
// SimpleFold(x) cycles to the next equivalent rune > x
|
||||||
// or wraps around to smaller values. Iterate until it wraps,
|
// or wraps around to smaller values. Iterate until it wraps,
|
||||||
@ -65,9 +65,9 @@ Slow:
|
|||||||
if 'A' <= r && r <= 'Z' {
|
if 'A' <= r && r <= 'Z' {
|
||||||
r += 'a' - 'A'
|
r += 'a' - 'A'
|
||||||
}
|
}
|
||||||
buf.WriteRune(r)
|
b.WriteRune(r)
|
||||||
}
|
}
|
||||||
return buf.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FoldDup reports a pair of strings from the list that are
|
// FoldDup reports a pair of strings from the list that are
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
package gccgoimporter
|
package gccgoimporter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/constant"
|
"go/constant"
|
||||||
@ -129,16 +128,16 @@ func (p *parser) parseUnquotedString() string {
|
|||||||
if p.tok == scanner.EOF {
|
if p.tok == scanner.EOF {
|
||||||
p.error("unexpected EOF")
|
p.error("unexpected EOF")
|
||||||
}
|
}
|
||||||
var buf bytes.Buffer
|
var b strings.Builder
|
||||||
buf.WriteString(p.scanner.TokenText())
|
b.WriteString(p.scanner.TokenText())
|
||||||
// This loop needs to examine each character before deciding whether to consume it. If we see a semicolon,
|
// This loop needs to examine each character before deciding whether to consume it. If we see a semicolon,
|
||||||
// we need to let it be consumed by p.next().
|
// we need to let it be consumed by p.next().
|
||||||
for ch := p.scanner.Peek(); ch != '\n' && ch != ';' && ch != scanner.EOF && p.scanner.Whitespace&(1<<uint(ch)) == 0; ch = p.scanner.Peek() {
|
for ch := p.scanner.Peek(); ch != '\n' && ch != ';' && ch != scanner.EOF && p.scanner.Whitespace&(1<<uint(ch)) == 0; ch = p.scanner.Peek() {
|
||||||
buf.WriteRune(ch)
|
b.WriteRune(ch)
|
||||||
p.scanner.Next()
|
p.scanner.Next()
|
||||||
}
|
}
|
||||||
p.next()
|
p.next()
|
||||||
return buf.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) next() {
|
func (p *parser) next() {
|
||||||
|
@ -829,18 +829,18 @@ func isQtext(r rune) bool {
|
|||||||
|
|
||||||
// quoteString renders a string as an RFC 5322 quoted-string.
|
// quoteString renders a string as an RFC 5322 quoted-string.
|
||||||
func quoteString(s string) string {
|
func quoteString(s string) string {
|
||||||
var buf strings.Builder
|
var b strings.Builder
|
||||||
buf.WriteByte('"')
|
b.WriteByte('"')
|
||||||
for _, r := range s {
|
for _, r := range s {
|
||||||
if isQtext(r) || isWSP(r) {
|
if isQtext(r) || isWSP(r) {
|
||||||
buf.WriteRune(r)
|
b.WriteRune(r)
|
||||||
} else if isVchar(r) {
|
} else if isVchar(r) {
|
||||||
buf.WriteByte('\\')
|
b.WriteByte('\\')
|
||||||
buf.WriteRune(r)
|
b.WriteRune(r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf.WriteByte('"')
|
b.WriteByte('"')
|
||||||
return buf.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// isVchar reports whether r is an RFC 5322 VCHAR character.
|
// isVchar reports whether r is an RFC 5322 VCHAR character.
|
||||||
|
Loading…
Reference in New Issue
Block a user