-
Notifications
You must be signed in to change notification settings - Fork 27.4k
chore(angular.toJson): use charAt instead of regexp #4093
Conversation
Thanks for the PR!
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
@mary-poppins I've signed, my name is Boris Serdyuk |
Some browsers sometimes put into as key argument not a string, because there is need additional check. |
Doesn't this mean that toJSON is not ignoring keys starting in $ for IE8 now? |
Can you provide a unit test if there isn't one for IE. |
@petebacondarwin there are already has tests for these keys, isn't it?https://github.com/angular/angular.js/blob/master/test/AngularSpec.js#L982 |
Oh, OK. So the check for charAt is in case the key is a number rather than a string? |
@petebacondarwin yes. I've changed these check for more effective. Here's comparison: http://jsperf.com/check-first-char/4 |
LGTM |
Provides a performance improvement when serializing to JSON strings. Closes #4093
Provides a performance improvement when serializing to JSON strings. Closes angular#4093
Provides a performance improvement when serializing to JSON strings. Closes angular#4093
Regular Expressions is an expensive operation and this case can be simplified. Here's a comparison: http://jsperf.com/check-first-char
Using charAt is better than using brackets, explanation of this can be found here http://stackoverflow.com/questions/5943726/string-charatx-or-stringx/5943760#5943760