RFR: 8356993: ArrayDeque should use Arrays.fill() instead of for() loops [v2]

ExE Boss duke at openjdk.org
Thu May 15 19:55:53 UTC 2025


On Thu, 15 May 2025 17:46:39 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:

>> Please review this small performance tweak `ArrayDeque`.
>> 
>> `ArrayDeque` has an invariant in which any unused elements in the array must be null. In a couple of places, the code is setting contiguous ranges of elements to null using `for()` loops. This can be both simplified and sped up by using `Arrays.fill()` instead.
>
> Archie Cobbs has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Add benchmark for ArrayDeque.clear().

Note that `Arrays.fill(…)` is simply a `for(…)` loop with an additional range check and is potentially subject to profile pollution due to [JDK‑8015417]:
<https://github.com/openjdk/jdk/blob/c59debb3844d009ac501a48c31822a07f00521e9/src/java.base/share/classes/java/util/Arrays.java#L3449-L3453>

[JDK‑8015417]: https://bugs.openjdk.org/browse/JDK-8015417

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

PR Comment: https://git.openjdk.org/jdk/pull/25237#issuecomment-2884908080


More information about the core-libs-dev mailing list