]> Cypherpunks repositories - gostls13.git/commitdiff
go/ast: use strings.Builder
authorcui fliter <imcusg@gmail.com>
Wed, 7 Sep 2022 03:33:43 +0000 (03:33 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 9 Sep 2022 15:35:30 +0000 (15:35 +0000)
Change-Id: I9c4c3ada3a8f5d8d198cc42a4afc06972ee00c61
GitHub-Last-Rev: 4ed80119e3aef2e5bcfdb58a2d53ed64ef40892b
GitHub-Pull-Request: golang/go#54916
Reviewed-on: https://go-review.googlesource.com/c/go/+/428921
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/go/ast/commentmap_test.go
src/go/ast/example_test.go
src/go/ast/filter_test.go
src/go/ast/print_test.go

index 281467c41f307454a01ca2786768c17e43aced07..f0faeed610a1871ace48cae0018094d556bfd5aa 100644 (file)
@@ -7,12 +7,12 @@
 package ast_test
 
 import (
-       "bytes"
        "fmt"
        . "go/ast"
        "go/parser"
        "go/token"
        "sort"
+       "strings"
        "testing"
 )
 
@@ -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())
        }
index e3013f64bed87e3e8ff2e41311688346b5cea41f..67860ce922d2cbea025eb3ad9caa78aad68300e8 100644 (file)
@@ -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.
@@ -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.
index 86f396bb8be897cbf6c929eaad5f9a03906f6b72..d5cb0c2e3f179748af78b34b88130e073dee0fcc 100644 (file)
@@ -7,11 +7,11 @@
 package ast_test
 
 import (
-       "bytes"
        "go/ast"
        "go/format"
        "go/parser"
        "go/token"
+       "strings"
        "testing"
 )
 
@@ -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)
        }
index 6691ccd63a3153e44fa2f9f2423ad0b37345785f..94b515bce76450fd344cd0eac4b6a37291b44286 100644 (file)
@@ -5,7 +5,6 @@
 package ast
 
 import (
-       "bytes"
        "strings"
        "testing"
 )
@@ -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 {