Skip to content

Commit 7fb4dbe

Browse files
Reuse map if it is a SortedMap instead of creating a new one
1 parent ec5fb7d commit 7fb4dbe

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

  • extractor/src/main/java/org/schabi/newpipe/extractor/downloader

extractor/src/main/java/org/schabi/newpipe/extractor/downloader/Response.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Collections;
66
import java.util.List;
77
import java.util.Map;
8+
import java.util.SortedMap;
89
import java.util.TreeMap;
910

1011
/**
@@ -13,7 +14,7 @@
1314
public class Response {
1415
private final int responseCode;
1516
private final String responseMessage;
16-
private final Map<String, List<String>> responseHeaders;
17+
private final SortedMap<String, List<String>> responseHeaders;
1718
private final String responseBody;
1819
private final String latestUrl;
1920

@@ -25,8 +26,12 @@ public Response(final int responseCode,
2526
this.responseCode = responseCode;
2627
this.responseMessage = responseMessage;
2728

28-
this.responseHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
29-
this.responseHeaders.putAll(responseHeaders);
29+
if (responseHeaders instanceof SortedMap) {
30+
this.responseHeaders = (SortedMap<String, List<String>>) responseHeaders;
31+
} else {
32+
this.responseHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
33+
this.responseHeaders.putAll(responseHeaders);
34+
}
3035

3136
this.responseBody = responseBody == null ? "" : responseBody;
3237
this.latestUrl = latestUrl;

0 commit comments

Comments
 (0)