chore(jqLite): performance reordering

This commit is contained in:
Misko Hevery 2012-06-04 21:11:35 -07:00 committed by Igor Minar
parent a57141fd1d
commit bcc3a021eb
2 changed files with 8 additions and 4 deletions

View file

@ -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({

View file

@ -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);