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

simplify Lib.ensureNumber #5634

Closed
archmoj opened this issue May 5, 2021 · 0 comments · Fixed by #5637
Closed

simplify Lib.ensureNumber #5634

archmoj opened this issue May 5, 2021 · 0 comments · Fixed by #5637

Comments

@archmoj
Copy link
Contributor

archmoj commented May 5, 2021

This is ensureNumber:

plotly.js/src/lib/index.js

Lines 166 to 171 in 8cccacc

lib.ensureNumber = function ensureNumber(v) {
if(!isNumeric(v)) return BADNUM;
v = Number(v);
if(v < -FP_SAFE || v > FP_SAFE) return BADNUM;
return isNumeric(v) ? Number(v) : BADNUM;
};

Any reason the last line isn't just return v;? This is a pretty hot function. After already filtering out non-numeric values and converting others to Number explicitly, why would we have to check isNumeric again?

Originally posted by @alexcjohnson in #5622 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant