Skip to content

Commit ac85f2b

Browse files
ash2kgopherbot
authored andcommitted
net/url: use quick path in URL.Encode() on empty map
Make url.Values.Encode() slightly more efficient when url.Values is an empty but non-nil map. Change-Id: I7f205cc7e67526a1fa0035eab4773cec5e0f2c99 GitHub-Last-Rev: 0530b43 GitHub-Pull-Request: #63836 Reviewed-on: https://go-review.googlesource.com/c/go/+/538637 Reviewed-by: Damien Neil <[email protected]> Reviewed-by: Bryan Mills <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Damien Neil <[email protected]>
1 parent 995ec5c commit ac85f2b

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/net/url/url.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ func parseQuery(m Values, query string) (err error) {
970970
// Encode encodes the values into “URL encoded” form
971971
// ("bar=baz&foo=quux") sorted by key.
972972
func (v Values) Encode() string {
973-
if v == nil {
973+
if len(v) == 0 {
974974
return ""
975975
}
976976
var buf strings.Builder

src/net/url/url_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,7 @@ type EncodeQueryTest struct {
10721072

10731073
var encodeQueryTests = []EncodeQueryTest{
10741074
{nil, ""},
1075+
{Values{}, ""},
10751076
{Values{"q": {"puppies"}, "oe": {"utf8"}}, "oe=utf8&q=puppies"},
10761077
{Values{"q": {"dogs", "&", "7"}}, "q=dogs&q=%26&q=7"},
10771078
{Values{

0 commit comments

Comments
 (0)