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

Commit f8f7a1d

Browse files
committed
perf(jqLite): simplify jqLiteDealoc
while querySelectorAll is much more expensive than getElementsByTagName on elements with both many and few children, cloning the live node list returned by getElementsByTagName makes it as expensive as querySelectorAll (we need to clone because we need the node list not to change while we iterate over it). the childNodes and childNodes.length check is as expensive as querySelectorAll on a node without any children, so it only makes the whole lookup 2x as slow, so I'm removing it.
1 parent b5f7970 commit f8f7a1d

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/jqLite.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,8 @@ function jqLiteClone(element) {
254254
function jqLiteDealoc(element, onlyDescendants){
255255
if (!onlyDescendants) jqLiteRemoveData(element);
256256

257-
if (element.childNodes && element.childNodes.length) {
258-
// we use querySelectorAll because documentFragments don't have getElementsByTagName
259-
var descendants = element.getElementsByTagName ? sliceArgs(element.getElementsByTagName('*')) :
260-
element.querySelectorAll ? element.querySelectorAll('*') : [];
257+
if (element.querySelectorAll) {
258+
var descendants = element.querySelectorAll('*');
261259
for (var i = 0, l = descendants.length; i < l; i++) {
262260
jqLiteRemoveData(descendants[i]);
263261
}

0 commit comments

Comments
 (0)