ywxzm03 commented on code in PR #3402:
URL: https://github.com/apache/dubbo-go/pull/3402#discussion_r3402699246


##########
common/url.go:
##########
@@ -1019,23 +1038,76 @@ 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)
+       // Build a small lookup set for excluded keys to avoid repeated linear 
scans
+       // and to avoid materializing two full maps just for comparison.
+       var excludeSet map[string]struct{}
+       if len(excludes) > 0 {
+               excludeSet = make(map[string]struct{}, len(excludes))
+               for _, k := range excludes {
+                       excludeSet[k] = struct{}{}
+               }
        }
 
-       if len(leftMap) != len(rightMap) {
-               return false
+       isExcluded := func(key string) bool {
+               if excludeSet == nil {
+                       return false
+               }
+               _, ok := excludeSet[key]
+               return ok
        }
 
-       for lk, lv := range leftMap {
-               if rv, ok := rightMap[lk]; !ok {
+       // Compare scalar fields directly.
+       if left.Protocol != right.Protocol && !isExcluded(PROTOCOL) {
+               return false
+       }
+       if left.Username != right.Username && !isExcluded("username") {
+               return false
+       }
+       if left.Password != right.Password && !isExcluded("password") {
+               return false
+       }
+       if left.Path != right.Path && !isExcluded("path") {
+               return false
+       }
+       if left.Location != right.Location {
+               if isExcluded("host") && isExcluded("port") {
+                       // Both excluded, skip Location comparison
+               } else if isExcluded("host") || isExcluded("port") {
+                       // Only one side of host:port excluded — fall through 
to param comparison
+               } else {
                        return false
-               } else if lv != rv {
+               }
+       }
+
+       // Compare params directly without materializing maps.
+       // Build left params (excluding filtered keys), then verify right 
matches.
+       leftParams := make(map[string]string)

Review Comment:
   这里可以做个容量预估,len(left.params) 就有了



-- 
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