Skip to content

Commit 32efcc8

Browse files
committed
PDFBOX-5660: optimize, as suggested by Valery Bokov; closes #390
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1931139 13f79535-47bb-0310-9956-ffa450edef68
1 parent d778782 commit 32efcc8

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType5.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,28 +158,32 @@ private List<ShadedTriangle> createShadedTriangleList(int rowNum, int numPerRow,
158158
{
159159
Point2D[] ps = new Point2D[3]; // array will be shallow-cloned in ShadedTriangle constructor
160160
float[][] cs = new float[3][];
161-
List<ShadedTriangle> list = new ArrayList<>();
161+
List<ShadedTriangle> list = new ArrayList<>((rowNum - 1) * (numPerRow - 1));
162162
for (int i = 0; i < rowNum - 1; i++)
163163
{
164164
for (int j = 0; j < numPerRow - 1; j++)
165165
{
166-
ps[0] = latticeArray[i][j].point;
167-
ps[1] = latticeArray[i][j + 1].point;
168-
ps[2] = latticeArray[i + 1][j].point;
169-
170-
cs[0] = latticeArray[i][j].color;
171-
cs[1] = latticeArray[i][j + 1].color;
172-
cs[2] = latticeArray[i + 1][j].color;
166+
Vertex vertex1 = latticeArray[i][j];
167+
Vertex vertex2 = latticeArray[i][j + 1];
168+
Vertex vertex3 = latticeArray[i + 1][j];
169+
Vertex vertex4 = latticeArray[i + 1][j + 1];
170+
ps[0] = vertex1.point;
171+
ps[1] = vertex2.point;
172+
ps[2] = vertex3.point;
173+
174+
cs[0] = vertex1.color;
175+
cs[1] = vertex2.color;
176+
cs[2] = vertex3.color;
173177

174178
list.add(new ShadedTriangle(ps, cs));
175179

176-
ps[0] = latticeArray[i][j + 1].point;
177-
ps[1] = latticeArray[i + 1][j].point;
178-
ps[2] = latticeArray[i + 1][j + 1].point;
180+
ps[0] = vertex2.point;
181+
ps[1] = vertex3.point;
182+
ps[2] = vertex4.point;
179183

180-
cs[0] = latticeArray[i][j + 1].color;
181-
cs[1] = latticeArray[i + 1][j].color;
182-
cs[2] = latticeArray[i + 1][j + 1].color;
184+
cs[0] = vertex2.color;
185+
cs[1] = vertex3.color;
186+
cs[2] = vertex4.color;
183187

184188
list.add(new ShadedTriangle(ps, cs));
185189
}

0 commit comments

Comments
 (0)