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

Reviewed-by: attila, serb, aivanov
This commit is contained in:
Andrey Turbanov 2023-02-03 06:51:54 +00:00
parent 7f313b0cef
commit 406021ad58
5 changed files with 8 additions and 37 deletions

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -874,11 +874,7 @@ public final class BandedSampleModel extends ComponentSampleModel
if (numBands <= 0) {
throw new IllegalArgumentException("numBands must be > 0");
}
int[] bandOffsets = new int[numBands];
for (int i=0; i < numBands; i++) {
bandOffsets[i] = 0;
}
return bandOffsets;
return new int[numBands];
}
private static int[] createIndicesArray(int numBands) {

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -518,9 +518,6 @@ public class ComponentColorModel extends ColorModel {
case DataBuffer.TYPE_BYTE:
{
byte[] bpixel = new byte[numComponents];
for (int i = 0; i < numColorComponents; i++) {
bpixel[i] = 0;
}
if (supportsAlpha) {
bpixel[numColorComponents] =
(byte) ((1 << nBits[numColorComponents]) - 1);
@ -535,9 +532,6 @@ public class ComponentColorModel extends ColorModel {
case DataBuffer.TYPE_USHORT:
{
short[] uspixel = new short[numComponents];
for (int i = 0; i < numColorComponents; i++) {
uspixel[i] = 0;
}
if (supportsAlpha) {
uspixel[numColorComponents] =
(short) ((1 << nBits[numColorComponents]) - 1);
@ -552,9 +546,6 @@ public class ComponentColorModel extends ColorModel {
case DataBuffer.TYPE_INT:
{
int[] ipixel = new int[numComponents];
for (int i = 0; i < numColorComponents; i++) {
ipixel[i] = 0;
}
if (supportsAlpha) {
ipixel[numColorComponents] =
((1 << nBits[numColorComponents]) - 1);
@ -569,9 +560,6 @@ public class ComponentColorModel extends ColorModel {
case DataBuffer.TYPE_SHORT:
{
short[] spixel = new short[numComponents];
for (int i = 0; i < numColorComponents; i++) {
spixel[i] = 0;
}
if (supportsAlpha) {
spixel[numColorComponents] = 32767;
}
@ -2486,7 +2474,6 @@ public class ComponentColorModel extends ColorModel {
} else {
if (zpixel == null) {
zpixel = new byte[numComponents];
java.util.Arrays.fill(zpixel, (byte) 0);
}
raster.setDataElements(rX, rY, zpixel);
}
@ -2514,7 +2501,6 @@ public class ComponentColorModel extends ColorModel {
} else {
if (zpixel == null) {
zpixel = new short[numComponents];
java.util.Arrays.fill(zpixel, (short) 0);
}
raster.setDataElements(rX, rY, zpixel);
}
@ -2541,7 +2527,6 @@ public class ComponentColorModel extends ColorModel {
} else {
if (zpixel == null) {
zpixel = new int[numComponents];
java.util.Arrays.fill(zpixel, 0);
}
raster.setDataElements(rX, rY, zpixel);
}
@ -2568,7 +2553,6 @@ public class ComponentColorModel extends ColorModel {
} else {
if (zpixel == null) {
zpixel = new short[numComponents];
java.util.Arrays.fill(zpixel, (short) 0);
}
raster.setDataElements(rX, rY, zpixel);
}
@ -2593,7 +2577,6 @@ public class ComponentColorModel extends ColorModel {
} else {
if (zpixel == null) {
zpixel = new float[numComponents];
java.util.Arrays.fill(zpixel, 0.0f);
}
raster.setDataElements(rX, rY, zpixel);
}
@ -2618,7 +2601,6 @@ public class ComponentColorModel extends ColorModel {
} else {
if (zpixel == null) {
zpixel = new double[numComponents];
java.util.Arrays.fill(zpixel, 0.0);
}
raster.setDataElements(rX, rY, zpixel);
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -152,9 +152,6 @@ public class ComponentSampleModel extends SampleModel
throw new IllegalArgumentException("Unsupported dataType.");
}
bankIndices = new int[numBands];
for (int i=0; i<numBands; i++) {
bankIndices[i] = 0;
}
verify();
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -1212,7 +1212,6 @@ public class DirectColorModel extends PackedColorModel {
} else {
if (zpixel == null) {
zpixel = new int[numComponents];
java.util.Arrays.fill(zpixel, 0);
}
raster.setPixel(rX, rY, zpixel);
}
@ -1235,7 +1234,6 @@ public class DirectColorModel extends PackedColorModel {
} else {
if (zpixel == null) {
zpixel = new int[numComponents];
java.util.Arrays.fill(zpixel, 0);
}
raster.setPixel(rX, rY, zpixel);
}
@ -1258,7 +1256,6 @@ public class DirectColorModel extends PackedColorModel {
} else {
if (zpixel == null) {
zpixel = new int[numComponents];
java.util.Arrays.fill(zpixel, 0);
}
raster.setPixel(rX, rY, zpixel);
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -33,8 +33,8 @@
******************************************************************
******************************************************************/
package java.awt.image;
import java.awt.Rectangle;
import java.awt.Point;
@ -366,11 +366,10 @@ public class Raster {
" be greater than 0");
}
int[] bankIndices = new int[bands];
int[] bandOffsets = new int[bands];
for (int i = 0; i < bands; i++) {
bankIndices[i] = i;
bandOffsets[i] = 0;
}
int[] bandOffsets = new int[bands]; // leave default 0 values
return createBandedRaster(dataType, w, h, w,
bankIndices, bandOffsets,