Skip to content

Commit

Permalink
use calcChain map instead of array for search
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchit3008 committed May 8, 2024
1 parent 8b15a84 commit dafa973
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions packages/core/src/modules/formula.ts
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,8 @@ export function insertUpdateFunctionGroup(
ctx: Context,
r: number,
c: number,
id?: string
id?: string,
calcChainSet?: Set<string>
) {
if (_.isNil(id)) {
id = ctx.currentSheetId;
Expand All @@ -971,14 +972,18 @@ export function insertUpdateFunctionGroup(
calcChain = [];
}

for (let i = 0; i < calcChain.length; i += 1) {
const calc = calcChain[i];
if (calc.r === r && calc.c === c && calc.id === id) {
// server.saveParam("fc", index, calc, {
// op: "update",
// pos: i,
// });
return;
if (calcChainSet) {
if (calcChainSet.has(`${r}_${c}_${id}`)) return;
} else {
for (let i = 0; i < calcChain.length; i += 1) {
const calc = calcChain[i];
if (calc.r === r && calc.c === c && calc.id === id) {
// server.saveParam("fc", index, calc, {
// op: "update",
// pos: i,
// });
return;
}
}
}

Expand All @@ -1003,6 +1008,7 @@ export function execfunction(
r: number,
c: number,
id?: string,
calcChainSet?: Set<string>,
isrefresh?: boolean,
notInsertFunc?: boolean
) {
Expand Down Expand Up @@ -1162,7 +1168,7 @@ export function execfunction(
}

if (!notInsertFunc) {
insertUpdateFunctionGroup(ctx, r, c, id);
insertUpdateFunctionGroup(ctx, r, c, id, calcChainSet);
}
}

Expand Down Expand Up @@ -1640,6 +1646,11 @@ export function execFunctionGroup(

formulaRunList.reverse();

const calcChainSet = new Set<string>();
calcChains.forEach((item) => {
calcChainSet.add(`${item.r}_${item.c}_${item.id}`);
});

// console.log(formulaObjects, ii)
// console.timeEnd("3");

Expand All @@ -1657,7 +1668,8 @@ export function execFunctionGroup(
calc_funcStr,
formulaCell.r,
formulaCell.c,
formulaCell.id
formulaCell.id,
calcChainSet
);

ctx.groupValuesRefreshData.push({
Expand Down

0 comments on commit dafa973

Please sign in to comment.