Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

chore(angular.toJson): use charAt instead of regexp #4093

Closed
wants to merge 1 commit into from
Closed

chore(angular.toJson): use charAt instead of regexp #4093

wants to merge 1 commit into from

Conversation

just-boris
Copy link
Contributor

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

@mary-poppins
Copy link

Thanks for the PR!

  • Contributor signed CLA now or in the past
    • If you just signed, leave a comment here with your real name
  • PR's commit messages follow the commit message format

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

@just-boris
Copy link
Contributor Author

@mary-poppins I've signed, my name is Boris Serdyuk

@just-boris
Copy link
Contributor Author

Some browsers sometimes put into as key argument not a string, because there is need additional check.
Here is broken travis build without it: https://travis-ci.org/angular/angular.js/builds/11624597

@petebacondarwin
Copy link
Contributor

Doesn't this mean that toJSON is not ignoring keys starting in $ for IE8 now?

@petebacondarwin
Copy link
Contributor

Can you provide a unit test if there isn't one for IE.
Also I think this counts as a refactor not a chore.

@just-boris
Copy link
Contributor Author

@petebacondarwin there are already has tests for these keys, isn't it?https://github.com/angular/angular.js/blob/master/test/AngularSpec.js#L982

@petebacondarwin
Copy link
Contributor

Oh, OK. So the check for charAt is in case the key is a number rather than a string?

@just-boris
Copy link
Contributor Author

@petebacondarwin yes. I've changed these check for more effective. Here's comparison: http://jsperf.com/check-first-char/4
Moreover, I can't reproduce case when key is number on my IE8, it always put string, unlike the travis build

@petebacondarwin
Copy link
Contributor

LGTM

petebacondarwin pushed a commit that referenced this pull request Sep 23, 2013
Provides a performance improvement when serializing to JSON strings.

Closes #4093
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this pull request Sep 25, 2013
Provides a performance improvement when serializing to JSON strings.

Closes angular#4093
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this pull request Jan 27, 2014
Provides a performance improvement when serializing to JSON strings.

Closes angular#4093
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants