Alanxtl commented on code in PR #3282:
URL: https://github.com/apache/dubbo-go/pull/3282#discussion_r3004005975
##########
common/url.go:
##########
@@ -102,6 +96,7 @@ type URL struct {
Port string
PrimitiveURL string
+ primitiveTS string
Review Comment:
what does TS stand for?
##########
common/url.go:
##########
@@ -653,9 +661,29 @@ func (c *URL) GetNonDefaultParam(s string) (string, bool) {
return r, r != ""
}
-// GetParams gets values
+// GetParams gets values.
+// Deprecated: use CopyParams instead.
func (c *URL) GetParams() url.Values {
- return c.params
+ return c.CopyParams()
+}
+
+// CopyParams returns a deep copy of params.
+func (c *URL) CopyParams() url.Values {
+ c.paramsLock.RLock()
+ defer c.paramsLock.RUnlock()
+
+ if c.params == nil {
+ return nil
+ }
+
+ params := make(url.Values, len(c.params))
+ for k, vs := range c.params {
+ copied := make([]string, len(vs))
+ copy(copied, vs)
+ params[k] = copied
+ }
+
+ return params
}
Review Comment:
every time I want to `GetParams()`, CopyParams() will generate a new map, it
is consuming
##########
common/url.go:
##########
@@ -596,6 +590,20 @@ func (c *URL) GetAttribute(key string) (any, bool) {
return r, ok
}
+func (c *URL) DeleteAttribute(key string) {
+ c.attributesLock.Lock()
+ defer c.attributesLock.Unlock()
+ if c.attributes != nil {
+ delete(c.attributes, key)
+ }
+}
+
+func (c *URL) ClearAttributes() {
+ c.attributesLock.Lock()
+ defer c.attributesLock.Unlock()
+ c.attributes = nil
Review Comment:
isn't it better to set `c.attributes` into a empty map instead of `nil` ?
--
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]