From 2c98773c8c3fa62467d3cee596abe56dea5abc4e Mon Sep 17 00:00:00 2001
From: Joe Zou <yixian.zou@gmail.com>
Date: Mon, 27 Jan 2020 20:22:25 +0800
Subject: [PATCH] fix review comment

---
 cluster/router/chain/chain.go            |  4 ++--
 cluster/router/match/match_utils.go      |  4 ++--
 cluster/router/match/match_utils_test.go | 16 ++++++++--------
 registry/directory/directory.go          |  8 --------
 4 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/cluster/router/chain/chain.go b/cluster/router/chain/chain.go
index 89be81567..4ca596886 100644
--- a/cluster/router/chain/chain.go
+++ b/cluster/router/chain/chain.go
@@ -52,7 +52,7 @@ func (c RouterChain) Route(invoker []protocol.Invoker, url *common.URL, invocati
 	return finalInvokers
 }
 func (c RouterChain) AddRouters(routers []router.Router) {
-	newRouters := make([]router.Router, 0)
+	newRouters := make([]router.Router, 0, len(c.builtinRouters)+len(routers))
 	newRouters = append(newRouters, c.builtinRouters...)
 	newRouters = append(newRouters, routers...)
 	sortRouter(newRouters)
@@ -64,7 +64,7 @@ func NewRouterChain(url *common.URL) (*RouterChain, error) {
 	if len(routerFactories) == 0 {
 		return nil, perrors.Errorf("Illegal route rule!")
 	}
-	routers := make([]router.Router, 0)
+	routers := make([]router.Router, 0, len(routerFactories))
 	for key, routerFactory := range routerFactories {
 		r, err := routerFactory().Router(url)
 		if r == nil || err != nil {
diff --git a/cluster/router/match/match_utils.go b/cluster/router/match/match_utils.go
index cc2d3cafe..636f330a8 100644
--- a/cluster/router/match/match_utils.go
+++ b/cluster/router/match/match_utils.go
@@ -29,10 +29,10 @@ func IsMatchGlobalPattern(pattern string, value string, param *common.URL) bool
 	if param != nil && strings.HasPrefix(pattern, "$") {
 		pattern = param.GetRawParam(pattern[1:])
 	}
-	return IsMatchInternalPattern(pattern, value)
+	return isMatchInternalPattern(pattern, value)
 }
 
-func IsMatchInternalPattern(pattern string, value string) bool {
+func isMatchInternalPattern(pattern string, value string) bool {
 	if "*" == pattern {
 		return true
 	}
diff --git a/cluster/router/match/match_utils_test.go b/cluster/router/match/match_utils_test.go
index 7ce550fb8..1048b3bae 100644
--- a/cluster/router/match/match_utils_test.go
+++ b/cluster/router/match/match_utils_test.go
@@ -31,14 +31,14 @@ import (
 )
 
 func TestIsMatchInternalPattern(t *testing.T) {
-	assert.Equal(t, true, IsMatchInternalPattern("*", "value"))
-	assert.Equal(t, true, IsMatchInternalPattern("", ""))
-	assert.Equal(t, false, IsMatchInternalPattern("", "value"))
-	assert.Equal(t, true, IsMatchInternalPattern("value", "value"))
-	assert.Equal(t, true, IsMatchInternalPattern("v*", "value"))
-	assert.Equal(t, true, IsMatchInternalPattern("*ue", "value"))
-	assert.Equal(t, true, IsMatchInternalPattern("*e", "value"))
-	assert.Equal(t, true, IsMatchInternalPattern("v*e", "value"))
+	assert.Equal(t, true, isMatchInternalPattern("*", "value"))
+	assert.Equal(t, true, isMatchInternalPattern("", ""))
+	assert.Equal(t, false, isMatchInternalPattern("", "value"))
+	assert.Equal(t, true, isMatchInternalPattern("value", "value"))
+	assert.Equal(t, true, isMatchInternalPattern("v*", "value"))
+	assert.Equal(t, true, isMatchInternalPattern("*ue", "value"))
+	assert.Equal(t, true, isMatchInternalPattern("*e", "value"))
+	assert.Equal(t, true, isMatchInternalPattern("v*e", "value"))
 }
 
 func TestIsMatchGlobPattern(t *testing.T) {
diff --git a/registry/directory/directory.go b/registry/directory/directory.go
index 2b2f8503a..3af5e0ca1 100644
--- a/registry/directory/directory.go
+++ b/registry/directory/directory.go
@@ -138,14 +138,6 @@ func (dir *registryDirectory) refreshInvokers(res *registry.ServiceEvent) {
 				urls = append(urls, v.(*common.URL))
 			}
 
-			for _, v := range dirUrl.GetBackupUrls() {
-				p := v.Protocol
-				category := v.GetParam(constant.CATEGORY_KEY, constant.PROVIDERS_CATEGORY)
-				if strings.EqualFold(category, constant.ROUTERS_CATEGORY) || strings.EqualFold(constant.ROUTE_PROTOCOL, p) {
-					urls = append(urls, v)
-				}
-			}
-
 			if len(urls) > 0 {
 				routers := toRouters(urls)
 				logger.Infof("Init file condition router success, size: %v", len(routers))
-- 
GitLab