Skip to content

Commit 43fc853

Browse files
author
Steven Orvell
committed
Slightly faster findAnnotatedNodes
1 parent b03a30e commit 43fc853

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

‎src/lib/annotations/annotations.html‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,18 +366,22 @@
366366

367367
// instance-time
368368

369-
_localSubTree: function(node, host) {
370-
return (node === host) ? node.childNodes :
371-
(node._lightChildren || node.childNodes);
372-
},
373-
374369
findAnnotatedNode: function(root, annote) {
375370
// recursively ascend tree until we hit root
376371
var parent = annote.parent &&
377372
Polymer.Annotations.findAnnotatedNode(root, annote.parent);
378373
// unwind the stack, returning the indexed node at each level
379-
return !parent ? root :
380-
Polymer.Annotations._localSubTree(parent, root)[annote.index];
374+
if (parent) {
375+
// note: marginally faster than indexing via childNodes
376+
// (http://jsperf.com/childnodes-lookup)
377+
for (var n=parent.firstChild, i=0; n; n=n.nextSibling) {
378+
if (annote.index === i++) {
379+
return n;
380+
}
381+
}
382+
} else {
383+
return root;
384+
}
381385
}
382386

383387
};

0 commit comments

Comments
 (0)