Skip to content

Commit 6945c67

Browse files
committed
cmd/compile: merge bytes inline test with the rest
In golang.org/cl/42813, a test was added in the bytes package to check if a Buffer method was being inlined, using 'go tool nm'. Now that we have a compiler test that verifies that certain funcs are inlineable, merge it there. Knowing whether the funcs are inlineable is also more reliable than whether or not their symbol appears in the binary, too. For example, under some circumstances, inlineable funcs can't be inlined, such as if closures are used. While at it, add a few more bytes.Buffer methods that are currently inlined and should clearly stay that way. Updates #21851. Change-Id: I62066e32ef5542d37908bd64f90bda51276da4de Reviewed-on: https://go-review.googlesource.com/65658 Run-TryBot: Daniel Martí <[email protected]> Reviewed-by: Marvin Stenger <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 0168fdb commit 6945c67

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

src/bytes/buffer_test.go

-22
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ package bytes_test
66

77
import (
88
. "bytes"
9-
"internal/testenv"
109
"io"
1110
"math/rand"
12-
"os/exec"
1311
"runtime"
1412
"testing"
1513
"unicode/utf8"
@@ -560,26 +558,6 @@ func TestBufferGrowth(t *testing.T) {
560558
}
561559
}
562560

563-
// Test that tryGrowByReslice is inlined.
564-
// Only execute on "linux-amd64" builder in order to avoid breakage.
565-
func TestTryGrowByResliceInlined(t *testing.T) {
566-
targetBuilder := "linux-amd64"
567-
if testenv.Builder() != targetBuilder {
568-
t.Skipf("%q gets executed on %q builder only", t.Name(), targetBuilder)
569-
}
570-
t.Parallel()
571-
goBin := testenv.GoToolPath(t)
572-
out, err := exec.Command(goBin, "tool", "nm", goBin).CombinedOutput()
573-
if err != nil {
574-
t.Fatalf("go tool nm: %v: %s", err, out)
575-
}
576-
// Verify this doesn't exist:
577-
sym := "bytes.(*Buffer).tryGrowByReslice"
578-
if Contains(out, []byte(sym)) {
579-
t.Errorf("found symbol %q in cmd/go, but should be inlined", sym)
580-
}
581-
}
582-
583561
func BenchmarkWriteByte(b *testing.B) {
584562
const n = 4 << 10
585563
b.SetBytes(n)

src/cmd/compile/internal/gc/inl_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ func TestIntendedInlining(t *testing.T) {
6464
"(*waitq).enqueue",
6565
},
6666
"runtime/internal/sys": {},
67+
"bytes": {
68+
"(*Buffer).Bytes",
69+
"(*Buffer).Cap",
70+
"(*Buffer).Len",
71+
"(*Buffer).Next",
72+
"(*Buffer).Read",
73+
"(*Buffer).ReadByte",
74+
"(*Buffer).Reset",
75+
"(*Buffer).String",
76+
"(*Buffer).UnreadByte",
77+
"(*Buffer).tryGrowByReslice",
78+
},
6779
"unicode/utf8": {
6880
"FullRune",
6981
"FullRuneInString",

0 commit comments

Comments
 (0)