8300929: Avoid unnecessary array fill after creation in java.awt.image
Reviewed-by: attila, serb, aivanov
This commit is contained in:
parent
7f313b0cef
commit
406021ad58
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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) {
|
if (numBands <= 0) {
|
||||||
throw new IllegalArgumentException("numBands must be > 0");
|
throw new IllegalArgumentException("numBands must be > 0");
|
||||||
}
|
}
|
||||||
int[] bandOffsets = new int[numBands];
|
return new int[numBands];
|
||||||
for (int i=0; i < numBands; i++) {
|
|
||||||
bandOffsets[i] = 0;
|
|
||||||
}
|
|
||||||
return bandOffsets;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int[] createIndicesArray(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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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:
|
case DataBuffer.TYPE_BYTE:
|
||||||
{
|
{
|
||||||
byte[] bpixel = new byte[numComponents];
|
byte[] bpixel = new byte[numComponents];
|
||||||
for (int i = 0; i < numColorComponents; i++) {
|
|
||||||
bpixel[i] = 0;
|
|
||||||
}
|
|
||||||
if (supportsAlpha) {
|
if (supportsAlpha) {
|
||||||
bpixel[numColorComponents] =
|
bpixel[numColorComponents] =
|
||||||
(byte) ((1 << nBits[numColorComponents]) - 1);
|
(byte) ((1 << nBits[numColorComponents]) - 1);
|
||||||
@ -535,9 +532,6 @@ public class ComponentColorModel extends ColorModel {
|
|||||||
case DataBuffer.TYPE_USHORT:
|
case DataBuffer.TYPE_USHORT:
|
||||||
{
|
{
|
||||||
short[] uspixel = new short[numComponents];
|
short[] uspixel = new short[numComponents];
|
||||||
for (int i = 0; i < numColorComponents; i++) {
|
|
||||||
uspixel[i] = 0;
|
|
||||||
}
|
|
||||||
if (supportsAlpha) {
|
if (supportsAlpha) {
|
||||||
uspixel[numColorComponents] =
|
uspixel[numColorComponents] =
|
||||||
(short) ((1 << nBits[numColorComponents]) - 1);
|
(short) ((1 << nBits[numColorComponents]) - 1);
|
||||||
@ -552,9 +546,6 @@ public class ComponentColorModel extends ColorModel {
|
|||||||
case DataBuffer.TYPE_INT:
|
case DataBuffer.TYPE_INT:
|
||||||
{
|
{
|
||||||
int[] ipixel = new int[numComponents];
|
int[] ipixel = new int[numComponents];
|
||||||
for (int i = 0; i < numColorComponents; i++) {
|
|
||||||
ipixel[i] = 0;
|
|
||||||
}
|
|
||||||
if (supportsAlpha) {
|
if (supportsAlpha) {
|
||||||
ipixel[numColorComponents] =
|
ipixel[numColorComponents] =
|
||||||
((1 << nBits[numColorComponents]) - 1);
|
((1 << nBits[numColorComponents]) - 1);
|
||||||
@ -569,9 +560,6 @@ public class ComponentColorModel extends ColorModel {
|
|||||||
case DataBuffer.TYPE_SHORT:
|
case DataBuffer.TYPE_SHORT:
|
||||||
{
|
{
|
||||||
short[] spixel = new short[numComponents];
|
short[] spixel = new short[numComponents];
|
||||||
for (int i = 0; i < numColorComponents; i++) {
|
|
||||||
spixel[i] = 0;
|
|
||||||
}
|
|
||||||
if (supportsAlpha) {
|
if (supportsAlpha) {
|
||||||
spixel[numColorComponents] = 32767;
|
spixel[numColorComponents] = 32767;
|
||||||
}
|
}
|
||||||
@ -2486,7 +2474,6 @@ public class ComponentColorModel extends ColorModel {
|
|||||||
} else {
|
} else {
|
||||||
if (zpixel == null) {
|
if (zpixel == null) {
|
||||||
zpixel = new byte[numComponents];
|
zpixel = new byte[numComponents];
|
||||||
java.util.Arrays.fill(zpixel, (byte) 0);
|
|
||||||
}
|
}
|
||||||
raster.setDataElements(rX, rY, zpixel);
|
raster.setDataElements(rX, rY, zpixel);
|
||||||
}
|
}
|
||||||
@ -2514,7 +2501,6 @@ public class ComponentColorModel extends ColorModel {
|
|||||||
} else {
|
} else {
|
||||||
if (zpixel == null) {
|
if (zpixel == null) {
|
||||||
zpixel = new short[numComponents];
|
zpixel = new short[numComponents];
|
||||||
java.util.Arrays.fill(zpixel, (short) 0);
|
|
||||||
}
|
}
|
||||||
raster.setDataElements(rX, rY, zpixel);
|
raster.setDataElements(rX, rY, zpixel);
|
||||||
}
|
}
|
||||||
@ -2541,7 +2527,6 @@ public class ComponentColorModel extends ColorModel {
|
|||||||
} else {
|
} else {
|
||||||
if (zpixel == null) {
|
if (zpixel == null) {
|
||||||
zpixel = new int[numComponents];
|
zpixel = new int[numComponents];
|
||||||
java.util.Arrays.fill(zpixel, 0);
|
|
||||||
}
|
}
|
||||||
raster.setDataElements(rX, rY, zpixel);
|
raster.setDataElements(rX, rY, zpixel);
|
||||||
}
|
}
|
||||||
@ -2568,7 +2553,6 @@ public class ComponentColorModel extends ColorModel {
|
|||||||
} else {
|
} else {
|
||||||
if (zpixel == null) {
|
if (zpixel == null) {
|
||||||
zpixel = new short[numComponents];
|
zpixel = new short[numComponents];
|
||||||
java.util.Arrays.fill(zpixel, (short) 0);
|
|
||||||
}
|
}
|
||||||
raster.setDataElements(rX, rY, zpixel);
|
raster.setDataElements(rX, rY, zpixel);
|
||||||
}
|
}
|
||||||
@ -2593,7 +2577,6 @@ public class ComponentColorModel extends ColorModel {
|
|||||||
} else {
|
} else {
|
||||||
if (zpixel == null) {
|
if (zpixel == null) {
|
||||||
zpixel = new float[numComponents];
|
zpixel = new float[numComponents];
|
||||||
java.util.Arrays.fill(zpixel, 0.0f);
|
|
||||||
}
|
}
|
||||||
raster.setDataElements(rX, rY, zpixel);
|
raster.setDataElements(rX, rY, zpixel);
|
||||||
}
|
}
|
||||||
@ -2618,7 +2601,6 @@ public class ComponentColorModel extends ColorModel {
|
|||||||
} else {
|
} else {
|
||||||
if (zpixel == null) {
|
if (zpixel == null) {
|
||||||
zpixel = new double[numComponents];
|
zpixel = new double[numComponents];
|
||||||
java.util.Arrays.fill(zpixel, 0.0);
|
|
||||||
}
|
}
|
||||||
raster.setDataElements(rX, rY, zpixel);
|
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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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.");
|
throw new IllegalArgumentException("Unsupported dataType.");
|
||||||
}
|
}
|
||||||
bankIndices = new int[numBands];
|
bankIndices = new int[numBands];
|
||||||
for (int i=0; i<numBands; i++) {
|
|
||||||
bankIndices[i] = 0;
|
|
||||||
}
|
|
||||||
verify();
|
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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -1212,7 +1212,6 @@ public class DirectColorModel extends PackedColorModel {
|
|||||||
} else {
|
} else {
|
||||||
if (zpixel == null) {
|
if (zpixel == null) {
|
||||||
zpixel = new int[numComponents];
|
zpixel = new int[numComponents];
|
||||||
java.util.Arrays.fill(zpixel, 0);
|
|
||||||
}
|
}
|
||||||
raster.setPixel(rX, rY, zpixel);
|
raster.setPixel(rX, rY, zpixel);
|
||||||
}
|
}
|
||||||
@ -1235,7 +1234,6 @@ public class DirectColorModel extends PackedColorModel {
|
|||||||
} else {
|
} else {
|
||||||
if (zpixel == null) {
|
if (zpixel == null) {
|
||||||
zpixel = new int[numComponents];
|
zpixel = new int[numComponents];
|
||||||
java.util.Arrays.fill(zpixel, 0);
|
|
||||||
}
|
}
|
||||||
raster.setPixel(rX, rY, zpixel);
|
raster.setPixel(rX, rY, zpixel);
|
||||||
}
|
}
|
||||||
@ -1258,7 +1256,6 @@ public class DirectColorModel extends PackedColorModel {
|
|||||||
} else {
|
} else {
|
||||||
if (zpixel == null) {
|
if (zpixel == null) {
|
||||||
zpixel = new int[numComponents];
|
zpixel = new int[numComponents];
|
||||||
java.util.Arrays.fill(zpixel, 0);
|
|
||||||
}
|
}
|
||||||
raster.setPixel(rX, rY, zpixel);
|
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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -33,8 +33,8 @@
|
|||||||
******************************************************************
|
******************************************************************
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
|
|
||||||
package java.awt.image;
|
package java.awt.image;
|
||||||
|
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
|
||||||
@ -366,11 +366,10 @@ public class Raster {
|
|||||||
" be greater than 0");
|
" be greater than 0");
|
||||||
}
|
}
|
||||||
int[] bankIndices = new int[bands];
|
int[] bankIndices = new int[bands];
|
||||||
int[] bandOffsets = new int[bands];
|
|
||||||
for (int i = 0; i < bands; i++) {
|
for (int i = 0; i < bands; i++) {
|
||||||
bankIndices[i] = i;
|
bankIndices[i] = i;
|
||||||
bandOffsets[i] = 0;
|
|
||||||
}
|
}
|
||||||
|
int[] bandOffsets = new int[bands]; // leave default 0 values
|
||||||
|
|
||||||
return createBandedRaster(dataType, w, h, w,
|
return createBandedRaster(dataType, w, h, w,
|
||||||
bankIndices, bandOffsets,
|
bankIndices, bandOffsets,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user