]> Cypherpunks.ru repositories - gostls13.git/commitdiff
net/url: use quick path in URL.Encode() on empty map
authorMikhail Mazurskiy <mmazurskiy@gitlab.com>
Tue, 31 Oct 2023 00:17:18 +0000 (00:17 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 7 Nov 2023 22:01:35 +0000 (22:01 +0000)
Make url.Values.Encode() slightly more efficient when url.Values
is an empty but non-nil map.

Change-Id: I7f205cc7e67526a1fa0035eab4773cec5e0f2c99
GitHub-Last-Rev: 0530b439db8cea755464c6dc2d268a0bd567889e
GitHub-Pull-Request: golang/go#63836
Reviewed-on: https://go-review.googlesource.com/c/go/+/538637
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>

src/net/url/url.go
src/net/url/url_test.go

index 2d40a58673c529946269c0d0a50d0eac39e1bcfe..902310c244cc0c2250cc28837b548e3119b4ef3a 100644 (file)
@@ -970,7 +970,7 @@ func parseQuery(m Values, query string) (err error) {
 // Encode encodes the values into “URL encoded” form
 // ("bar=baz&foo=quux") sorted by key.
 func (v Values) Encode() string {
-       if v == nil {
+       if len(v) == 0 {
                return ""
        }
        var buf strings.Builder
index 23c5c581c5a7d0e440e959bf529c4fce52000a93..4aa20bb95feb0bdf2cb5cba2f3e7330e55588e89 100644 (file)
@@ -1072,6 +1072,7 @@ type EncodeQueryTest struct {
 
 var encodeQueryTests = []EncodeQueryTest{
        {nil, ""},
+       {Values{}, ""},
        {Values{"q": {"puppies"}, "oe": {"utf8"}}, "oe=utf8&q=puppies"},
        {Values{"q": {"dogs", "&", "7"}}, "q=dogs&q=%26&q=7"},
        {Values{