mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 14:10:14 -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) {
|
if (append) {
|
||||||
// Append them all at the end.
|
// Append them all at the end.
|
||||||
// Use a loop as it is the best way to handle big arrays (see #1493)
|
// Use a loop as the best way to handle big arrays (see #1493).
|
||||||
for (var i = 0, l = segs.length; i < l; i++) {
|
// Set future array length before the loop for better performances.
|
||||||
segments.push(segs[i]);
|
var originalLength = segments.length;
|
||||||
|
var offsetLength = segs.length;
|
||||||
|
segments.length += offsetLength;
|
||||||
|
for (var i = 0; i < offsetLength; i++) {
|
||||||
|
segments[originalLength + i] = segs[i];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Insert somewhere else
|
// Insert somewhere else
|
||||||
|
|
Loading…
Reference in a new issue