Skip to content

Commit 1ce0fd9

Browse files
committed
avoid allocations
1 parent 428a27b commit 1ce0fd9

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

‎src/main/java/robaho/net/httpserver/ExchangeImpl.java‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -340,21 +340,21 @@ else if (http10) {
340340
static final String colonSpace = ": ";
341341
static final String CRNL = "\r\n";
342342

343+
private static void outputAscii(String s,OutputStream os) throws IOException {
344+
os.write(s.getBytes(ISO_CHARSET));
345+
}
346+
343347
void writeHeaders(Headers map, OutputStream os) throws IOException {
344-
StringBuilder sb = new StringBuilder(128*map.size());
345-
Set<Map.Entry<String, List<String>>> entries = map.entrySet();
346-
for (Map.Entry<String, List<String>> entry : entries) {
348+
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
347349
String key = entry.getKey();
348-
List<String> values = entry.getValue();
349-
for (String val : values) {
350-
sb.append(Objects.requireNonNull(key));
351-
sb.append(colonSpace);
352-
sb.append(Objects.requireNonNull(val));
353-
sb.append(CRNL);
350+
for (String val : entry.getValue()) {
351+
outputAscii(key,os);
352+
outputAscii(colonSpace,os);
353+
outputAscii(val,os);
354+
outputAscii(CRNL,os);
354355
}
355356
}
356-
sb.append(CRNL);
357-
os.write(sb.toString().getBytes(ISO_CHARSET));
357+
outputAscii(CRNL,os);
358358
}
359359

360360
public InetSocketAddress getRemoteAddress() {

0 commit comments

Comments
 (0)