RFR: 8300929: Avoid unnecessary array fill after creation in java.awt.image

Andrey Turbanov aturbanov at openjdk.org
Tue Jan 24 18:31:12 UTC 2023


On Tue, 24 Jan 2023 16:25:46 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:

>> No need to fill elements of array with default values if it was just created. Java guarantees that all elements of numeric array have default values after allocations - 0.
>
> src/java.desktop/share/classes/java/awt/image/Raster.java line 372:
> 
>> 370:         for (int i = 0; i < bands; i++) {
>> 371:             bankIndices[i] = i;
>> 372:             bandOffsets[i] = 0;
> 
> I suggest to comment this line and adding a comment like "0 zero is the default value not need to be set"

I'm not really fan of commented out code.
What if I add a comment to the array declaration itself?

int[] bandOffsets = new int[bands]; // by default have 0 values

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

PR: https://git.openjdk.org/jdk/pull/12147



More information about the client-libs-dev mailing list