Skip to content

Commit 223f6a6

Browse files
authored
perf: preparation avoid duplicate copying of cells (#217)
Cells are all already copied on previous `.map` invokation, there's no need to copy them again here.
1 parent 9c4af05 commit 223f6a6

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/datamanager.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,19 @@ export default class DataManager {
205205
}
206206

207207
prepareRow(row, meta) {
208-
const baseRowCell = {
209-
rowIndex: meta.rowIndex,
210-
indent: meta.indent
211-
};
212-
213208
row = row
214209
.map((cell, i) => this.prepareCell(cell, i))
215-
.map(cell => Object.assign({}, baseRowCell, cell));
210+
.map(cell => {
211+
// Following code is equivalent but avoids memory allocation and copying.
212+
// return Object.assign({rowIndex: meta.rowIndex, indent: meta.indent}, cell)
213+
if (cell.rowIndex == null) {
214+
cell.rowIndex = meta.rowIndex;
215+
}
216+
if (cell.indent == null) {
217+
cell.indent = meta.indent;
218+
}
219+
return cell;
220+
});
216221

217222
// monkey patched in array object
218223
row.meta = meta;

0 commit comments

Comments
 (0)