From 22358cf9c703d67f3cf9eb4899404b09578a5fad Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Wed, 8 Oct 2014 14:34:26 -0400 Subject: [PATCH] perf($animate): access DOM less in resolveElementClasses Previously we were reading DOM attributes frequently, now we can do it just once. --- src/ng/animate.js | 8 +++++++- src/ngAnimate/animate.js | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ng/animate.js b/src/ng/animate.js index 13a0049a..b53dc02e 100644 --- a/src/ng/animate.js +++ b/src/ng/animate.js @@ -102,8 +102,14 @@ var $AnimateProvider = ['$provide', function($provide) { function resolveElementClasses(element, cache) { var toAdd = [], toRemove = []; + + var hasClasses = createMap(); + forEach((element.attr('class') || '').split(/\s+/), function(className) { + hasClasses[className] = true; + }); + forEach(cache.classes, function(status, className) { - var hasClass = jqLiteHasClass(element[0], className); + var hasClass = hasClasses[className]; // If the most recent class manipulation (via $animate) was to remove the class, and the // element currently has the class, the class is scheduled for removal. Otherwise, if diff --git a/src/ngAnimate/animate.js b/src/ngAnimate/animate.js index bb0778a4..c4cadb08 100644 --- a/src/ngAnimate/animate.js +++ b/src/ngAnimate/animate.js @@ -477,9 +477,14 @@ angular.module('ngAnimate', ['ng']) }); }); + var hasClasses = Object.create(null); + forEach((element.attr('class') || '').split(/\s+/), function(className) { + hasClasses[className] = true; + }); + var toAdd = [], toRemove = []; forEach(cache.classes, function(status, className) { - var hasClass = angular.$$hasClass(element[0], className); + var hasClass = hasClasses[className] === true; var matchingAnimation = lookup[className] || {}; // When addClass and removeClass is called then $animate will check to