src/java.desktop/share/classes/sun/java2d/marlin/Dasher.java
changeset 50135 793e481c7641
parent 49496 1ea202af7a97
child 57929 13178f7e75d5
--- a/src/java.desktop/share/classes/sun/java2d/marlin/Dasher.java	Mon May 07 13:36:36 2018 -0700
+++ b/src/java.desktop/share/classes/sun/java2d/marlin/Dasher.java	Tue May 08 10:13:21 2018 +0200
@@ -138,8 +138,8 @@
      * @param recycleDashes true to indicate to recycle the given dash array
      * @return this instance
      */
-    Dasher init(final PathConsumer2D out, float[] dash, int dashLen,
-                float phase, boolean recycleDashes)
+    Dasher init(final PathConsumer2D out, final float[] dash, final int dashLen,
+                float phase, final boolean recycleDashes)
     {
         this.out = out;
 
@@ -147,9 +147,10 @@
         int sidx = 0;
         dashOn = true;
 
+        // note: BasicStroke constructor checks dash elements and sum > 0
         float sum = 0.0f;
-        for (float d : dash) {
-            sum += d;
+        for (int i = 0; i < dashLen; i++) {
+            sum += dash[i];
         }
         this.cycleLen = sum;
 
@@ -159,13 +160,13 @@
                 phase = 0.0f;
             } else {
                 int fullcycles = FloatMath.floor_int(-cycles);
-                if ((fullcycles & dash.length & 1) != 0) {
+                if ((fullcycles & dashLen & 1) != 0) {
                     dashOn = !dashOn;
                 }
                 phase += fullcycles * sum;
                 while (phase < 0.0f) {
                     if (--sidx < 0) {
-                        sidx = dash.length - 1;
+                        sidx = dashLen - 1;
                     }
                     phase += dash[sidx];
                     dashOn = !dashOn;
@@ -176,14 +177,14 @@
                 phase = 0.0f;
             } else {
                 int fullcycles = FloatMath.floor_int(cycles);
-                if ((fullcycles & dash.length & 1) != 0) {
+                if ((fullcycles & dashLen & 1) != 0) {
                     dashOn = !dashOn;
                 }
                 phase -= fullcycles * sum;
                 float d;
                 while (phase >= (d = dash[sidx])) {
                     phase -= d;
-                    sidx = (sidx + 1) % dash.length;
+                    sidx = (sidx + 1) % dashLen;
                     dashOn = !dashOn;
                 }
             }