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

Commit 3c46c94

Browse files
jbedardrodyhaddad
authored andcommitted
perf(jqLite): expose the low-level jqLite.data/removeData calls
- updated the internal jqLite helpers to use the low-level jqLite.data/removeData to avoid unnecessary jq wrappers and loops - updated $compile to use the low-level jqLite.data/removeData to avoid unnecessary jq wrappers at link time
1 parent 71eb190 commit 3c46c94

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/jqLite.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -417,25 +417,22 @@ function jqLiteController(element, name) {
417417
}
418418

419419
function jqLiteInheritedData(element, name, value) {
420-
element = jqLite(element);
421-
422420
// if element is the document object work with the html element instead
423421
// this makes $(document).scope() possible
424-
if(element[0].nodeType == 9) {
425-
element = element.find('html');
422+
if(element.nodeType == 9) {
423+
element = element.documentElement;
426424
}
427425
var names = isArray(name) ? name : [name];
428426

429-
while (element.length) {
430-
var node = element[0];
427+
while (element) {
431428
for (var i = 0, ii = names.length; i < ii; i++) {
432-
if ((value = element.data(names[i])) !== undefined) return value;
429+
if ((value = jqLite.data(element, names[i])) !== undefined) return value;
433430
}
434431

435432
// If dealing with a document fragment node with a host element, and no parent, use the host
436433
// element as the parent. This enables directives within a Shadow DOM or polyfilled Shadow DOM
437434
// to lookup parent controllers.
438-
element = jqLite(node.parentNode || (node.nodeType === 11 && node.host));
435+
element = element.parentNode || (element.nodeType === 11 && element.host);
439436
}
440437
}
441438

@@ -510,18 +507,25 @@ function getBooleanAttrName(element, name) {
510507
return booleanAttr && BOOLEAN_ELEMENTS[element.nodeName] && booleanAttr;
511508
}
512509

510+
forEach({
511+
data: jqLiteData,
512+
removeData: jqLiteRemoveData
513+
}, function(fn, name) {
514+
JQLite[name] = fn;
515+
});
516+
513517
forEach({
514518
data: jqLiteData,
515519
inheritedData: jqLiteInheritedData,
516520

517521
scope: function(element) {
518522
// Can't use jqLiteData here directly so we stay compatible with jQuery!
519-
return jqLite(element).data('$scope') || jqLiteInheritedData(element.parentNode || element, ['$isolateScope', '$scope']);
523+
return jqLite.data(element, '$scope') || jqLiteInheritedData(element.parentNode || element, ['$isolateScope', '$scope']);
520524
},
521525

522526
isolateScope: function(element) {
523527
// Can't use jqLiteData here directly so we stay compatible with jQuery!
524-
return jqLite(element).data('$isolateScope') || jqLite(element).data('$isolateScopeNoTemplate');
528+
return jqLite.data(element, '$isolateScope') || jqLite.data(element, '$isolateScopeNoTemplate');
525529
},
526530

527531
controller: jqLiteController,

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
947947
if (nodeLinkFn) {
948948
if (nodeLinkFn.scope) {
949949
childScope = scope.$new();
950-
jqLite(node).data('$scope', childScope);
950+
jqLite.data(node, '$scope', childScope);
951951
} else {
952952
childScope = scope;
953953
}

0 commit comments

Comments
 (0)