Skip to content

Commit

Permalink
perf: Optimize SlickGrid handleSelectedRangesChanged by using Set (#1061
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ghiscoding authored Sep 14, 2024
1 parent 0d07e60 commit 8ff354b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/slick.grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3479,8 +3479,12 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e

if (this.simpleArrayEquals(previousSelectedRows, this.selectedRows)) {
const caller = ne?.detail?.caller ?? 'click';
const newSelectedAdditions = this.getSelectedRows().filter((i) => previousSelectedRows.indexOf(i) < 0);
const newSelectedDeletions = previousSelectedRows.filter((i) => this.getSelectedRows().indexOf(i) < 0);
// Use Set for faster performance
const selectedRowsSet = new Set(this.getSelectedRows());
const previousSelectedRowsSet = new Set(previousSelectedRows);

const newSelectedAdditions = Array.from(selectedRowsSet).filter(i => !previousSelectedRowsSet.has(i));
const newSelectedDeletions = Array.from(previousSelectedRowsSet).filter(i => !selectedRowsSet.has(i));

this.trigger(this.onSelectedRowsChanged, {
rows: this.getSelectedRows(),
Expand Down

0 comments on commit 8ff354b

Please sign in to comment.