Browse Source

fix(formula efficiency up): speed up

master
liuyang 5 years ago
parent
commit
d05151f474
  1. 8
      src/controllers/sheetmanage.js
  2. 168
      src/global/formula.js

8
src/controllers/sheetmanage.js

@ -976,13 +976,19 @@ const sheetmanage = {
return; return;
} }
let _this = this; let _this = this;
if(index==Store.currentSheetIndex){
return;
}
if(server.allowUpdate){ if(server.allowUpdate){
$("#luckysheet-cell-main #luckysheet-multipleRange-show").empty(); $("#luckysheet-cell-main #luckysheet-multipleRange-show").empty();
server.multipleIndex = 0; server.multipleIndex = 0;
} }
$('#luckysheet-filter-selected-sheet' + Store.currentSheetIndex + ', #luckysheet-filter-options-sheet' + Store.currentSheetIndex).hide(); $('#luckysheet-filter-selected-sheet' + Store.currentSheetIndex + ', #luckysheet-filter-options-sheet' + Store.currentSheetIndex).hide();
$('#luckysheet-filter-selected-sheet' + index + ', #luckysheet-filter-options-sheet' + index).show(); $('#luckysheet-filter-selected-sheet' + index + ', #luckysheet-filter-options-sheet' + index).show();

168
src/global/formula.js

@ -680,7 +680,7 @@ const luckysheetformula = {
let sheettxt = "", let sheettxt = "",
rangetxt = "", rangetxt = "",
sheetIndex = -1, sheetIndex = null,
sheetdata = null; sheetdata = null;
let luckysheetfile = getluckysheetfile(); let luckysheetfile = getluckysheetfile();
@ -1279,7 +1279,7 @@ const luckysheetformula = {
if(getObjType(value) == "string" && value.slice(0, 1) == "=" && value.length > 1){ if(getObjType(value) == "string" && value.slice(0, 1) == "=" && value.length > 1){
let v = _this.execfunction(value, r, c, true); let v = _this.execfunction(value, r, c, true);
isRunExecFunction = false;
curv = _this.execFunctionGroupData[r][c]; curv = _this.execFunctionGroupData[r][c];
curv.f = v[2]; curv.f = v[2];
@ -1307,7 +1307,7 @@ const luckysheetformula = {
if(getObjType(valueFunction) == "string" && valueFunction.slice(0, 1) == "=" && valueFunction.length > 1){ if(getObjType(valueFunction) == "string" && valueFunction.slice(0, 1) == "=" && valueFunction.length > 1){
let v = _this.execfunction(valueFunction, r, c, true); let v = _this.execfunction(valueFunction, r, c, true);
isRunExecFunction = false;
// get v/m/ct // get v/m/ct
curv = _this.execFunctionGroupData[r][c]; curv = _this.execFunctionGroupData[r][c];
@ -1337,7 +1337,7 @@ const luckysheetformula = {
if(getObjType(valueFunction) == "string" && valueFunction.slice(0, 1) == "=" && valueFunction.length > 1){ if(getObjType(valueFunction) == "string" && valueFunction.slice(0, 1) == "=" && valueFunction.length > 1){
let v = _this.execfunction(valueFunction, r, c, true); let v = _this.execfunction(valueFunction, r, c, true);
isRunExecFunction = false;
// get v/m/ct // get v/m/ct
curv = _this.execFunctionGroupData[r][c]; curv = _this.execFunctionGroupData[r][c];
@ -1392,7 +1392,7 @@ const luckysheetformula = {
else { else {
if(getObjType(value) == "string" && value.slice(0, 1) == "=" && value.length > 1){ if(getObjType(value) == "string" && value.slice(0, 1) == "=" && value.length > 1){
let v = _this.execfunction(value, r, c, true); let v = _this.execfunction(value, r, c, true);
isRunExecFunction = false;
value = { value = {
"v": v[1], "v": v[1],
"f": v[2] "f": v[2]
@ -1419,7 +1419,7 @@ const luckysheetformula = {
if(getObjType(valueFunction) == "string" && valueFunction.slice(0, 1) == "=" && valueFunction.length > 1){ if(getObjType(valueFunction) == "string" && valueFunction.slice(0, 1) == "=" && valueFunction.length > 1){
let v = _this.execfunction(valueFunction, r, c, true); let v = _this.execfunction(valueFunction, r, c, true);
isRunExecFunction = false;
// value = { // value = {
// "v": v[1], // "v": v[1],
// "f": v[2] // "f": v[2]
@ -1894,7 +1894,7 @@ const luckysheetformula = {
else if (orient == "l" && !freezonFuc[1]) { else if (orient == "l" && !freezonFuc[1]) {
col -= step; col -= step;
} }
else if (!freezonFuc[0]) { else if (orient == "d" && !freezonFuc[0]) {
row += step; row += step;
} }
@ -1966,7 +1966,7 @@ const luckysheetformula = {
col[1] -= step; col[1] -= step;
} }
} }
else { else if(orient=="d") {
if (!freezonFuc0[0]) { if (!freezonFuc0[0]) {
row[0] += step; row[0] += step;
} }
@ -4150,7 +4150,7 @@ const luckysheetformula = {
setluckysheetfile(luckysheetfile); setluckysheetfile(luckysheetfile);
}, },
isFunctionRangeSave: false, isFunctionRangeSave: false,
isFunctionRange1: function(txt, r, c) { isFunctionRangeSimple: function(txt, r, c,dynamicArray_compute) {
let _this = this; let _this = this;
if (_this.operatorjson == null) { if (_this.operatorjson == null) {
@ -4182,7 +4182,7 @@ const luckysheetformula = {
} }
let luckysheetfile = getluckysheetfile(); let luckysheetfile = getluckysheetfile();
let dynamicArray_compute = luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dynamicArray_compute"] == null ? {} : luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dynamicArray_compute"];
while (i < funcstack.length) { while (i < funcstack.length) {
let s = funcstack[i]; let s = funcstack[i];
@ -4201,12 +4201,12 @@ const luckysheetformula = {
} }
else if (s == ")" && matchConfig.dquote == 0) { else if (s == ")" && matchConfig.dquote == 0) {
matchConfig.bracket -= 1; matchConfig.bracket -= 1;
function_str += _this.isFunctionRange(str, r, c) + ")"; function_str += _this.isFunctionRangeSimple(str, r, c,dynamicArray_compute) + ")";
str = ""; str = "";
} }
else if (s == ',' && matchConfig.dquote == 0) { else if (s == ',' && matchConfig.dquote == 0) {
//matchConfig.comma += 1; //matchConfig.comma += 1;
function_str += _this.isFunctionRange(str, r, c) + ','; function_str += _this.isFunctionRangeSimple(str, r, c,dynamicArray_compute) + ',';
str = ""; str = "";
} }
else if (s in _this.operatorjson && matchConfig.dquote == 0) { else if (s in _this.operatorjson && matchConfig.dquote == 0) {
@ -4218,7 +4218,7 @@ const luckysheetformula = {
if ((s + s_next) in _this.operatorjson) { if ((s + s_next) in _this.operatorjson) {
if (str.length > 0) { if (str.length > 0) {
function_str += _this.isFunctionRange(str, r, c) + s + s_next; function_str += _this.isFunctionRangeSimple(str, r, c,dynamicArray_compute) + s + s_next;
str = ""; str = "";
} }
else { else {
@ -4229,7 +4229,7 @@ const luckysheetformula = {
} }
else { else {
if (str.length > 0) { if (str.length > 0) {
function_str += _this.isFunctionRange(str, r, c) + s; function_str += _this.isFunctionRangeSimple(str, r, c,dynamicArray_compute) + s;
str = ""; str = "";
} }
else { else {
@ -4243,48 +4243,50 @@ const luckysheetformula = {
if (i == funcstack.length - 1) { if (i == funcstack.length - 1) {
if (_this.iscelldata($.trim(str))) { if (_this.iscelldata($.trim(str))) {
if (r != null && c != null) { _this.isFunctionRangeSaveChange(str, r, c, dynamicArray_compute);
let range = _this.getcellrange($.trim(str)); // if (r != null && c != null) {
let row = range.row,
col = range.column; // let range = _this.getcellrange($.trim(str));
// let row = range.row,
if ((r + "_" + c) in dynamicArray_compute) { // col = range.column;
let isd_range = false;
// if ((r + "_" + c) in dynamicArray_compute) {
for (let d_r = row[0]; d_r <= row[1]; d_r++) { // let isd_range = false;
for (let d_c = col[0]; d_c <= col[1]; d_c++) {
if ((d_r + "_" + d_c) in dynamicArray_compute && dynamicArray_compute[d_r + "_" + d_c].r == r && dynamicArray_compute[d_r + "_" + d_c].c == c) { // for (let d_r = row[0]; d_r <= row[1]; d_r++) {
isd_range = true; // for (let d_c = col[0]; d_c <= col[1]; d_c++) {
} // if ((d_r + "_" + d_c) in dynamicArray_compute && dynamicArray_compute[d_r + "_" + d_c].r == r && dynamicArray_compute[d_r + "_" + d_c].c == c) {
} // isd_range = true;
} // }
// }
if (isd_range) { // }
_this.isFunctionRangeSave = _this.isFunctionRangeSave || true;
} // if (isd_range) {
else { // _this.isFunctionRangeSave = _this.isFunctionRangeSave || true;
_this.isFunctionRangeSave = _this.isFunctionRangeSave || false; // }
} // else {
} // _this.isFunctionRangeSave = _this.isFunctionRangeSave || false;
else { // }
if (r >= row[0] && r <= row[1] && c >= col[0] && c <= col[1]) { // }
_this.isFunctionRangeSave = _this.isFunctionRangeSave || true; // else {
} // if (r >= row[0] && r <= row[1] && c >= col[0] && c <= col[1]) {
else { // _this.isFunctionRangeSave = _this.isFunctionRangeSave || true;
_this.isFunctionRangeSave = _this.isFunctionRangeSave || false; // }
} // else {
} // _this.isFunctionRangeSave = _this.isFunctionRangeSave || false;
} // }
else { // }
let sheetlen = $.trim(str).split("!"); // }
// else {
if (sheetlen.length > 1) { // let sheetlen = $.trim(str).split("!");
_this.isFunctionRangeSave = _this.isFunctionRangeSave || true;
} // if (sheetlen.length > 1) {
else { // _this.isFunctionRangeSave = _this.isFunctionRangeSave || true;
_this.isFunctionRangeSave = _this.isFunctionRangeSave || false; // }
} // else {
} // _this.isFunctionRangeSave = _this.isFunctionRangeSave || false;
// }
// }
} }
else { else {
//console.log(str); //console.log(str);
@ -4296,7 +4298,19 @@ const luckysheetformula = {
//console.log(function_str); //console.log(function_str);
return function_str; return function_str;
}, },
isFunctionRange: function (txt, r, c) { isFunctionRangeSelect:function(txt, r, c, dynamicArray_compute){
if(txt==null || txt==""){
return;
}
let txt1 = txt.toUpperCase();
if(txt1.indexOf("INDIRECT")>-1 || txt1.indexOf("OFFSET")>-1){
this.isFunctionRange(txt, r, c, dynamicArray_compute);
}
else{
this.isFunctionRangeSimple(txt, r, c, dynamicArray_compute);
}
},
isFunctionRange: function (txt, r, c, dynamicArray_compute) {
let _this = this; let _this = this;
if (_this.operatorjson == null) { if (_this.operatorjson == null) {
@ -4329,8 +4343,8 @@ const luckysheetformula = {
"braces": 0 "braces": 0
} }
let luckysheetfile = getluckysheetfile(); // let luckysheetfile = getluckysheetfile();
let dynamicArray_compute = luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dynamicArray_compute"] == null ? {} : luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dynamicArray_compute"]; // let dynamicArray_compute = luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dynamicArray_compute"] == null ? {} : luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dynamicArray_compute"];
//bracket 0为运算符括号、1为函数括号 //bracket 0为运算符括号、1为函数括号
let cal1 = [], cal2 = [], bracket = []; let cal1 = [], cal2 = [], bracket = [];
@ -4358,7 +4372,7 @@ const luckysheetformula = {
let bt = bracket.pop(); let bt = bracket.pop();
if (bracket.length == 0) { if (bracket.length == 0) {
function_str += _this.isFunctionRange(str,r,c) + ")"; function_str += _this.isFunctionRange(str,r,c,dynamicArray_compute) + ")";
str = ""; str = "";
} }
else { else {
@ -4385,7 +4399,7 @@ const luckysheetformula = {
} }
else if (s == ',' && matchConfig.dquote == 0 && matchConfig.braces == 0) { else if (s == ',' && matchConfig.dquote == 0 && matchConfig.braces == 0) {
if (bracket.length <= 1) { if (bracket.length <= 1) {
function_str += _this.isFunctionRange(str, r, c) + ","; function_str += _this.isFunctionRange(str, r, c,dynamicArray_compute) + ",";
str = ""; str = "";
} }
else { else {
@ -4403,7 +4417,7 @@ const luckysheetformula = {
if ((s + s_next) in _this.operatorjson) { if ((s + s_next) in _this.operatorjson) {
if (bracket.length == 0) { if (bracket.length == 0) {
if ($.trim(str).length > 0) { if ($.trim(str).length > 0) {
cal2.unshift(_this.isFunctionRange($.trim(str), r, c)); cal2.unshift(_this.isFunctionRange($.trim(str), r, c,dynamicArray_compute));
} }
else if ($.trim(function_str).length > 0) { else if ($.trim(function_str).length > 0) {
cal2.unshift($.trim(function_str)); cal2.unshift($.trim(function_str));
@ -4432,7 +4446,7 @@ const luckysheetformula = {
else { else {
if (bracket.length == 0) { if (bracket.length == 0) {
if ($.trim(str).length > 0) { if ($.trim(str).length > 0) {
cal2.unshift(_this.isFunctionRange($.trim(str), r, c)); cal2.unshift(_this.isFunctionRange($.trim(str), r, c,dynamicArray_compute));
} }
else if ($.trim(function_str).length > 0) { else if ($.trim(function_str).length > 0) {
cal2.unshift($.trim(function_str)); cal2.unshift($.trim(function_str));
@ -4538,9 +4552,10 @@ const luckysheetformula = {
if (r != null && c != null) { if (r != null && c != null) {
let range = _this.getcellrange($.trim(str)); let range = _this.getcellrange($.trim(str));
let row = range.row, let row = range.row,
col = range.column; col = range.column,
index = range.sheetIndex;
if ((r + "_" + c) in dynamicArray_compute) { if ((r + "_" + c) in dynamicArray_compute && (Store.currentSheetIndex==index || index==null)) {
let isd_range = false; let isd_range = false;
for (let d_r = row[0]; d_r <= row[1]; d_r++) { for (let d_r = row[0]; d_r <= row[1]; d_r++) {
@ -4559,7 +4574,7 @@ const luckysheetformula = {
} }
} }
else { else {
if (r >= row[0] && r <= row[1] && c >= col[0] && c <= col[1]) { if (r >= row[0] && r <= row[1] && c >= col[0] && c <= col[1] && (Store.currentSheetIndex==index || index==null)) {
_this.isFunctionRangeSave = _this.isFunctionRangeSave || true; _this.isFunctionRangeSave = _this.isFunctionRangeSave || true;
} }
else { else {
@ -4571,7 +4586,7 @@ const luckysheetformula = {
let sheetlen = $.trim(str).split("!"); let sheetlen = $.trim(str).split("!");
if (sheetlen.length > 1) { if (sheetlen.length > 1) {
_this.isFunctionRangeSave = _this.isFunctionRangeSave || true; _this.isFunctionRangeSave = _this.isFunctionRangeSave || true;//if change sheet, it must be true, but this is very slow
} }
else { else {
_this.isFunctionRangeSave = _this.isFunctionRangeSave || false; _this.isFunctionRangeSave = _this.isFunctionRangeSave || false;
@ -4655,8 +4670,10 @@ const luckysheetformula = {
window.luckysheet_offset_check = luckysheet_offset_check; window.luckysheet_offset_check = luckysheet_offset_check;
window.luckysheet_calcADPMM = luckysheet_calcADPMM; window.luckysheet_calcADPMM = luckysheet_calcADPMM;
} }
_this.execFunctionGroupData = $.extend(true, [], data); _this.execFunctionGroupData = $.extend(true, [], data);
let luckysheetfile = getluckysheetfile();
let dynamicArray_compute = luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dynamicArray_compute"] == null ? {} : luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dynamicArray_compute"];
if (value != null) { if (value != null) {
//此处setcellvalue 中this.execFunctionGroupData会保存想要更新的值,本函数结尾不要设为null,以备后续函数使用 //此处setcellvalue 中this.execFunctionGroupData会保存想要更新的值,本函数结尾不要设为null,以备后续函数使用
@ -4675,8 +4692,6 @@ const luckysheetformula = {
_this.execvertex = {}; _this.execvertex = {};
if (_this.execFunctionExist == null) { if (_this.execFunctionExist == null) {
let luckysheetfile = getluckysheetfile();
for (let i = 0; i < group.length; i++) { for (let i = 0; i < group.length; i++) {
let item = group[i]; let item = group[i];
let file =luckysheetfile[getSheetIndex(item["index"])]; let file =luckysheetfile[getSheetIndex(item["index"])];
@ -4702,10 +4717,10 @@ const luckysheetformula = {
_this.isFunctionRangeSave = true; _this.isFunctionRangeSave = true;
} }
else if (origin_r != null && origin_c != null) { else if (origin_r != null && origin_c != null) {
_this.isFunctionRange(calc_funcStr, origin_r, origin_c); _this.isFunctionRangeSelect(calc_funcStr, origin_r, origin_c, dynamicArray_compute);
} }
else { else {
_this.isFunctionRange(calc_funcStr); _this.isFunctionRangeSelect(calc_funcStr, undefined, undefined ,dynamicArray_compute);
} }
if (_this.isFunctionRangeSave) { if (_this.isFunctionRangeSave) {
@ -4738,7 +4753,7 @@ const luckysheetformula = {
_this.isFunctionRangeSave = true; _this.isFunctionRangeSave = true;
} }
else{ else{
_this.isFunctionRange(calc_funcStr, cell.r, cell.c); _this.isFunctionRangeSelect(calc_funcStr, cell.r, cell.c, dynamicArray_compute);
} }
if (_this.isFunctionRangeSave) { if (_this.isFunctionRangeSave) {
@ -4749,7 +4764,7 @@ const luckysheetformula = {
} }
} }
} }
while (stack.length > 0) { while (stack.length > 0) {
let u = stack.shift(); let u = stack.shift();
@ -4761,7 +4776,7 @@ const luckysheetformula = {
_this.isFunctionRangeSave = false; _this.isFunctionRangeSave = false;
let item = vertex1[name]; let item = vertex1[name];
let calc_funcStr = getcellFormula(item.r, item.c, item.index, _this.execFunctionGroupData); let calc_funcStr = getcellFormula(item.r, item.c, item.index, _this.execFunctionGroupData);
_this.isFunctionRange(calc_funcStr, u.r, u.c); _this.isFunctionRangeSelect(calc_funcStr, u.r, u.c, dynamicArray_compute);
if (_this.isFunctionRangeSave) { if (_this.isFunctionRangeSave) {
let v = vertex1[name]; let v = vertex1[name];
@ -4798,10 +4813,8 @@ const luckysheetformula = {
//深度优先算法,处理多级调用函数 //深度优先算法,处理多级调用函数
functionDFS: function(u) { functionDFS: function(u) {
let _this = this; let _this = this;
u.color = "g"; u.color = "g";
u.times += 1; u.times += 1;
for (let chd in u.chidren) { for (let chd in u.chidren) {
let v = _this.execvertex[chd]; let v = _this.execvertex[chd];
if (v.color == "w") { if (v.color == "w") {
@ -4813,6 +4826,7 @@ const luckysheetformula = {
u.color = "b"; u.color = "b";
window.luckysheet_getcelldata_cache = null; window.luckysheet_getcelldata_cache = null;
let calc_funcStr = getcellFormula(u.r, u.c, u.index, _this.execFunctionGroupData); let calc_funcStr = getcellFormula(u.r, u.c, u.index, _this.execFunctionGroupData);
let v = _this.execfunction(calc_funcStr, u.r, u.c); let v = _this.execfunction(calc_funcStr, u.r, u.c);
let value = _this.execFunctionGroupData[u.r][u.c]; let value = _this.execFunctionGroupData[u.r][u.c];

Loading…
Cancel
Save