Skip to content

Commit 1a79dc6

Browse files
committed
Minor performance improvements when parsing query params
1 parent f688376 commit 1a79dc6

File tree

1 file changed

+4
-3
lines changed
  • protocol/src/main/java/org/threadly/litesockets/protocols/http/shared

1 file changed

+4
-3
lines changed

protocol/src/main/java/org/threadly/litesockets/protocols/http/shared/HTTPUtils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ public static Map<String, List<String>> queryToMap(String query) {
8989
Map<String, List<String>> map = new HashMap<>();
9090
if(query.startsWith("?")) {
9191
query = query.substring(1);
92-
} else if (query.contains("?")){
93-
int qpos = query.indexOf("?");
92+
}
93+
int qpos = query.indexOf("?");
94+
if (qpos >= 0){
9495
query = query.substring(qpos+1);
9596
}
9697
String[] tmpQ = query.trim().split("&");
@@ -100,7 +101,7 @@ public static Map<String, List<String>> queryToMap(String query) {
100101
// case where either no `=` or empty key string
101102
continue;
102103
}
103-
List<String> paramValues = map.computeIfAbsent(tmpkv[0], (ignored) -> new ArrayList<>(1));
104+
List<String> paramValues = map.computeIfAbsent(tmpkv[0], (ignored) -> new ArrayList<>(2));
104105
if(tmpkv.length == 1) {
105106
paramValues.add("");
106107
} else {

0 commit comments

Comments
 (0)