From a16092f374522536ad637e5a3766585df2c160f0 Mon Sep 17 00:00:00 2001 From: Tom Thorogood Date: Mon, 6 Nov 2023 16:57:11 +1030 Subject: [PATCH] Use strings.Builder in endingToString (#1506) This will cause one less allocation as String allocates on a bytes.Buffer but not on a strings.Builder. --- scan_rr.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scan_rr.go b/scan_rr.go index d08c8e6a7..a635e1c5c 100644 --- a/scan_rr.go +++ b/scan_rr.go @@ -1,7 +1,6 @@ package dns import ( - "bytes" "encoding/base64" "errors" "net" @@ -12,15 +11,15 @@ import ( // A remainder of the rdata with embedded spaces, return the parsed string (sans the spaces) // or an error func endingToString(c *zlexer, errstr string) (string, *ParseError) { - var buffer bytes.Buffer + var s strings.Builder l, _ := c.Next() // zString for l.value != zNewline && l.value != zEOF { if l.err { - return buffer.String(), &ParseError{"", errstr, l} + return s.String(), &ParseError{"", errstr, l} } switch l.value { case zString: - buffer.WriteString(l.token) + s.WriteString(l.token) case zBlank: // Ok default: return "", &ParseError{"", errstr, l} @@ -28,7 +27,7 @@ func endingToString(c *zlexer, errstr string) (string, *ParseError) { l, _ = c.Next() } - return buffer.String(), nil + return s.String(), nil } // A remainder of the rdata with embedded spaces, split on unquoted whitespace