mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Merge pull request #1534 from sasensi/Fix_#1493_Path#add_crashes_whith_1000000_segments
Fix #1493 Path#add crashes whith 1000000 segments
This commit is contained in:
commit
a148e61129
2 changed files with 18 additions and 2 deletions
|
@ -404,8 +404,15 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
this._updateSelection(segment, 0, segment._selection);
|
this._updateSelection(segment, 0, segment._selection);
|
||||||
}
|
}
|
||||||
if (append) {
|
if (append) {
|
||||||
// Append them all at the end by using push
|
// Append them all at the end.
|
||||||
segments.push.apply(segments, segs);
|
// 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 {
|
} else {
|
||||||
// Insert somewhere else
|
// Insert somewhere else
|
||||||
segments.splice.apply(segments, [index, 0].concat(segs));
|
segments.splice.apply(segments, [index, 0].concat(segs));
|
||||||
|
|
|
@ -611,3 +611,12 @@ test('Path#arcTo(from, through, to); where from, through and to all share the sa
|
||||||
}
|
}
|
||||||
equals(error != null, true, 'We expect this arcTo() command to throw an error');
|
equals(error != null, true, 'We expect this arcTo() command to throw an error');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('#1493 Path#add with 1000000 segments', function() {
|
||||||
|
var path = new Path();
|
||||||
|
for (var i = 0; i < 1000000; i++) {
|
||||||
|
path.add(new Point(0, 0));
|
||||||
|
}
|
||||||
|
path.clone();
|
||||||
|
expect(0);
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue