From add10bc3763f39918d5a6b1ef2176e0154e8ecbf Mon Sep 17 00:00:00 2001
From: "xg.gao" <xg.gao@tianrang-inc.com>
Date: Fri, 28 Feb 2020 10:17:12 +0800
Subject: [PATCH] add cap to initialize slice

---
 config/protocol_config.go  |  3 +--
 config/reference_config.go | 10 +++++-----
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/config/protocol_config.go b/config/protocol_config.go
index 586b53165..33de976bc 100644
--- a/config/protocol_config.go
+++ b/config/protocol_config.go
@@ -38,14 +38,13 @@ func (c *ProtocolConfig) Prefix() string {
 }
 
 func loadProtocol(protocolsIds string, protocols map[string]*ProtocolConfig) []*ProtocolConfig {
-	var returnProtocols []*ProtocolConfig
+	returnProtocols := make([]*ProtocolConfig, 0, len(protocols))
 	for _, v := range strings.Split(protocolsIds, ",") {
 		for k, protocol := range protocols {
 			if v == k {
 				returnProtocols = append(returnProtocols, protocol)
 			}
 		}
-
 	}
 	return returnProtocols
 }
diff --git a/config/reference_config.go b/config/reference_config.go
index e8e68a0b1..bd5fc66f6 100644
--- a/config/reference_config.go
+++ b/config/reference_config.go
@@ -101,7 +101,7 @@ func (c *ReferenceConfig) Refer(_ interface{}) {
 	)
 
 	if c.Url != "" {
-		//1. user specified URL, could be peer-to-peer address, or register center's address.
+		// 1. user specified URL, could be peer-to-peer address, or register center's address.
 		urlStrings := gxstrings.RegSplit(c.Url, "\\s*[;]+\\s*")
 		for _, urlStr := range urlStrings {
 			serviceUrl, err := common.NewURL(urlStr)
@@ -121,10 +121,10 @@ func (c *ReferenceConfig) Refer(_ interface{}) {
 			}
 		}
 	} else {
-		//2. assemble SubURL from register center's configuration妯″紡
+		// 2. assemble SubURL from register center's configuration妯″紡
 		c.urls = loadRegistries(c.Registry, consumerConfig.Registries, common.CONSUMER)
 
-		//set url to regUrls
+		// set url to regUrls
 		for _, regUrl := range c.urls {
 			regUrl.SubURL = cfgURL
 		}
@@ -133,7 +133,7 @@ func (c *ReferenceConfig) Refer(_ interface{}) {
 	if len(c.urls) == 1 {
 		c.invoker = extension.GetProtocol(c.urls[0].Protocol).Refer(*c.urls[0])
 	} else {
-		var invokers []protocol.Invoker
+		invokers := make([]protocol.Invoker, 0, len(c.urls))
 		var regUrl *common.URL
 		for _, u := range c.urls {
 			invokers = append(invokers, extension.GetProtocol(u.Protocol).Refer(*u))
@@ -150,7 +150,7 @@ func (c *ReferenceConfig) Refer(_ interface{}) {
 		}
 	}
 
-	//create proxy
+	// create proxy
 	if c.Async {
 		callback := GetCallback(c.id)
 		c.pxy = extension.GetProxyFactory(consumerConfig.ProxyFactory).GetAsyncProxy(c.invoker, callback, cfgURL)
-- 
GitLab