Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(sheet): fix some performance issue (#4664)

VicKunb9e740298fe7
diff --git a/packages/core/src/common/boolean.ts b/packages/core/src/common/boolean.ts
index 0f953b9b29..87851aff95 100644
--- a/packages/core/src/common/boolean.ts
+++ b/packages/core/src/common/boolean.ts
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+const BooleanStringSet = new Set(['true', 'false']);
export function isBooleanString(str: string): boolean {
- return ['true', 'false'].includes(str.toLowerCase());
+ return BooleanStringSet.has(str.toLowerCase());
}
diff --git a/packages/core/src/shared/generate.ts b/packages/core/src/shared/generate.ts
index ab9ea1643f..289a7a95cd 100644
--- a/packages/core/src/shared/generate.ts
+++ b/packages/core/src/shared/generate.ts
@@ -19,9 +19,8 @@
* @param val The number or string to be judged
* @returns Result
*/
-const $blank = /\s/g;
-export function isRealNum(val: string | number | boolean) {
- if (val === null || val.toString().replace($blank, '') === '') {
+export function isRealNum(val: string | number | boolean): boolean {
+ if (val === null || val === undefined) {
return false;
}
@@ -29,8 +28,17 @@ export function isRealNum(val: string | number | boolean) {
return false;
}
- if (!isNaN(val as number)) {
- return true;
+ if (typeof val === 'number') {
+ return !isNaN(val);
}
+
+ if (typeof val === 'string') {
+ const trimmedVal = val.trim();
+ if (trimmedVal === '') {
+ return false;
+ }
+ return !isNaN(Number(trimmedVal));
+ }
+
return false;
}
diff --git a/packages/sheets-ui/src/controllers/status-bar.controller.ts b/packages/sheets-ui/src/controllers/status-bar.controller.ts
index 7965b94499..9c932cdb0e 100644
--- a/packages/sheets-ui/src/controllers/status-bar.controller.ts
+++ b/packages/sheets-ui/src/controllers/status-bar.controller.ts
@@ -157,11 +157,19 @@ export class StatusBarController extends Disposable {
);
}, 100);
+ const _statisticsMovingHandler = debounce((selections: ISelectionWithStyle[]) => {
+ const primary = selections[selections.length - 1]?.primary;
+ this._calculateSelection(
+ selections.map((selection) => selection.range),
+ primary
+ );
+ }, 500);
+
this.disposeWithMe(
toDisposable(
this._selectionManagerService.selectionMoving$.subscribe((selections) => {
if (selections) {
- _statisticsHandler(selections);
+ _statisticsMovingHandler(selections);
}
})
)