perf: Traverse dom using firstChild instead of childNodes
5% improvement in speed by not using childNodes DOM API.
This commit is contained in:
parent
f04967ad37
commit
0866485f95
|
@ -275,11 +275,12 @@ export class ProtoView {
|
||||||
}
|
}
|
||||||
var viewNodes;
|
var viewNodes;
|
||||||
if (this.isTemplateElement) {
|
if (this.isTemplateElement) {
|
||||||
var childNodes = rootElementClone.content.childNodes;
|
var childNode = DOM.firstChild(rootElementClone.content);
|
||||||
// Note: An explicit loop is the fastes way to convert a DOM array into a JS array!
|
viewNodes = []; // TODO(perf): Should be fixed size, since we could pre-compute in in ProtoView
|
||||||
viewNodes = ListWrapper.createFixedSize(childNodes.length);
|
// Note: An explicit loop is the fastest way to convert a DOM array into a JS array!
|
||||||
for (var i=0; i<childNodes.length; i++) {
|
while(childNode != null) {
|
||||||
viewNodes[i] = childNodes[i];
|
ListWrapper.push(viewNodes, childNode);
|
||||||
|
childNode = DOM.nextSibling(childNode);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
viewNodes = [rootElementClone];
|
viewNodes = [rootElementClone];
|
||||||
|
@ -338,9 +339,12 @@ export class ProtoView {
|
||||||
// textNodes
|
// textNodes
|
||||||
var textNodeIndices = binder.textNodeIndices;
|
var textNodeIndices = binder.textNodeIndices;
|
||||||
if (isPresent(textNodeIndices)) {
|
if (isPresent(textNodeIndices)) {
|
||||||
var childNodes = DOM.templateAwareRoot(element).childNodes;
|
var childNode = DOM.firstChild(DOM.templateAwareRoot(element));
|
||||||
for (var j = 0; j < textNodeIndices.length; j++) {
|
for (var j = 0, k = 0; j < textNodeIndices.length; j++) {
|
||||||
ListWrapper.push(textNodes, childNodes[textNodeIndices[j]]);
|
for(var index = textNodeIndices[j]; k < index; k++) {
|
||||||
|
childNode = DOM.nextSibling(childNode);
|
||||||
|
}
|
||||||
|
ListWrapper.push(textNodes, childNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue