WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
136825
Rename Node::childNode(index) to traverseToChildAt(index) for clarity
https://bugs.webkit.org/show_bug.cgi?id=136825
Summary
Rename Node::childNode(index) to traverseToChildAt(index) for clarity
Chris Dumez
Reported
2014-09-15 08:42:43 PDT
Rename Node::childNode(index) to traverseToChildAt(index) to make it clearer that the method is actually traversing the children and thus is potentially expensive. We should also avoid calling this method whenever there is a more efficient alternative.
Attachments
Patch
(27.41 KB, patch)
2014-09-15 09:22 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(27.40 KB, patch)
2014-09-16 17:51 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Show Obsolete
(1)
View All
Add attachment
proposed patch, testcase, etc.
Chris Dumez
Comment 1
2014-09-15 09:22:12 PDT
Created
attachment 238131
[details]
Patch
Benjamin Poulain
Comment 2
2014-09-16 00:01:13 PDT
Comment on
attachment 238131
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=238131&action=review
I like it!
> Source/WebCore/WebCore.exp.in:-1629 > -__ZNK7WebCore13ContainerNode9childNodeEj
Check UIKit before landing just in case.
> Source/WebCore/dom/ContainerNode.cpp:945 > + for (; child && index > 0; --index)
I am surprised you had to manually write the descending loop, clang is usually very good at that. A random thought: if this code is hot enough, you should dump the average value of "index" in a typical use. If it is large enough, it could be worth doing some manual unrolling.
> Source/WebCore/inspector/DOMPatchSupport.cpp:381 > + for (size_t i = 0; node && i < newMap.size(); ++i, node = node->nextSibling()) {
size_t -> unsigned. Personally I would use a while() here instead of for() because of the return in the loop and the non-obvious iteration steps.
Darin Adler
Comment 3
2014-09-16 09:01:16 PDT
We normally use “traverse” to refer to tree traversal, not just walking the linear child list.
Chris Dumez
Comment 4
2014-09-16 09:05:07 PDT
(In reply to
comment #3
)
> We normally use “traverse” to refer to tree traversal, not just walking the linear child list.
Do you have another naming suggestion? I thought iterating over the direct children still counted as a tree traversal, but if there is a better name for it, I am happy to make the update.
Chris Dumez
Comment 5
2014-09-16 09:17:52 PDT
(In reply to
comment #3
)
> We normally use “traverse” to refer to tree traversal, not just walking the linear child list.
Since you're using the term "walking", do you think walkToChildAt() would be a better alternative? I don't feel strongly either way ("traversing" a linked list sounded OK to me).
Chris Dumez
Comment 6
2014-09-16 11:16:08 PDT
Comment on
attachment 238131
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=238131&action=review
>> Source/WebCore/dom/ContainerNode.cpp:945 >> + for (; child && index > 0; --index) > > I am surprised you had to manually write the descending loop, clang is usually very good at that. > > A random thought: if this code is hot enough, you should dump the average value of "index" in a typical use. If it is large enough, it could be worth doing some manual unrolling.
I did not check the generated assembly to see if there was a difference. Since I was updated this function for coding style, I figured I would refactor it a bit. The purpose was not really to optimize.
>> Source/WebCore/inspector/DOMPatchSupport.cpp:381 >> + for (size_t i = 0; node && i < newMap.size(); ++i, node = node->nextSibling()) { > > size_t -> unsigned. > > Personally I would use a while() here instead of for() because of the return in the loop and the non-obvious iteration steps.
newMap.size() returns a size_t so wouldn't be using unsigned for |i| be risky?
Chris Dumez
Comment 7
2014-09-16 11:20:43 PDT
Comment on
attachment 238131
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=238131&action=review
>> Source/WebCore/WebCore.exp.in:-1629 >> -__ZNK7WebCore13ContainerNode9childNodeEj > > Check UIKit before landing just in case.
I have just checked, UIKit does not use ContainerNode::childNode().
Chris Dumez
Comment 8
2014-09-16 17:07:32 PDT
Another proposal would be findChildAt(index). I still prefer traverseToChildAt(index) though.
Chris Dumez
Comment 9
2014-09-16 17:51:04 PDT
Created
attachment 238230
[details]
Patch
Darin Adler
Comment 10
2014-09-16 18:24:54 PDT
Comment on
attachment 238230
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=238230&action=review
> Source/WebCore/dom/ContainerNode.cpp:945 > + for (; child && index > 0; --index)
It’d be pretty standard WebKit style to just say "child && index" instead of "child && index > 0".
> Source/WebCore/dom/Position.cpp:249 > - return m_anchorNode->childNode(m_offset - 1); // -1 converts to childNode((unsigned)-1) and returns null. > + return m_offset ? m_anchorNode->traverseToChildAt(m_offset - 1) : nullptr;
Wow, that 0 case could have been really slow before!
> Source/WebCore/inspector/DOMPatchSupport.cpp:381 > + for (unsigned i = 0; node && i < newMap.size(); ++i, node = node->nextSibling()) {
A little strange to use unsigned here now when it was size_t before.
WebKit Commit Bot
Comment 11
2014-09-16 19:00:46 PDT
Comment on
attachment 238230
[details]
Patch Clearing flags on attachment: 238230 Committed
r173684
: <
http://trac.webkit.org/changeset/173684
>
WebKit Commit Bot
Comment 12
2014-09-16 19:00:51 PDT
All reviewed patches have been landed. Closing bug.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug