In the current implementation of `String.join(CharSequence, Iterable)`, the temp array `elems` is always initialized with a length of 8. It will cause many array recreations when the `Iterable` contains more than 8 elements. Furthermore, it's very common that an `Iterable` is also a `Collection`. So if the `Iterable` is an instance of `Collection`, the initial length of the array can be `((Collection<?>)elements).size()`. It will not change the current behavior even if the `Collection` is modified asynchronously.
I don't know whether this change requires a CSR request. ------------- Commit messages: - Optimize String.join(CharSequence,Iterable) Changes: https://git.openjdk.org/jdk/pull/13383/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=13383&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8305774 Stats: 2 lines in 1 file changed: 1 ins; 0 del; 1 mod Patch: https://git.openjdk.org/jdk/pull/13383.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/13383/head:pull/13383 PR: https://git.openjdk.org/jdk/pull/13383