Skip to content

simplify Lib.ensureNumber #5634

Closed
Closed
@archmoj

Description

@archmoj

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions