es6-shim
es6-shim copied to clipboard
String#trim consistency with es5-shim
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?
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.