On Wed, 8 Feb 2023 00:07:14 GMT, Claes Redestad <[email protected]> wrote:
>> This patch adds special-cases to `Arrays.copyOf` and `Arrays.copyOfRange` to
>> clone arrays when `newLength` or range inputs span the input array. This
>> helps eliminate range checks and has been verified to help various String
>> operations. Example:
>>
>> Baseline
>>
>> Benchmark (size) Mode Cnt
>> Score Error Units
>> StringConstructor.newStringFromArray 7 avgt 15
>> 16.817 ± 0.369 ns/op
>> StringConstructor.newStringFromArrayWithCharset 7 avgt 15
>> 16.866 ± 0.449 ns/op
>> StringConstructor.newStringFromArrayWithCharsetName 7 avgt 15
>> 22.198 ± 0.396 ns/op
>>
>> Patch:
>>
>> Benchmark (size) Mode Cnt
>> Score Error Units
>> StringConstructor.newStringFromArray 7 avgt 15
>> 14.666 ± 0.336 ns/op
>> StringConstructor.newStringFromArrayWithCharset 7 avgt 15
>> 14.582 ± 0.288 ns/op
>> StringConstructor.newStringFromArrayWithCharsetName 7 avgt 15
>> 20.339 ± 0.328 ns/op
>
> Claes Redestad has updated the pull request incrementally with one additional
> commit since the last revision:
>
> Minimize, force inline, generalize
src/java.base/share/classes/java/util/Arrays.java line 3594:
> 3592: public static int[] copyOf(int[] original, int newLength) {
> 3593: if (newLength == original.length) {
> 3594: return original.clone();
I am curious about the use of `clone ` for some primitive array types and
`copyOf` using `System.arraycopy` in other types (e.g. `byte[]`). Do these
types optimize differently or hit different intrinsics depending on primitive
type? Is there difference in array zeroing?
-------------
PR: https://git.openjdk.org/jdk/pull/12453