IG: description tweaks

This commit is contained in:
Bas Leijdekkers
2018-01-23 17:58:03 +01:00
parent 2e3a5d9e6e
commit ffa4af8259
@@ -1,22 +1,22 @@
<html>
<body>
There are two styles to convert collection to array: either using a pre-sized array
There are two styles to convert a collection to an array: either using a pre-sized array
(like <b>c.toArray(new String[c.size()])</b>) or using an empty array (like
<b>c.toArray(new String[0])</b>.
<p>
In older Java versions using pre-sized array was recommended as a reflection
In older Java versions using pre-sized array was recommended, as the reflection
call which is necessary to create an array of proper size was quite slow.
However since late updates of OpenJDK 6 this call was intrinsified making
the performance of the empty array version the same and sometimes even better, comparing
However since late updates of OpenJDK 6 this call was intrinsified, making
the performance of the empty array version the same and sometimes even better, compared
to the pre-sized version. Also passing pre-sized array is dangerous for a concurrent or
synchronized collection as data race is possible between the <b>size</b> and <b>toArray</b>
call which may result in extra nulls at the end of the array if the collection was concurrently
synchronized collection as a data race is possible between the <b>size</b> and <b>toArray</b>
call which may result in extra nulls at the end of the array, if the collection was concurrently
shrunk during the operation.
</p>
<p>
This inspection allows to follow the uniform style: either using an empty array
(which is recommended in modern Java)
or using a pre-sized array (which might be faster in older Java versions or some non-HotSpot based JVMs).
or using a pre-sized array (which might be faster in older Java versions or non-HotSpot based JVMs).
</p>
</body>
</html>