AlexStocks commented on code in PR #3402:
URL: https://github.com/apache/dubbo-go/pull/3402#discussion_r3410654905
##########
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 {
Review Comment:
[P1] 这里把 `host` / `port` 的排除逻辑挂在整条 `Location` 上了:只传 `host` 或只传 `port`
时,`left.Location != right.Location` 也会直接落入“放行”分支,另一半地址差异被一并忽略。旧实现是按 `ToMap()`
删除单个 key 比较,两个字段的排除语义是独立的。请分别比较 host/port,或保留原来的按键删除语义。
--
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]