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

String#trim consistency with es5-shim #343

Open
lewisje opened this issue May 11, 2015 · 1 comment
Open

String#trim consistency with es5-shim #343

lewisje opened this issue May 11, 2015 · 1 comment

Comments

@lewisje
Copy link

lewisje commented May 11, 2015

I noticed that this shim uses a single regex, while es5-shim uses two, and although I know the es5-shim project didn't want to get into "performance golfing" toward further optimizing its trim shim, it does turn out to be reliably faster to use two regexes than one: https://jsperf.com/mega-trim-test/47

(Comparing character codes against numbers is even faster than the native String#trim, but it results in code that is more difficult to understand, particularly in this jsPerf, which uses decimal literals.)

Also, why does this implementation use capturing groups?

@ljharb
Copy link
Collaborator

ljharb commented May 11, 2015

At the time the es6-shim implementation was written, the es5-shim implementation also used 1 regex. When that was updated for performance to 2 regexes, this one wasn't.

A PR that updates this one to not use capturing groups, and/or to use 2 instead of 1 regex, would be great.

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

No branches or pull requests

2 participants