From d12b99e252114a204c7d000f9045e9f8cc864380 Mon Sep 17 00:00:00 2001 From: sasensi Date: Wed, 3 Oct 2018 08:59:36 +0200 Subject: [PATCH] Improve Path#add performance with big arrays --- src/path/Path.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/path/Path.js b/src/path/Path.js index c270a2ca..c516176b 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -405,9 +405,13 @@ var Path = PathItem.extend(/** @lends Path# */{ } if (append) { // Append them all at the end. - // Use a loop as it is the best way to handle big arrays (see #1493) - for (var i = 0, l = segs.length; i < l; i++) { - segments.push(segs[i]); + // Use a loop as the best way to handle big arrays (see #1493). + // Set future array length before the loop for better performances. + var originalLength = segments.length; + var offsetLength = segs.length; + segments.length += offsetLength; + for (var i = 0; i < offsetLength; i++) { + segments[originalLength + i] = segs[i]; } } else { // Insert somewhere else