chaojixinren commented on code in PR #3488:
URL: https://github.com/apache/dubbo-go/pull/3488#discussion_r3569696673
##########
common/url.go:
##########
@@ -1163,28 +1184,97 @@ 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 lookup set for excluded keys to avoid repeated scans
+ // and to skip materializing two full maps just for comparison
+ excludeSet := make(map[string]struct{}, len(excludes))
+ for _, k := range excludes {
+ excludeSet[k] = struct{}{}
}
- if len(leftMap) != len(rightMap) {
+ isExcluded := func(key string) bool {
+ _, ok := excludeSet[key]
+ return 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
}
- for lk, lv := range leftMap {
- if rv, ok := rightMap[lk]; !ok {
- return false
- } else if lv != rv {
+ // Compare Location (host:port)
+ if left.Location != right.Location {
+ hostExcluded := isExcluded("host")
+ portExcluded := isExcluded("port")
Review Comment:
已补上,统一放到 common/constant/key.go:新增 HostKey/UsernameKey/PasswordKey,复用已有的
PortKey/PathKey/ProtocolKey。IsEquals 里的字面量已全部替换为常量。
--
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]