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
This commit is contained in:
Robin Böhm 2013-04-28 20:05:44 +02:00 committed by Pete Bacon Darwin
parent 61c0adedc3
commit cb62a57d43

View file

@ -15,9 +15,9 @@ function classDirective(name, selector) {
if (name !== 'ngClass') {
scope.$watch('$index', function($index, old$index) {
var mod = $index % 2;
if (mod !== old$index % 2) {
if (mod == selector) {
var mod = $index & 1;
if (mod !== old$index & 1) {
if (mod === selector) {
addClass(scope.$eval(attr[name]));
} else {
removeClass(scope.$eval(attr[name]));