Copilot commented on code in PR #3134:
URL: https://github.com/apache/dubbo-go/pull/3134#discussion_r2638757826
##########
config_center/zookeeper/impl.go:
##########
@@ -115,7 +115,9 @@ func buildPath(rootPath, subPath string) string {
if !strings.HasPrefix(path, pathSeparator) {
path = pathSeparator + path
}
- path = strings.ReplaceAll(path, "//", "/")
+ for strings.Contains(path, "//") {
+ path = strings.ReplaceAll(path, "//", "/")
+ }
Review Comment:
The loop in the buildPath function is unnecessary and inefficient. The
strings.ReplaceAll function already replaces all occurrences of "//" with "/"
in a single pass. The loop will repeatedly scan the string until no more "//"
patterns exist, but this is redundant since ReplaceAll does this internally.
Consider reverting to the original single ReplaceAll call, or if you need to
handle multiple consecutive slashes like "///", use a more efficient approach
with strings.Replace or a regular expression.
```suggestion
path = strings.ReplaceAll(path, "//", "/")
```
--
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]