mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Improve Path#add performance with big arrays
This commit is contained in:
parent
f673542640
commit
d12b99e252
1 changed files with 7 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue