Skip to content

Commit

Permalink
Line rendering - avoid spread operator on large arrays (#4173)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
  • Loading branch information
mvaligursky and Martin Valigursky authored Apr 4, 2022
1 parent 4e13e5b commit 6bac479
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/scene/immediate/immediate-batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ class ImmediateBatch {
addLinesArrays(positions, color) {

// positions
this.positions.push(...positions);
const destPos = this.positions;
for (let i = 0; i < positions.length; i += 3) {
destPos.push(positions[i], positions[i + 1], positions[i + 2]);
}

// colors
const destCol = this.colors;
if (color.length) {
// multi colored line
destCol.push(...color);
for (let i = 0; i < color.length; i += 4) {
destCol.push(color[i], color[i + 1], color[i + 2], color[i + 3]);
}
} else {
// single colored line
const count = positions.length / 3;
Expand Down

0 comments on commit 6bac479

Please sign in to comment.