Skip to content

Commit 4ed8011

Browse files
committed
go/ast: use strings.Builder
Signed-off-by: cui fliter <[email protected]>
1 parent ba1ef54 commit 4ed8011

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

src/go/ast/commentmap_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
package ast_test
88

99
import (
10-
"bytes"
1110
"fmt"
1211
. "go/ast"
1312
"go/parser"
1413
"go/token"
1514
"sort"
15+
"strings"
1616
"testing"
1717
)
1818

@@ -94,7 +94,7 @@ var res = map[string]string{
9494
}
9595

9696
func ctext(list []*CommentGroup) string {
97-
var buf bytes.Buffer
97+
var buf strings.Builder
9898
for _, g := range list {
9999
buf.WriteString(g.Text())
100100
}

src/go/ast/example_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
package ast_test
66

77
import (
8-
"bytes"
98
"fmt"
109
"go/ast"
1110
"go/format"
1211
"go/parser"
1312
"go/token"
13+
"strings"
1414
)
1515

1616
// This example demonstrates how to inspect the AST of a Go program.
@@ -186,11 +186,11 @@ func main() {
186186
f.Comments = cmap.Filter(f).Comments()
187187

188188
// Print the modified AST.
189-
var buf bytes.Buffer
189+
var buf strings.Builder
190190
if err := format.Node(&buf, fset, f); err != nil {
191191
panic(err)
192192
}
193-
fmt.Printf("%s", buf.Bytes())
193+
fmt.Printf("%s", buf.String())
194194

195195
// Output:
196196
// // This is the package comment.

src/go/ast/filter_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
package ast_test
88

99
import (
10-
"bytes"
1110
"go/ast"
1211
"go/format"
1312
"go/parser"
1413
"go/token"
14+
"strings"
1515
"testing"
1616
)
1717

@@ -73,7 +73,7 @@ func TestFilterDuplicates(t *testing.T) {
7373
merged := ast.MergePackageFiles(pkg, ast.FilterFuncDuplicates)
7474

7575
// pretty-print
76-
var buf bytes.Buffer
76+
var buf strings.Builder
7777
if err := format.Node(&buf, fset, merged); err != nil {
7878
t.Fatal(err)
7979
}

src/go/ast/print_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package ast
66

77
import (
8-
"bytes"
98
"strings"
109
"testing"
1110
)
@@ -84,7 +83,7 @@ func trim(s string) string {
8483
}
8584

8685
func TestPrint(t *testing.T) {
87-
var buf bytes.Buffer
86+
var buf strings.Builder
8887
for _, test := range tests {
8988
buf.Reset()
9089
if err := Fprint(&buf, nil, test.x, nil); err != nil {

0 commit comments

Comments
 (0)