Skip to content

Commit bcc3a02

Browse files
mheveryIgorMinar
authored andcommitted
chore(jqLite): performance reordering
1 parent a57141f commit bcc3a02

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/jqLite.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,12 @@ forEach('input,select,option,textarea,button,form'.split(','), function(value) {
365365
BOOLEAN_ELEMENTS[uppercase(value)] = true;
366366
});
367367

368-
function isBooleanAttr(element, name) {
369-
return BOOLEAN_ELEMENTS[element.nodeName] && BOOLEAN_ATTR[name.toLowerCase()];
368+
function getBooleanAttrName(element, name) {
369+
// check dom last since we will most likely fail on name
370+
var booleanAttr = BOOLEAN_ATTR[name.toLowerCase()];
371+
372+
// booleanAttr is here twice to minimize DOM access
373+
return booleanAttr && BOOLEAN_ELEMENTS[element.nodeName] && booleanAttr;
370374
}
371375

372376
forEach({

src/ng/compile.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ function $CompileProvider($provide) {
286286
* @param {string=} attrName Optional none normalized name. Defaults to key.
287287
*/
288288
$set: function(key, value, writeAttr, attrName) {
289-
var booleanKey = isBooleanAttr(this.$$element[0], key.toLowerCase());
289+
var booleanKey = getBooleanAttrName(this.$$element[0], key);
290290

291291
if (booleanKey) {
292292
this.$$element.prop(key, value);
@@ -498,7 +498,7 @@ function $CompileProvider($provide) {
498498
attrs[nName] = value = trim((msie && name == 'href')
499499
? decodeURIComponent(node.getAttribute(name, 2))
500500
: attr.value);
501-
if (isBooleanAttr(node, nName)) {
501+
if (getBooleanAttrName(node, nName)) {
502502
attrs[nName] = true; // presence means true
503503
}
504504
addAttrInterpolateDirective(node, directives, value, nName);

0 commit comments

Comments
 (0)