This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/develop by this push:
     new 8ffc312  Opt: optimize url to string
     new 168f944  Merge pull request #531 from watermelo/featue/optUrlToString
8ffc312 is described below

commit 8ffc312461c1131aa716d9dd7eda44e472217e46
Author: watermelo <[email protected]>
AuthorDate: Thu May 21 13:33:57 2020 +0800

    Opt: optimize url to string
---
 common/url.go | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/common/url.go b/common/url.go
index a70ac7d..fd23324 100644
--- a/common/url.go
+++ b/common/url.go
@@ -18,7 +18,6 @@
 package common
 
 import (
-       "bytes"
        "encoding/base64"
        "fmt"
        "math"
@@ -292,20 +291,20 @@ func isMatchCategory(category1 string, category2 string) 
bool {
 }
 
 func (c URL) String() string {
-       var buildString string
+       var buf strings.Builder
        if len(c.Username) == 0 && len(c.Password) == 0 {
-               buildString = fmt.Sprintf(
+               buf.WriteString(fmt.Sprintf(
                        "%s://%s:%s%s?",
-                       c.Protocol, c.Ip, c.Port, c.Path)
+                       c.Protocol, c.Ip, c.Port, c.Path))
        } else {
-               buildString = fmt.Sprintf(
+               buf.WriteString(fmt.Sprintf(
                        "%s://%s:%s@%s:%s%s?",
-                       c.Protocol, c.Username, c.Password, c.Ip, c.Port, 
c.Path)
+                       c.Protocol, c.Username, c.Password, c.Ip, c.Port, 
c.Path))
        }
        c.paramsLock.RLock()
-       buildString += c.params.Encode()
+       buf.WriteString(c.params.Encode())
        c.paramsLock.RUnlock()
-       return buildString
+       return buf.String()
 }
 
 // Key ...
@@ -322,7 +321,7 @@ func (c URL) ServiceKey() string {
        if intf == "" {
                return ""
        }
-       buf := &bytes.Buffer{}
+       var buf strings.Builder
        group := c.GetParam(constant.GROUP_KEY, "")
        if group != "" {
                buf.WriteString(group)
@@ -347,7 +346,7 @@ func (c *URL) ColonSeparatedKey() string {
        if intf == "" {
                return ""
        }
-       buf := &bytes.Buffer{}
+       var buf strings.Builder
        buf.WriteString(intf)
        buf.WriteString(":")
        version := c.GetParam(constant.VERSION_KEY, "")

Reply via email to