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

refactor(ngRepeat): use &1 instead of %2 for even odd checking#4359

Closed
demike wants to merge 2 commits intoangular:masterfrom
demike:patch-1
Closed

refactor(ngRepeat): use &1 instead of %2 for even odd checking#4359
demike wants to merge 2 commits intoangular:masterfrom
demike:patch-1

Conversation

@demike
Copy link
Copy Markdown

@demike demike commented Oct 10, 2013

use

index&1==0

instead of

index%2==0

for even odd checking

use "index&1==0"  instead of "index%2==0" for even odd checking
@mary-poppins
Copy link
Copy Markdown

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!

@jbruni
Copy link
Copy Markdown
Contributor

jbruni commented Oct 10, 2013

It is breaking the build.

Use parenthesis so it performs correctly and return boolean instead of integer: (index&1)==0

@petebacondarwin
Copy link
Copy Markdown
Contributor

Optimizations like this need to be supported by some evidence.
Here is a jsperf case http://jsperf.com/odd-and-even/2 which seems to show that the &1 case is 99% faster, which is quite convincing.
There are some concerns over using bitwise operators since JavaScript numbers are always floating point. In this case we are guaranteed that the numbers are positive integers so I guess it is safe to optimise.
@IgorMinar or @mhevery - do you have a view?

@petebacondarwin
Copy link
Copy Markdown
Contributor

@demike - can you make sure you sign the CLA.
By the way I would say that this is a "refactor" not a "chore", since chores are more about the build and package process.

@demike
Copy link
Copy Markdown
Author

demike commented Oct 10, 2013

Just signed the CLA.

@lgalfaso
Copy link
Copy Markdown
Contributor

this PR is no longer valid as this change was done with f2fab49

@lgalfaso lgalfaso closed this Dec 28, 2014
peebeebee referenced this pull request Aug 18, 2016
This now uses the same technique as ngRepeat.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants