Skip to content

Commit

Permalink
Optimize URL#addParameters method to reuse existing methods (#8005)
Browse files Browse the repository at this point in the history
  • Loading branch information
BurningCN committed Jun 8, 2021
1 parent ab4de5c commit ed88f43
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
Expand Up @@ -1244,18 +1244,10 @@ public URL addParametersIfAbsent(Map<String, String> parameters) {
}

public URL addParameters(String... pairs) {
if (pairs == null || pairs.length == 0) {
if (ArrayUtils.isEmpty(pairs)) {
return this;
}
if (pairs.length % 2 != 0) {
throw new IllegalArgumentException("Map pairs can not be odd number.");
}
Map<String, String> map = new HashMap<>();
int len = pairs.length / 2;
for (int i = 0; i < len; i++) {
map.put(pairs[2 * i], pairs[2 * i + 1]);
}
return addParameters(map);
return addParameters(CollectionUtils.toStringMap(pairs));
}

public URL addParameterString(String query) {
Expand Down

0 comments on commit ed88f43

Please sign in to comment.