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

Optimization: Check whether encoding/decoding is needed #31

Open
mudcube opened this issue Jul 12, 2017 · 0 comments
Open

Optimization: Check whether encoding/decoding is needed #31

mudcube opened this issue Jul 12, 2017 · 0 comments

Comments

@mudcube
Copy link

mudcube commented Jul 12, 2017

Would it make sense to check whether encoding/decoding is needed?

if (/^[\u0000-\u007F]*$/i.test(str)) {
    return str
} else {
    return encode(str) // or decode(str)
}

Use case—I'm using UTF8.js to encode SVGs into dataURLs, and for larger SVGs it can take a little bit of time to encode them (not a huge amount, maybe 100ms per MB). Most of the time the SVGs do not actually need encoding as they're entirely ASCII, this RegExp check is fairly quick, so saves a bit of time overall.

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

No branches or pull requests

1 participant