On Thu, 21 Sep 2023 14:32:46 GMT, Claes Redestad <[email protected]> wrote:
> `URLEncoder` currently appends chars that needs encoding into a > `java.io.CharArrayWriter`, converts that to a `String`, uses > `String::getBytes` to get the encoded bytes and then appends these bytes in a > escaped manner to the output stream. This is somewhat inefficient. > > This PR replaces the `CharArrayWriter` with a reusable `CharBuffer` + > `ByteBuffer` pair. This allows us to encode to the output `StringBuilder` in > small chunks, with greatly reduced allocation as a result. > > The exact size of the buffers is an open question, but generally it seems > that a tiny buffer wins by virtue of allocating less, and that the per chunk > overheads are relatively small. This pull request has now been integrated. Changeset: c24c66db Author: Claes Redestad <[email protected]> URL: https://git.openjdk.org/jdk/commit/c24c66db97a52371875a63862f85ea5c2010d5a7 Stats: 96 lines in 4 files changed: 77 ins; 14 del; 5 mod 8316681: Rewrite URLEncoder.encode to use small reusable buffers Reviewed-by: dfuchs, rriggs ------------- PR: https://git.openjdk.org/jdk/pull/15865
