Skip to content

go/ast: use strings.Builder #54916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/go/ast/commentmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
package ast_test

import (
"bytes"
"fmt"
. "go/ast"
"go/parser"
"go/token"
"sort"
"strings"
"testing"
)

Expand Down Expand Up @@ -94,7 +94,7 @@ var res = map[string]string{
}

func ctext(list []*CommentGroup) string {
var buf bytes.Buffer
var buf strings.Builder
for _, g := range list {
buf.WriteString(g.Text())
}
Expand Down
6 changes: 3 additions & 3 deletions src/go/ast/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
package ast_test

import (
"bytes"
"fmt"
"go/ast"
"go/format"
"go/parser"
"go/token"
"strings"
)

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

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

// Output:
// // This is the package comment.
Expand Down
4 changes: 2 additions & 2 deletions src/go/ast/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
package ast_test

import (
"bytes"
"go/ast"
"go/format"
"go/parser"
"go/token"
"strings"
"testing"
)

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

// pretty-print
var buf bytes.Buffer
var buf strings.Builder
if err := format.Node(&buf, fset, merged); err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions src/go/ast/print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package ast

import (
"bytes"
"strings"
"testing"
)
Expand Down Expand Up @@ -84,7 +83,7 @@ func trim(s string) string {
}

func TestPrint(t *testing.T) {
var buf bytes.Buffer
var buf strings.Builder
for _, test := range tests {
buf.Reset()
if err := Fprint(&buf, nil, test.x, nil); err != nil {
Expand Down