On Tue, 4 Nov 2025 20:03:28 GMT, jengebr <[email protected]> wrote:

>>> cl4es: Consider simplifying this to reduce code duplication:
>> 
>> or even simpler?
>> 
>> 
>> Object[] a = c.getClass() == ArrayList.class ? ((ArrayList<?>)c).elementData 
>> : a.toArray();
>> int newNum = a.length;
>> ...
>> 
>> 
>> 
>>> jengebr: Interestingly, this hurt the fast-path about 5%, but the control 
>>> case about 35%.
>> 
>> what is the control case, LinkedList.addAll() ?
>
> No, ArrayList.addAll(LinkedList).  This is the slow path that ideally will 
> perform the same as before this change - and the initial change achieves 
> that.  Rewriting to reduce duplication increased runtime of both the 
> optimized and control.
> 
> I'll benchmark your suggestion as well.

That variant is incorrect since `size <= a.length`, potentially adding a 
surprising tail of `null` elements to the list.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28116#discussion_r2491936650

Reply via email to