Skip to content

Commit 406021a

Browse files
author
Andrey Turbanov
committed
8300929: Avoid unnecessary array fill after creation in java.awt.image
Reviewed-by: attila, serb, aivanov
1 parent 7f313b0 commit 406021a

File tree

5 files changed

+8
-37
lines changed

5 files changed

+8
-37
lines changed

src/java.desktop/share/classes/java/awt/image/BandedSampleModel.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -874,11 +874,7 @@ private static int[] createOffsetArray(int numBands) {
874874
if (numBands <= 0) {
875875
throw new IllegalArgumentException("numBands must be > 0");
876876
}
877-
int[] bandOffsets = new int[numBands];
878-
for (int i=0; i < numBands; i++) {
879-
bandOffsets[i] = 0;
880-
}
881-
return bandOffsets;
877+
return new int[numBands];
882878
}
883879

884880
private static int[] createIndicesArray(int numBands) {

src/java.desktop/share/classes/java/awt/image/ComponentColorModel.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -518,9 +518,6 @@ private void initScale() {
518518
case DataBuffer.TYPE_BYTE:
519519
{
520520
byte[] bpixel = new byte[numComponents];
521-
for (int i = 0; i < numColorComponents; i++) {
522-
bpixel[i] = 0;
523-
}
524521
if (supportsAlpha) {
525522
bpixel[numColorComponents] =
526523
(byte) ((1 << nBits[numColorComponents]) - 1);
@@ -535,9 +532,6 @@ private void initScale() {
535532
case DataBuffer.TYPE_USHORT:
536533
{
537534
short[] uspixel = new short[numComponents];
538-
for (int i = 0; i < numColorComponents; i++) {
539-
uspixel[i] = 0;
540-
}
541535
if (supportsAlpha) {
542536
uspixel[numColorComponents] =
543537
(short) ((1 << nBits[numColorComponents]) - 1);
@@ -552,9 +546,6 @@ private void initScale() {
552546
case DataBuffer.TYPE_INT:
553547
{
554548
int[] ipixel = new int[numComponents];
555-
for (int i = 0; i < numColorComponents; i++) {
556-
ipixel[i] = 0;
557-
}
558549
if (supportsAlpha) {
559550
ipixel[numColorComponents] =
560551
((1 << nBits[numColorComponents]) - 1);
@@ -569,9 +560,6 @@ private void initScale() {
569560
case DataBuffer.TYPE_SHORT:
570561
{
571562
short[] spixel = new short[numComponents];
572-
for (int i = 0; i < numColorComponents; i++) {
573-
spixel[i] = 0;
574-
}
575563
if (supportsAlpha) {
576564
spixel[numColorComponents] = 32767;
577565
}
@@ -2486,7 +2474,6 @@ public ColorModel coerceData (WritableRaster raster,
24862474
} else {
24872475
if (zpixel == null) {
24882476
zpixel = new byte[numComponents];
2489-
java.util.Arrays.fill(zpixel, (byte) 0);
24902477
}
24912478
raster.setDataElements(rX, rY, zpixel);
24922479
}
@@ -2514,7 +2501,6 @@ public ColorModel coerceData (WritableRaster raster,
25142501
} else {
25152502
if (zpixel == null) {
25162503
zpixel = new short[numComponents];
2517-
java.util.Arrays.fill(zpixel, (short) 0);
25182504
}
25192505
raster.setDataElements(rX, rY, zpixel);
25202506
}
@@ -2541,7 +2527,6 @@ public ColorModel coerceData (WritableRaster raster,
25412527
} else {
25422528
if (zpixel == null) {
25432529
zpixel = new int[numComponents];
2544-
java.util.Arrays.fill(zpixel, 0);
25452530
}
25462531
raster.setDataElements(rX, rY, zpixel);
25472532
}
@@ -2568,7 +2553,6 @@ public ColorModel coerceData (WritableRaster raster,
25682553
} else {
25692554
if (zpixel == null) {
25702555
zpixel = new short[numComponents];
2571-
java.util.Arrays.fill(zpixel, (short) 0);
25722556
}
25732557
raster.setDataElements(rX, rY, zpixel);
25742558
}
@@ -2593,7 +2577,6 @@ public ColorModel coerceData (WritableRaster raster,
25932577
} else {
25942578
if (zpixel == null) {
25952579
zpixel = new float[numComponents];
2596-
java.util.Arrays.fill(zpixel, 0.0f);
25972580
}
25982581
raster.setDataElements(rX, rY, zpixel);
25992582
}
@@ -2618,7 +2601,6 @@ public ColorModel coerceData (WritableRaster raster,
26182601
} else {
26192602
if (zpixel == null) {
26202603
zpixel = new double[numComponents];
2621-
java.util.Arrays.fill(zpixel, 0.0);
26222604
}
26232605
raster.setDataElements(rX, rY, zpixel);
26242606
}

src/java.desktop/share/classes/java/awt/image/ComponentSampleModel.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -152,9 +152,6 @@ public ComponentSampleModel(int dataType,
152152
throw new IllegalArgumentException("Unsupported dataType.");
153153
}
154154
bankIndices = new int[numBands];
155-
for (int i=0; i<numBands; i++) {
156-
bankIndices[i] = 0;
157-
}
158155
verify();
159156
}
160157

src/java.desktop/share/classes/java/awt/image/DirectColorModel.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1995, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1212,7 +1212,6 @@ public final ColorModel coerceData (WritableRaster raster,
12121212
} else {
12131213
if (zpixel == null) {
12141214
zpixel = new int[numComponents];
1215-
java.util.Arrays.fill(zpixel, 0);
12161215
}
12171216
raster.setPixel(rX, rY, zpixel);
12181217
}
@@ -1235,7 +1234,6 @@ public final ColorModel coerceData (WritableRaster raster,
12351234
} else {
12361235
if (zpixel == null) {
12371236
zpixel = new int[numComponents];
1238-
java.util.Arrays.fill(zpixel, 0);
12391237
}
12401238
raster.setPixel(rX, rY, zpixel);
12411239
}
@@ -1258,7 +1256,6 @@ public final ColorModel coerceData (WritableRaster raster,
12581256
} else {
12591257
if (zpixel == null) {
12601258
zpixel = new int[numComponents];
1261-
java.util.Arrays.fill(zpixel, 0);
12621259
}
12631260
raster.setPixel(rX, rY, zpixel);
12641261
}

src/java.desktop/share/classes/java/awt/image/Raster.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -33,8 +33,8 @@
3333
******************************************************************
3434
******************************************************************/
3535

36-
3736
package java.awt.image;
37+
3838
import java.awt.Rectangle;
3939
import java.awt.Point;
4040

@@ -366,11 +366,10 @@ public static WritableRaster createBandedRaster(int dataType,
366366
" be greater than 0");
367367
}
368368
int[] bankIndices = new int[bands];
369-
int[] bandOffsets = new int[bands];
370369
for (int i = 0; i < bands; i++) {
371370
bankIndices[i] = i;
372-
bandOffsets[i] = 0;
373371
}
372+
int[] bandOffsets = new int[bands]; // leave default 0 values
374373

375374
return createBandedRaster(dataType, w, h, w,
376375
bankIndices, bandOffsets,

0 commit comments

Comments
 (0)