GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Allocate less in QueryStringDecoder.addParam for typical use case (#1… · netty/netty@893ea2e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-http/src/main/java/io/netty/handler/codec/http
    • QueryStringDecoder.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-http/src/main/java/io/netty/handler/codec/http/QueryStringDecoder.java‎

Copy file name to clipboardExpand all lines: codec-http/src/main/java/io/netty/handler/codec/http/QueryStringDecoder.java
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ private Map<String, List<String>> decodeParams(String s, int from, Charset chars
248248
if (s.charAt(from) == '?') {
249249
from++;
250250
}
251-
Map<String, List<String>> params = new LinkedHashMap<String, List<String>>();
251+
Map<String, List<String>> params = new LinkedHashMap<>();
252252
int nameStart = from;
253253
int valueStart = -1;
254254
int i;
@@ -298,10 +298,15 @@ private boolean addParam(String s, int nameStart, int valueStart, int valueEnd,
298298
String value = decodeComponent(s, valueStart, valueEnd, charset, htmlQueryDecoding);
299299
List<String> values = params.get(name);
300300
if (values == null) {
301-
values = new ArrayList<String>(1); // Often there's only 1 value.
302-
params.put(name, values);
301+
params.put(name, Collections.singletonList(value));
302+
} else if (values instanceof ArrayList) {
303+
values.add(value);
304+
} else {
305+
List<String> newValues = new ArrayList<>(2);
306+
newValues.add(values.get(0));
307+
newValues.add(value);
308+
params.put(name, newValues);
303309
}
304-
values.add(value);
305310
return true;
306311
}
307312

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.