From bcc3a021ebbdc33f826cc668e40de360ee6a6b23 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 4 Jun 2012 21:11:35 -0700 Subject: chore(jqLite): performance reordering --- src/jqLite.js | 8 ++++++-- src/ng/compile.js | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/jqLite.js b/src/jqLite.js index 387de47d..3e8fb266 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -365,8 +365,12 @@ forEach('input,select,option,textarea,button,form'.split(','), function(value) { BOOLEAN_ELEMENTS[uppercase(value)] = true; }); -function isBooleanAttr(element, name) { - return BOOLEAN_ELEMENTS[element.nodeName] && BOOLEAN_ATTR[name.toLowerCase()]; +function getBooleanAttrName(element, name) { + // check dom last since we will most likely fail on name + var booleanAttr = BOOLEAN_ATTR[name.toLowerCase()]; + + // booleanAttr is here twice to minimize DOM access + return booleanAttr && BOOLEAN_ELEMENTS[element.nodeName] && booleanAttr; } forEach({ diff --git a/src/ng/compile.js b/src/ng/compile.js index 5c7f1419..0d9ff9ea 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -286,7 +286,7 @@ function $CompileProvider($provide) { * @param {string=} attrName Optional none normalized name. Defaults to key. */ $set: function(key, value, writeAttr, attrName) { - var booleanKey = isBooleanAttr(this.$$element[0], key.toLowerCase()); + var booleanKey = getBooleanAttrName(this.$$element[0], key); if (booleanKey) { this.$$element.prop(key, value); @@ -498,7 +498,7 @@ function $CompileProvider($provide) { attrs[nName] = value = trim((msie && name == 'href') ? decodeURIComponent(node.getAttribute(name, 2)) : attr.value); - if (isBooleanAttr(node, nName)) { + if (getBooleanAttrName(node, nName)) { attrs[nName] = true; // presence means true } addAttrInterpolateDirective(node, directives, value, nName); -- cgit v1.2.3