refector(rateFn): RegularExpression optimize - #12
Conversation
The internal functions toParsedFloat and getConverted are heavy logic used in the for loop. Changes to scope references without generating regular expressions each time, and fixes and optimizes errors in regular expressions.
|
Thank you very much for your PR! As you mentioned above, there was regex insufficiency. And your suggestion looks better than previous. 👍 In following code m[3] is no more valid, it should be m[2]. function toParsedFloat(val) {
const m = val.match(toParsedFloatRegNum);
let ret;
if (m && m.length >= 1) {
ret = {"num": parseFloat(m[1]), "unit": m[3]}; // m[3] is no more valid, it should be m[2]
}
return ret;
}And related with the performance, Because fx.rateFn = fx.rateFn || rateFn(fx.elem, fx.start, fx.end); // fx.rateFn is not rateFnSame name may be confusing your code reading. Sorry for confusing name. TT And as I know Finally It would be thankful if you check eslint and test as following. :) After review applied, I'll merge your precious PR! |
|
I apologize for requests without a lint & test. |
|
Please close it. |
The internal functions toParsedFloat and getConverted are heavy logic used in the for loop. Changes to scope references without generating regular expressions each time, and fixes and optimizes errors in regular expressions.