On Tue, 19 Sep 2023 11:16:11 GMT, Glavo <[email protected]> wrote:

>> I mainly made these optimizations:
>> 
>> * Avoid allocating `StringBuilder` when there are no characters in the URL 
>> that need to be encoded;
>> * ~Implement a fast path for UTF-8.~ (Has been removed from this PR)
>> 
>> In addition to improving performance, these optimizations also reduce 
>> temporary objects:
>> 
>> * It no longer allocates any object when there are no characters in the URL 
>> that need to be encoded;
>> * The initial size of StringBuilder is larger to avoid expansion as much as 
>> possible;
>> * ~For UTF-8, the temporary `CharArrayWriter`, strings and byte arrays are 
>> no longer needed.~ (Has been removed from this PR)
>> 
>> I also updated the tests to add more test cases.
>
> Glavo has updated the pull request incrementally with one additional commit 
> since the last revision:
> 
>   Update src/java.base/share/classes/java/net/URLEncoder.java
>   
>   Co-authored-by: Claes Redestad <[email protected]>

src/java.base/share/classes/java/net/URLEncoder.java line 251:

> 249:             if (DONT_NEED_ENCODING.test(c)) {
> 250:                 if (c == ' ') {
> 251:                     c = '+';

The extra test (on every regular character) for space could be moved to a 
separate if at line 255 (and remove space from DONT_NEED_ENCODING). The 
performance improvement might not be noticable but it would remove an anomaly 
from the algorithm.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/15354#discussion_r1330161498

Reply via email to