Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1093)

Issue 171953002: Get rid of inefficient uses of childNodeCount() (Closed)

Created:
6 years, 10 months ago by Inactive
Modified:
6 years, 10 months ago
Reviewers:
adamk, eseidel
CC:
blink-reviews, nessy, gasubic, sof, eae+blinkwatch, fs, eric.carlson_apple.com, dglazkov+blink, adamk+blink_chromium.org, vcarbune.chromium, philipj_slow, Inactive
Visibility:
Public.

Description

Get 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() #

Unified diffs Side-by-side diffs Delta from patch set Stats (+46 lines, -23 lines) Patch
M Source/core/dom/ContainerNode.h View 1 2 2 chunks +11 lines, -0 lines 0 comments Download
M Source/core/dom/Range.cpp View 1 chunk +3 lines, -2 lines 0 comments Download
M Source/core/editing/ApplyStyleCommand.cpp View 3 chunks +7 lines, -4 lines 0 comments Download
M Source/core/editing/ReplaceSelectionCommand.cpp View 1 chunk +1 line, -1 line 0 comments Download
M Source/core/editing/TextIterator.cpp View 1 2 1 chunk +10 lines, -6 lines 0 comments Download
M Source/core/editing/htmlediting.cpp View 2 chunks +2 lines, -2 lines 0 comments Download
M Source/core/editing/markup.cpp View 1 2 3 2 chunks +9 lines, -5 lines 0 comments Download
M Source/core/html/track/vtt/VTTRegion.cpp View 1 chunk +3 lines, -3 lines 0 comments Download

Messages

Total messages: 10 (0 generated)
Inactive
https://codereview.chromium.org/171953002/diff/40001/Source/core/dom/ContainerNode.cpp File Source/core/dom/ContainerNode.cpp (left): https://codereview.chromium.org/171953002/diff/40001/Source/core/dom/ContainerNode.cpp#oldcode540 Source/core/dom/ContainerNode.cpp:540: removedChildren.reserveInitialCapacity(childNodeCount()); I don't think this one is worth it ...
6 years, 10 months ago (2014-02-19 04:13:32 UTC) #1
eseidel
lgtm Please see the comments below. https://codereview.chromium.org/171953002/diff/40001/Source/core/dom/ContainerNode.cpp File Source/core/dom/ContainerNode.cpp (left): https://codereview.chromium.org/171953002/diff/40001/Source/core/dom/ContainerNode.cpp#oldcode540 Source/core/dom/ContainerNode.cpp:540: removedChildren.reserveInitialCapacity(childNodeCount()); On 2014/02/19 ...
6 years, 10 months ago (2014-02-19 05:39:53 UTC) #2
Inactive
https://codereview.chromium.org/171953002/diff/40001/Source/core/dom/ContainerNode.cpp File Source/core/dom/ContainerNode.cpp (left): https://codereview.chromium.org/171953002/diff/40001/Source/core/dom/ContainerNode.cpp#oldcode540 Source/core/dom/ContainerNode.cpp:540: removedChildren.reserveInitialCapacity(childNodeCount()); On 2014/02/19 05:39:54, eseidel wrote: > On 2014/02/19 ...
6 years, 10 months ago (2014-02-19 14:28:15 UTC) #3
Inactive
I updated the patch as per review comments. Please take another look (especially the new ...
6 years, 10 months ago (2014-02-19 16:19:56 UTC) #4
eseidel
lgtm https://codereview.chromium.org/171953002/diff/140001/Source/core/editing/markup.cpp File Source/core/editing/markup.cpp (right): https://codereview.chromium.org/171953002/diff/140001/Source/core/editing/markup.cpp#newcode797 Source/core/editing/markup.cpp:797: return element->hasChildCount(2) && isTabSpanTextNode(element->firstChild()->firstChild()) && element->firstChild()->nextSibling()->isTextNode(); The last ...
6 years, 10 months ago (2014-02-19 18:26:50 UTC) #5
Inactive
https://codereview.chromium.org/171953002/diff/140001/Source/core/editing/markup.cpp File Source/core/editing/markup.cpp (right): https://codereview.chromium.org/171953002/diff/140001/Source/core/editing/markup.cpp#newcode797 Source/core/editing/markup.cpp:797: return element->hasChildCount(2) && isTabSpanTextNode(element->firstChild()->firstChild()) && element->firstChild()->nextSibling()->isTextNode(); On 2014/02/19 18:26:50, ...
6 years, 10 months ago (2014-02-19 18:36:32 UTC) #6
Inactive
The CQ bit was checked by ch.dumez@samsung.com
6 years, 10 months ago (2014-02-19 18:36:37 UTC) #7
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/ch.dumez@samsung.com/171953002/250001
6 years, 10 months ago (2014-02-19 22:03:20 UTC) #8
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/ch.dumez@samsung.com/171953002/250001
6 years, 10 months ago (2014-02-19 23:09:08 UTC) #9
commit-bot: I haz the power
6 years, 10 months ago (2014-02-19 23:47:28 UTC) #10
Message was sent while issue was closed.
Change committed as 167444

Powered by Google App Engine
This is Rietveld 408576698