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

Commit 22358cf

Browse files
committed
perf($animate): access DOM less in resolveElementClasses
Previously we were reading DOM attributes frequently, now we can do it just once.
1 parent 003c44e commit 22358cf

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/ng/animate.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,14 @@ var $AnimateProvider = ['$provide', function($provide) {
102102

103103
function resolveElementClasses(element, cache) {
104104
var toAdd = [], toRemove = [];
105+
106+
var hasClasses = createMap();
107+
forEach((element.attr('class') || '').split(/\s+/), function(className) {
108+
hasClasses[className] = true;
109+
});
110+
105111
forEach(cache.classes, function(status, className) {
106-
var hasClass = jqLiteHasClass(element[0], className);
112+
var hasClass = hasClasses[className];
107113

108114
// If the most recent class manipulation (via $animate) was to remove the class, and the
109115
// element currently has the class, the class is scheduled for removal. Otherwise, if

src/ngAnimate/animate.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,14 @@ angular.module('ngAnimate', ['ng'])
477477
});
478478
});
479479

480+
var hasClasses = Object.create(null);
481+
forEach((element.attr('class') || '').split(/\s+/), function(className) {
482+
hasClasses[className] = true;
483+
});
484+
480485
var toAdd = [], toRemove = [];
481486
forEach(cache.classes, function(status, className) {
482-
var hasClass = angular.$$hasClass(element[0], className);
487+
var hasClass = hasClasses[className] === true;
483488
var matchingAnimation = lookup[className] || {};
484489

485490
// When addClass and removeClass is called then $animate will check to

0 commit comments

Comments
 (0)