Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Sources/Common/Core/CellArray/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,16 @@ function vtkCellArray(publicAPI, model) {
cellPointIds = cell;
}
const cellId = publicAPI.getNumberOfCells();
publicAPI.insertNextTuples([cellPointIds.length, ...cellPointIds]);
// Build the [count, ...pointIds] record without the spread operator, which
// would walk the iterator protocol and allocate an extra intermediate for
// every inserted cell.
const numberOfPoints = cellPointIds.length;
const cellRecord = new Array(numberOfPoints + 1);
cellRecord[0] = numberOfPoints;
for (let i = 0; i < numberOfPoints; ++i) {
cellRecord[i + 1] = cellPointIds[i];
}
publicAPI.insertNextTuples(cellRecord);
Comment thread
finetjul marked this conversation as resolved.
// By computing the number of cells earlier, we made sure that numberOfCells is defined
++model.numberOfCells;
if (model.cellSizes != null) {
Expand Down
13 changes: 7 additions & 6 deletions Sources/Common/DataModel/CellLinks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ function vtkCellLinks(publicAPI, model) {
* will be built.
*/
publicAPI.allocate = (numLinks, ext = 1000) => {
model.array = Array(numLinks)
.fill()
.map(() => ({
ncells: 0,
cells: null,
}));
// Populate in a single pass. Array(n).fill().map() walks the array three
// times (allocate sparse, fill, map) before producing the link objects.
const array = new Array(numLinks);
for (let i = 0; i < numLinks; ++i) {
array[i] = { ncells: 0, cells: null };
}
model.array = array;
model.extend = ext;
model.maxId = -1;
};
Expand Down
Loading
Loading