aboutsummaryrefslogtreecommitdiff
path: root/src/net/http
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2018-03-26 06:56:39 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2018-03-26 23:05:53 +0000
commit48db2c01b42d959f2d8fa0c24d853bdb6100cf8a (patch)
treec80a885e1971c4114d33c25e905def159be7f73c /src/net/http
parentf0eca373beb94763b71dadcf6504a95a3797dcbb (diff)
downloadgo-48db2c01b42d959f2d8fa0c24d853bdb6100cf8a.tar.xz
all: use strings.Builder instead of bytes.Buffer where appropriate
I grepped for "bytes.Buffer" and "buf.String" and mostly ignored test files. I skipped a few on purpose and probably missed a few others, but otherwise I think this should be most of them. Updates #18990 Change-Id: I5a6ae4296b87b416d8da02d7bfaf981d8cc14774 Reviewed-on: https://go-review.googlesource.com/102479 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/net/http')
-rw-r--r--src/net/http/cookie.go12
-rw-r--r--src/net/http/httptest/server.go4
2 files changed, 6 insertions, 10 deletions
diff --git a/src/net/http/cookie.go b/src/net/http/cookie.go
index 38b1b3630e..3e80cb659a 100644
--- a/src/net/http/cookie.go
+++ b/src/net/http/cookie.go
@@ -5,7 +5,6 @@
package http
import (
- "bytes"
"log"
"net"
"strconv"
@@ -143,7 +142,7 @@ func (c *Cookie) String() string {
if c == nil || !isCookieNameValid(c.Name) {
return ""
}
- var b bytes.Buffer
+ var b strings.Builder
b.WriteString(sanitizeCookieName(c.Name))
b.WriteRune('=')
b.WriteString(sanitizeCookieValue(c.Value))
@@ -168,17 +167,14 @@ func (c *Cookie) String() string {
log.Printf("net/http: invalid Cookie.Domain %q; dropping domain attribute", c.Domain)
}
}
+ var buf [len(TimeFormat)]byte
if validCookieExpires(c.Expires) {
b.WriteString("; Expires=")
- b2 := b.Bytes()
- b.Reset()
- b.Write(c.Expires.UTC().AppendFormat(b2, TimeFormat))
+ b.Write(c.Expires.UTC().AppendFormat(buf[:0], TimeFormat))
}
if c.MaxAge > 0 {
b.WriteString("; Max-Age=")
- b2 := b.Bytes()
- b.Reset()
- b.Write(strconv.AppendInt(b2, int64(c.MaxAge), 10))
+ b.Write(strconv.AppendInt(buf[:0], int64(c.MaxAge), 10))
} else if c.MaxAge < 0 {
b.WriteString("; Max-Age=0")
}
diff --git a/src/net/http/httptest/server.go b/src/net/http/httptest/server.go
index 6075397a26..ebafc9999c 100644
--- a/src/net/http/httptest/server.go
+++ b/src/net/http/httptest/server.go
@@ -7,7 +7,6 @@
package httptest
import (
- "bytes"
"crypto/tls"
"crypto/x509"
"flag"
@@ -17,6 +16,7 @@ import (
"net/http"
"net/http/internal"
"os"
+ "strings"
"sync"
"time"
)
@@ -224,7 +224,7 @@ func (s *Server) Close() {
func (s *Server) logCloseHangDebugInfo() {
s.mu.Lock()
defer s.mu.Unlock()
- var buf bytes.Buffer
+ var buf strings.Builder
buf.WriteString("httptest.Server blocked in Close after 5 seconds, waiting for connections:\n")
for c, st := range s.conns {
fmt.Fprintf(&buf, " %T %p %v in state %v\n", c, c, c.RemoteAddr(), st)