oauth2: use strings.Builder instead of bytes.Buffer
The former does not make a copy of the accumulated buffer
to produce a string.
WriteByte() is faster than WriteRune() and we are not
appending non-ASCII here.
Change-Id: I562461eec2fdcf6230e46b3011fabe0979d05044
GitHub-Last-Rev: b7845f8881d5097e0a70d025d737f1da6eaa7586
GitHub-Pull-Request: golang/oauth2#785
Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/694715
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
Reviewed-by: Sean Liao <sean@liao.dev>
Auto-Submit: Sean Liao <sean@liao.dev>
diff --git a/google/externalaccount/aws.go b/google/externalaccount/aws.go
index e1a735e..f62ec99 100644
--- a/google/externalaccount/aws.go
+++ b/google/externalaccount/aws.go
@@ -5,7 +5,6 @@
package externalaccount
import (
- "bytes"
"context"
"crypto/hmac"
"crypto/sha256"
@@ -148,13 +147,13 @@
}
sort.Strings(headers)
- var fullHeaders bytes.Buffer
+ var fullHeaders strings.Builder
for _, header := range headers {
headerValue := strings.Join(lowerCaseHeaders[header], ",")
fullHeaders.WriteString(header)
- fullHeaders.WriteRune(':')
+ fullHeaders.WriteByte(':')
fullHeaders.WriteString(headerValue)
- fullHeaders.WriteRune('\n')
+ fullHeaders.WriteByte('\n')
}
return strings.Join(headers, ";"), fullHeaders.String()
diff --git a/oauth2.go b/oauth2.go
index de34feb..3e3b630 100644
--- a/oauth2.go
+++ b/oauth2.go
@@ -9,7 +9,6 @@
package oauth2 // import "golang.org/x/oauth2"
import (
- "bytes"
"context"
"errors"
"net/http"
@@ -158,7 +157,7 @@
// PKCE), https://www.oauth.com/oauth2-servers/pkce/ and
// https://www.ietf.org/archive/id/draft-ietf-oauth-v2-1-09.html#name-cross-site-request-forgery (describing both approaches)
func (c *Config) AuthCodeURL(state string, opts ...AuthCodeOption) string {
- var buf bytes.Buffer
+ var buf strings.Builder
buf.WriteString(c.Endpoint.AuthURL)
v := url.Values{
"response_type": {"code"},