mirror of
https://github.com/golang/go
synced 2024-11-26 16:16:57 -07:00
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: 0530b439db
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>
This commit is contained in:
parent
995ec5c85b
commit
ac85f2bedd
@ -970,7 +970,7 @@ func parseQuery(m Values, query string) (err error) {
|
|||||||
// Encode encodes the values into “URL encoded” form
|
// Encode encodes the values into “URL encoded” form
|
||||||
// ("bar=baz&foo=quux") sorted by key.
|
// ("bar=baz&foo=quux") sorted by key.
|
||||||
func (v Values) Encode() string {
|
func (v Values) Encode() string {
|
||||||
if v == nil {
|
if len(v) == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
var buf strings.Builder
|
var buf strings.Builder
|
||||||
|
@ -1072,6 +1072,7 @@ type EncodeQueryTest struct {
|
|||||||
|
|
||||||
var encodeQueryTests = []EncodeQueryTest{
|
var encodeQueryTests = []EncodeQueryTest{
|
||||||
{nil, ""},
|
{nil, ""},
|
||||||
|
{Values{}, ""},
|
||||||
{Values{"q": {"puppies"}, "oe": {"utf8"}}, "oe=utf8&q=puppies"},
|
{Values{"q": {"puppies"}, "oe": {"utf8"}}, "oe=utf8&q=puppies"},
|
||||||
{Values{"q": {"dogs", "&", "7"}}, "q=dogs&q=%26&q=7"},
|
{Values{"q": {"dogs", "&", "7"}}, "q=dogs&q=%26&q=7"},
|
||||||
{Values{
|
{Values{
|
||||||
|
Loading…
Reference in New Issue
Block a user