Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sheet): add flag to get better performance #3631

Merged
merged 1 commit into from
Sep 29, 2024
Merged
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
30 changes: 23 additions & 7 deletions packages/core/src/sheets/span-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

import type { IRange } from './typedef';
import { LRUMap, Rectangle, Tools } from '../shared';
import { Disposable } from '../shared/lifecycle';
import { RANGE_TYPE } from './typedef';
import type { IRange } from './typedef';

export class SpanModel extends Disposable {
/**
Expand All @@ -32,6 +32,14 @@ export class SpanModel extends Disposable {
* @property Cache for RANGE_TYPE.COLUMN
*/
private _columnCache: Map<number, number> = new Map();
/**
* @property Whether has RANGE_TYPE.ROW
*/
private _hasRow: boolean = false;
/**
* @property Whether has RANGE_TYPE.COLUMN
*/
private _hasColumn: boolean = false;
/**
* @property Whether has RANGE_TYPE.ALL
*/
Expand Down Expand Up @@ -68,6 +76,8 @@ export class SpanModel extends Disposable {
this._allIndex = -1;
this._rangeMap.clear();
this._skeletonCache.clear();
this._hasColumn = false;
this._hasRow = false;
}

private _createCache(mergeData: IRange[]) {
Expand Down Expand Up @@ -100,13 +110,15 @@ export class SpanModel extends Disposable {
const { startRow, endRow } = range;
for (let i = startRow; i <= endRow; i++) {
this._rowCache.set(i, index);
this._hasRow = true;
}
}

private _createColumnCache(range: IRange, index: number) {
const { startColumn, endColumn } = range;
for (let i = startColumn; i <= endColumn; i++) {
this._columnCache.set(i, index);
this._hasColumn = true;
}
}

Expand Down Expand Up @@ -274,14 +286,18 @@ export class SpanModel extends Disposable {
return this._allIndex;
}

const rowValue = this._rowCache.get(row);
if (rowValue !== undefined) {
return rowValue;
if (this._hasRow) {
const rowValue = this._rowCache.get(row);
if (rowValue !== undefined) {
return rowValue;
}
}

const columnValue = this._columnCache.get(column);
if (columnValue !== undefined) {
return columnValue;
if (this._hasColumn) {
const columnValue = this._columnCache.get(column);
if (columnValue !== undefined) {
return columnValue;
}
}

const cellValue = this._cellCache.get(row)?.get(column);
Expand Down
Loading