aboutsummaryrefslogtreecommitdiff
path: root/syntax
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2019-03-01 14:24:35 -0800
committeralandonovan <adonovan@google.com>2019-03-01 17:24:35 -0500
commit8cb25c8162478e5f38d1e77f93d90e8db4cc6259 (patch)
tree4b35a94382a7f2e03c9d348104f932cf2bcacb11 /syntax
parent1174b2613e8224c5fe76d0fc8eb8de4a1384a89f (diff)
downloadstarlark-go-8cb25c8162478e5f38d1e77f93d90e8db4cc6259.tar.gz
all: use strings.Builder (#163)
Fixes #95
Diffstat (limited to 'syntax')
-rw-r--r--syntax/quote.go5
-rw-r--r--syntax/scan.go3
2 files changed, 3 insertions, 5 deletions
diff --git a/syntax/quote.go b/syntax/quote.go
index d31eb2a..cc9a8d0 100644
--- a/syntax/quote.go
+++ b/syntax/quote.go
@@ -7,7 +7,6 @@ package syntax
// Starlark quoted string utilities.
import (
- "bytes"
"fmt"
"strconv"
"strings"
@@ -95,7 +94,7 @@ func unquote(quoted string) (s string, triple bool, err error) {
// Otherwise process quoted string.
// Each iteration processes one escape sequence along with the
// plain text leading up to it.
- var buf bytes.Buffer
+ buf := new(strings.Builder)
for {
// Remove prefix before escape sequence.
i := strings.IndexAny(quoted, unquoteChars)
@@ -204,7 +203,7 @@ func quote(unquoted string, triple bool) string {
q = `"""`
}
- var buf bytes.Buffer
+ buf := new(strings.Builder)
buf.WriteString(q)
for i := 0; i < len(unquoted); i++ {
diff --git a/syntax/scan.go b/syntax/scan.go
index 7fbc5d6..5b3fcbc 100644
--- a/syntax/scan.go
+++ b/syntax/scan.go
@@ -7,7 +7,6 @@ package syntax
// A lexical scanner for Starlark.
import (
- "bytes"
"fmt"
"io"
"io/ioutil"
@@ -832,7 +831,7 @@ func (sc *scanner) scanString(val *tokenValue, quote rune) Token {
// A triple-quoted string literal may span multiple
// gulps of REPL input; it is the only such token.
// Thus we must avoid {start,end}Token.
- var raw bytes.Buffer
+ raw := new(strings.Builder)
// Copy the prefix, e.g. r''' or """ (see startToken).
raw.Write(sc.token[:len(sc.token)-len(sc.rest)])