chaojixinren commented on code in PR #3488:
URL: https://github.com/apache/dubbo-go/pull/3488#discussion_r3587285359


##########
common/url.go:
##########
@@ -1163,26 +1195,91 @@ func IsEquals(left *URL, right *URL, excludes 
...string) bool {
                return false
        }
 
-       leftMap := left.ToMap()
-       rightMap := right.ToMap()
-       for _, exclude := range excludes {
-               delete(leftMap, exclude)
-               delete(rightMap, exclude)
+       excluded := newKeySet(excludes)
+       return equalScalars(left, right, excluded) &&
+               equalLocation(left.Location, right.Location, excluded) &&
+               equalParams(left, right, excluded)
+}
+
+// equalScalars compares the non-param scalar fields of two URLs, skipping any 
excluded key.
+func equalScalars(left, right *URL, excluded keySet) bool {
+       scalars := []struct {
+               key         string
+               left, right string
+       }{
+               {constant.ProtocolKey, left.Protocol, right.Protocol},
+               {constant.UsernameKey, left.Username, right.Username},
+               {constant.PasswordKey, left.Password, right.Password},
+               {constant.PathKey, left.Path, right.Path},
        }
+       for _, s := range scalars {
+               if s.left != s.right && !excluded.contains(s.key) {
+                       return false
+               }
+       }
+       return true
+}
 
-       if len(leftMap) != len(rightMap) {
+// equalLocation compares two "host:port" locations, skipping host and/or port 
when excluded.
+func equalLocation(left, right string, excluded keySet) bool {
+       if left == right {
+               return true
+       }
+
+       hostExcluded := excluded.contains(constant.HostKey)
+       portExcluded := excluded.contains(constant.PortKey)
+       if hostExcluded && portExcluded {
+               return true
+       }
+
+       leftHost, leftPort := parseLocation(left)
+       rightHost, rightPort := parseLocation(right)
+       if !hostExcluded && leftHost != rightHost {
+               return false
+       }
+       if !portExcluded && leftPort != rightPort {
                return false
        }
+       return true
+}
 
-       for lk, lv := range leftMap {
-               if rv, ok := rightMap[lk]; !ok {
-                       return false
-               } else if lv != rv {
+// equalParams compares the params of two URLs, skipping excluded keys. It 
avoids
+// materializing both maps by snapshotting only the left side and streaming 
the right.
+func equalParams(left, right *URL, excluded keySet) bool {
+       leftParams := make(map[string]string)
+       left.RangeParams(func(key, value string) bool {

Review Comment:
   已修改,麻烦重新review一下



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to