chan-dx commented on code in PR #4628:
URL: https://github.com/apache/solr/pull/4628#discussion_r3637078616
##########
solr/solrj/src/java/org/apache/solr/common/params/SolrParams.java:
##########
@@ -459,19 +460,16 @@ public NamedList<Object> toNamedList() {
*/
public String toQueryString() {
final Charset charset = StandardCharsets.UTF_8;
- final StringBuilder sb = new StringBuilder(128);
- boolean first = true;
+
+ var output = new StringJoiner("&", "?", "");
+ output.setEmptyValue("");
for (final Iterator<String> it = getParameterNamesIterator();
it.hasNext(); ) {
- final String name = it.next(), nameEnc = URLEncoder.encode(name,
charset);
+ final String name = it.next();
for (String val : getParams(name)) {
- sb.append(first ? '?' : '&')
- .append(nameEnc)
- .append('=')
- .append(URLEncoder.encode(val, charset));
- first = false;
+ output.add(URLEncoder.encode(name, charset) + "=" +
URLEncoder.encode(val, charset));
Review Comment:
```suggestion
final String name = it.next();
final String nameEnc = URLEncoder.encode(name, charset);
for (String val : getParams(name)) {
output.add(nameEnc + "=" + URLEncoder.encode(val, charset));
```
**Just a minor suggestion:** `encode(name)` currently runs once per value,
that could hoist it out of the inner loop (just like the old code did) so it
only runs once per name, avoiding redundant re-encoding for multi-valued
params. It doesn't change output, just avoid some unnecessary work.
--
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]