Skip to content

Commit 67e04e6

Browse files
committed
internal/buffer: add String method
Change-Id: Ic041a15e505df39476fada1079b31ef6d68c13b5 Reviewed-on: https://go-review.googlesource.com/c/exp/+/435380 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alan Donovan <[email protected]> Run-TryBot: Jonathan Amsterdam <[email protected]>
1 parent c76eaa3 commit 67e04e6

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

slog/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func (h *commonHandler) handle(r Record) error {
181181
buf.WriteString(file)
182182
buf.WriteByte(':')
183183
itoa((*[]byte)(buf), line, -1)
184-
s := string(*buf)
184+
s := buf.String()
185185
buf.Free()
186186
replace(String(key, s))
187187
}

slog/internal/buffer/buffer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ func (b *Buffer) WriteString(s string) {
4444
func (b *Buffer) WriteByte(c byte) {
4545
*b = append(*b, c)
4646
}
47+
48+
func (b *Buffer) String() string {
49+
return string(*b)
50+
}

slog/internal/buffer/buffer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func Test(t *testing.T) {
1212
b.WriteString("hello")
1313
b.WriteByte(',')
1414
b.Write([]byte(" world"))
15-
got := string(*b)
15+
got := b.String()
1616
want := "hello, world"
1717
if got != want {
1818
t.Errorf("got %q, want %q", got, want)

slog/record_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func BenchmarkSourceLine(b *testing.B) {
132132
buf.WriteString(file)
133133
buf.WriteByte(':')
134134
itoa((*[]byte)(buf), line, -1)
135-
s := string(*buf)
135+
s := buf.String()
136136
buf.Free()
137137
_ = s
138138
}

0 commit comments

Comments
 (0)