-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Adopt more smart pointers in dom/Text #46876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adopt more smart pointers in dom/Text #46876
Conversation
EWS run on previous version of this PR (hash af255e6) |
@@ -24290,6 +24290,9 @@ | |||
FB39D0701200ED9200088E69 /* Project object */ = { | |||
isa = PBXProject; | |||
attributes = { | |||
KnownAssetTags = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to figure out how to force push a new commit that overwrites this...
Please ignore this for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Updated commit should remove this.
af255e6
to
0a81702
Compare
EWS run on previous version of this PR (hash 0a81702) |
0a81702
to
d0244c2
Compare
EWS run on previous version of this PR (hash d0244c2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly good, a few small comments.
Source/WebCore/dom/Text.cpp
Outdated
const Text* endText = latestLogicallyAdjacentTextNode(this); | ||
ASSERT(endText); | ||
const Node* onePastEndText = TextNodeTraversal::nextSibling(*endText); | ||
RefPtr startText = const_cast<Text*>(earliestLogicallyAdjacentTextNode(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we don't need the const_cast<Text*>
here. You should be able to just do:
RefPtr startText = earliestLogicallyAdjacentTextNode(this);
Source/WebCore/dom/Text.cpp
Outdated
ASSERT(endText); | ||
const Node* onePastEndText = TextNodeTraversal::nextSibling(*endText); | ||
RefPtr startText = const_cast<Text*>(earliestLogicallyAdjacentTextNode(this)); | ||
RefPtr endText = const_cast<Text*>(latestLogicallyAdjacentTextNode(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Thanks for pointing this out Rupin!
Source/WebCore/dom/Text.cpp
Outdated
const Node* onePastEndText = TextNodeTraversal::nextSibling(*endText); | ||
RefPtr startText = const_cast<Text*>(earliestLogicallyAdjacentTextNode(this)); | ||
RefPtr endText = const_cast<Text*>(latestLogicallyAdjacentTextNode(this)); | ||
RefPtr onePastEndText = const_cast<Text*>(TextNodeTraversal::nextSibling(*endText)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use:
RefPtr<const Node> onePastEndText = TextNodeTraversal::nextSibling(*endText);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe RefPtr
would deduce as RefPtr<const Node>
without the const_cast. No need to be explicit about it.
Source/WebCore/dom/Text.cpp
Outdated
|
||
StringBuilder result; | ||
for (const Text* text = startText; text != onePastEndText; text = TextNodeTraversal::nextSibling(*text)) | ||
for (RefPtr text = startText; text != onePastEndText; text = const_cast<Text*>(TextNodeTraversal::nextSibling(*text))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use RefPtr<const Text>
and remove the const_cast
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We definitely should avoid const_cast
as much as possible.
Please drop the OOPS line or put the radar link if you have one (not mandatory). |
When starting out, I'd recommend staying out of dom/ as this is performance sensitive code. This PR will have to be A/B tested on Speedometer. |
d0244c2
to
8c691e4
Compare
EWS run on previous version of this PR (hash 8c691e4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there, but as Chris mentioned, this will have to be A/B tested before landing.
Source/WebCore/dom/Text.cpp
Outdated
ASSERT(endText); | ||
const Node* onePastEndText = TextNodeTraversal::nextSibling(*endText); | ||
RefPtr<const Text> onePastEndText = TextNodeTraversal::nextSibling(*endText); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep using Node
here. So RefPtr<const Node>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops I missed that it was using Node originally. Thanks for catching that Rupin!
Source/WebCore/dom/Text.cpp
Outdated
|
||
StringBuilder result; | ||
for (const Text* text = startText; text != onePastEndText; text = TextNodeTraversal::nextSibling(*text)) | ||
for (RefPtr<const Text> text = startText; text != onePastEndText; text = TextNodeTraversal::nextSibling(*text)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since startText
is RefPtr<const Text>
from above, we don't need to specify the <const Text>
part again. We can just use RefPtr text
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. When we create RefPtr text
variable., RefPtr
is automatically created with the same type as StartText
(aka a constText as the typeParameter). Good point! This has been fixed and thanks Rupin!
8c691e4
to
20a3947
Compare
EWS run on current version of this PR (hash 20a3947) |
@jelee53 does not have committer permissions according to https://raw.githubusercontent.com/WebKit/WebKit/main/metadata/contributors.json. If you do have committer permissions, please ensure that your GitHub username is added to contributors.json. Rejecting 20a3947 from merge queue. |
https://bugs.webkit.org/show_bug.cgi?id=294640 rdar://153684504 (Adopt more smart pointers in dom/Text (294640)) Reviewed by Ryosuke Niwa. Smart pointer adoption as per the static analyzer. * Source/WebCore/SaferCPPExpectations/UncheckedLocalVarsCheckerExpectations: * Source/WebCore/SaferCPPExpectations/UncountedLocalVarsCheckerExpectations: * Source/WebCore/dom/Text.cpp: (WebCore::Text::wholeText const): * Source/WebCore/dom/TextNodeTraversal.cpp: (WebCore::TextNodeTraversal::appendContents): (WebCore::TextNodeTraversal::childTextContent): * Source/WebCore/dom/TextNodeTraversal.h: (WebCore::TextNodeTraversal::firstTextWithinTemplate): (WebCore::TextNodeTraversal::traverseNextTextTemplate): Canonical link: https://commits.webkit.org/296685@main
20a3947
to
dcd1706
Compare
Committed 296685@main (dcd1706): https://commits.webkit.org/296685@main Reviewed commits have been landed. Closing PR #46876 and removing active labels. |
dcd1706
20a3947
🛠 playstation