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

Commit cb62a57

Browse files
robinboehmpetebacondarwin
authored andcommitted
refact(ngClass): improve performance through bitwise operations
Change modulo % 2 operations to bitwise & 1 Read about this in Nicholas C. Zakas book "High Performance JavaScript"(ISBN: 978-0-596-80279-0) Use the Fast Parts --> Bitwise Operators --> Page 156++ Proven at http://jsperf.com/modulo-vs-bitwise/11
1 parent 61c0ade commit cb62a57

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/ng/directive/ngClass.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ function classDirective(name, selector) {
1515

1616
if (name !== 'ngClass') {
1717
scope.$watch('$index', function($index, old$index) {
18-
var mod = $index % 2;
19-
if (mod !== old$index % 2) {
20-
if (mod == selector) {
18+
var mod = $index & 1;
19+
if (mod !== old$index & 1) {
20+
if (mod === selector) {
2121
addClass(scope.$eval(attr[name]));
2222
} else {
2323
removeClass(scope.$eval(attr[name]));

0 commit comments

Comments
 (0)