RESOLVED FIXED269199
AX: Replace is<T> downcast<t> with dynamicDowncast<T> uncheckedDowncast<T> when appropriate.
https://bugs.webkit.org/show_bug.cgi?id=269199
Summary AX: Replace is<T> downcast<t> with dynamicDowncast<T> uncheckedDowncast<T> wh...
Andres Gonzalez
Reported 2024-02-12 08:45:27 PST
.
Attachments
Patch (36.23 KB, patch)
2024-02-12 08:51 PST, Andres Gonzalez
no flags
Patch (36.32 KB, patch)
2024-02-12 11:47 PST, Andres Gonzalez
no flags
Patch (36.16 KB, patch)
2024-02-12 15:50 PST, Andres Gonzalez
no flags
Patch (36.17 KB, patch)
2024-02-12 16:48 PST, Andres Gonzalez
no flags
Radar WebKit Bug Importer
Comment 1 2024-02-12 08:46:06 PST
Andres Gonzalez
Comment 2 2024-02-12 08:51:39 PST
Tyler Wilcock
Comment 3 2024-02-12 09:24:48 PST
Comment on attachment 469826 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=469826&action=review > COMMIT_MESSAGE:9 > +is<T> followed by downcast<t> has a performance impact since it is performing the type check twice. In those cases the code can be re-wtitten using dynamicDonwcast<T>. In other cases where we are certain that the downcast is returning the correct type, we should use uncheckedDowncast. This patch makes these changes in some of the accessibility core code. More similar changes in subsequent patches. this patch also include some code cleanup and more adoption of smart mpointer to replace raw pointers. typos: re-wtitten dynamicDonwcast mpointer > Source/WebCore/accessibility/AccessibilityRenderObject.cpp:183 > + continuation = uncheckedDowncast<RenderInline>(*continuation).continuation(); I get this downcast existed before this patch...but I can't understand why it's safe not to type-check here. Furthermore, isn't the downcast unnecessary? continuation() exists on RenderBoxModelObject, so by my reading we shouldn't need it? > Source/WebCore/accessibility/AccessibilityRenderObject.cpp:203 > + firstChild = firstChildInContinuation(uncheckedDowncast<RenderInline>(renderer)); Rather than doing an unchecked downcast, can we make firstChildInContinuation take a RenderBoxModelObject? > Source/WebCore/accessibility/AccessibilityRenderObject.cpp:451 > + WeakPtr renderInline = dynamicDowncast<RenderInline>(renderer); > + if (renderInline && !renderer.isReplacedOrInlineBlock()) > + return renderInline->continuation(); The work we perform to cast here is not used if !renderer.isReplacedOrInlineBlock(). > Source/WebCore/accessibility/AccessibilityRenderObject.cpp:718 > + auto& altText = renderTextFragment->altText(); const auto&? > Source/WebCore/accessibility/AccessibilityRenderObject.cpp:721 > + return renderTextFragment ? renderTextFragment->contentString() : String(); Do we need a null-check here? Entering this block is predicated on renderTextFragment being non-null, and I don't think acquiring a reference to a string via altText() will ever invalidate the WeakPtr. > Source/WebCore/accessibility/AccessibilityRenderObject.cpp:724 > + return renderText ? renderText->text() : String(); Do we need a null-check here? Entering this block is predicated on renderText being non-null. > Source/WebCore/accessibility/AccessibilityRenderObject.cpp:1375 > - if (!m_renderer || !is<RenderView>(*m_renderer)) > + if (!m_renderer) > return 0; > - return downcast<RenderView>(*m_renderer).frameView().layoutContext().layoutCount(); > + > + auto* view = dynamicDowncast<RenderView>(*m_renderer); > + return view ? view->frameView().layoutContext().layoutCount() : 0; Can write this more succinctly: auto* view = dynamicDowncast<RenderView>(m_renderer.get()); return view ? view->frameView().layoutContext().layoutCount() : 0;
Andres Gonzalez
Comment 4 2024-02-12 11:47:29 PST
Andres Gonzalez
Comment 5 2024-02-12 11:56:29 PST
(In reply to Tyler Wilcock from comment #3) > Comment on attachment 469826 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=469826&action=review > > > COMMIT_MESSAGE:9 > > +is<T> followed by downcast<t> has a performance impact since it is performing the type check twice. In those cases the code can be re-wtitten using dynamicDonwcast<T>. In other cases where we are certain that the downcast is returning the correct type, we should use uncheckedDowncast. This patch makes these changes in some of the accessibility core code. More similar changes in subsequent patches. this patch also include some code cleanup and more adoption of smart mpointer to replace raw pointers. > > typos: > > re-wtitten > dynamicDonwcast > mpointer Fixed. > > > Source/WebCore/accessibility/AccessibilityRenderObject.cpp:183 > > + continuation = uncheckedDowncast<RenderInline>(*continuation).continuation(); > > I get this downcast existed before this patch...but I can't understand why > it's safe not to type-check here. Furthermore, isn't the downcast > unnecessary? continuation() exists on RenderBoxModelObject, so by my reading > we shouldn't need it? Fixed. > > > Source/WebCore/accessibility/AccessibilityRenderObject.cpp:203 > > + firstChild = firstChildInContinuation(uncheckedDowncast<RenderInline>(renderer)); > > Rather than doing an unchecked downcast, can we make > firstChildInContinuation take a RenderBoxModelObject? Changed the type of the param to firstChildInContinuation but we still need a cast here since renderer is a RenderObject. > > > Source/WebCore/accessibility/AccessibilityRenderObject.cpp:451 > > + WeakPtr renderInline = dynamicDowncast<RenderInline>(renderer); > > + if (renderInline && !renderer.isReplacedOrInlineBlock()) > > + return renderInline->continuation(); > > The work we perform to cast here is not used if > !renderer.isReplacedOrInlineBlock(). Fixed. > > > Source/WebCore/accessibility/AccessibilityRenderObject.cpp:718 > > + auto& altText = renderTextFragment->altText(); > > const auto&? Fixed. > > > Source/WebCore/accessibility/AccessibilityRenderObject.cpp:721 > > + return renderTextFragment ? renderTextFragment->contentString() : String(); > > Do we need a null-check here? Entering this block is predicated on > renderTextFragment being non-null, and I don't think acquiring a reference > to a string via altText() will ever invalidate the WeakPtr. I'd rather keep the null-check here since altText() may not be a trivial method. > > > Source/WebCore/accessibility/AccessibilityRenderObject.cpp:724 > > + return renderText ? renderText->text() : String(); > > Do we need a null-check here? Entering this block is predicated on > renderText being non-null. Likewise here. > > > Source/WebCore/accessibility/AccessibilityRenderObject.cpp:1375 > > - if (!m_renderer || !is<RenderView>(*m_renderer)) > > + if (!m_renderer) > > return 0; > > - return downcast<RenderView>(*m_renderer).frameView().layoutContext().layoutCount(); > > + > > + auto* view = dynamicDowncast<RenderView>(*m_renderer); > > + return view ? view->frameView().layoutContext().layoutCount() : 0; > > Can write this more succinctly: > > auto* view = dynamicDowncast<RenderView>(m_renderer.get()); > return view ? view->frameView().layoutContext().layoutCount() : 0; Fixed.
Andres Gonzalez
Comment 6 2024-02-12 15:50:48 PST
Andres Gonzalez
Comment 7 2024-02-12 16:48:47 PST
EWS
Comment 8 2024-02-12 21:00:29 PST
Committed 274522@main (cfef85306eb0): <https://commits.webkit.org/274522@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 469839 [details].
Note You need to log in before you can comment on or make changes to this bug.