DescriptionGet rid of inefficient uses of childNodeCount()
Get rid of inefficient uses of childNodeCount() as this method can be costly.
Its implementation needs to traverse the node's direct children in the DOM tree
in order to count them. A lot of callers wrongly assume calling
childNodeCount() is cheap.
In a lot of cases, the callers simply want to know if the node has any children
or it is has exactly one child. hasChildNodes() / hasOneChild() methods provide
the same information much more efficiently.
In some cases, we already know the node is a ContainerNode but call the
Node::childNodeCount() method instead of ContainerNode::childNodeCount() which
bypasses the isContainerNode() check.
Finally, the caller sometimes wants to traverse all the direct children and
uses childNodeCount() / childNode(index) to do so. This causes the children to
be traversed twice (even more when childNodeCount() is used as loop condition
and not cached before the loop). In this case, it is best to use the traversal
API (NodeTraversal / ElementTraversal).
R=adamk, eseidel
Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=167444
Patch Set 1 #Patch Set 2 : Small clean up #
Total comments: 13
Patch Set 3 : Take feedback into consideration #
Total comments: 2
Patch Set 4 : Use lastChild() #
Messages
Total messages: 10 (0 generated)
|