From 23f3097f8417cdb2d97c984f5183d95a22065ec0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=BCrg=20Lehni?= <juerg@scratchdisk.com>
Date: Fri, 22 Jul 2016 14:21:35 +0200
Subject: [PATCH] Facilitate code minification in PathIterator.

---
 src/path/PathIterator.js | 22 ++++++++++++----------
 test/tests/Path.js       |  1 -
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/src/path/PathIterator.js b/src/path/PathIterator.js
index f30bed2b..24b2f94d 100644
--- a/src/path/PathIterator.js
+++ b/src/path/PathIterator.js
@@ -107,25 +107,28 @@ var PathIterator = Base.extend({
     _get: function(offset) {
         // Make sure we're not beyond the requested offset already. Search the
         // start position backwards from where to then process the loop below.
-        var i, j = this.index;
+        var parts = this.parts,
+            length = parts.length,
+            start,
+            i, j = this.index;
         for (;;) {
             i = j;
-            if (!j || this.parts[--j].offset < offset)
+            if (!j || parts[--j].offset < offset)
                 break;
         }
         // Find the part that succeeds the given offset, then interpolate
         // with the previous part
-        for (var l = this.parts.length; i < l; i++) {
-            var part = this.parts[i];
+        for (; i < length; i++) {
+            var part = parts[i];
             if (part.offset >= offset) {
                 // Found the right part, remember current position
                 this.index = i;
                 // Now get the previous part so we can linearly interpolate
                 // the curve parameter
-                var prev = this.parts[i - 1];
-                // Make sure we only use the previous parameter value if its
-                // for the same curve, by checking index. Use 0 otherwise.
-                var prevTime = prev && prev.index === part.index ? prev.time : 0,
+                var prev = parts[i - 1],
+                    // Make sure we only use the previous parameter value if its
+                    // for the same curve, by checking index. Use 0 otherwise.
+                    prevTime = prev && prev.index === part.index ? prev.time : 0,
                     prevOffset = prev ? prev.offset : 0;
                 return {
                     index: part.index,
@@ -136,9 +139,8 @@ var PathIterator = Base.extend({
             }
         }
         // If we're still here, return last one
-        var part = this.parts[this.parts.length - 1];
         return {
-            index: part.index,
+            index: parts[length - 1].index,
             time: 1
         };
     },
diff --git a/test/tests/Path.js b/test/tests/Path.js
index 0f22c0a0..74119ae9 100644
--- a/test/tests/Path.js
+++ b/test/tests/Path.js
@@ -402,7 +402,6 @@ test('path.curves on closed paths', function() {
     equals(path.curves.toString(), "{ point1: { x: 100, y: 0 }, handle1: { x: 55.22847, y: 0 }, handle2: { x: 0, y: -55.22847 }, point2: { x: 200, y: 100 } },{ point1: { x: 200, y: 100 }, handle1: { x: 0, y: 55.22847 }, handle2: { x: 55.22847, y: 0 }, point2: { x: 100, y: 200 } },{ point1: { x: 100, y: 200 }, handle1: { x: -55.22847, y: 0 }, handle2: { x: -55.22847, y: 0 }, point2: { x: 100, y: 0 } }");
 });
 
-
 test('path.flatten(maxDistance)', function() {
     var path = new Path.Circle(new Size(80, 50), 35);