Bug 137858

Summary: Kill toRenderedDocumentMarker() by using tighter typing
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: Layout and RenderingAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, commit-queue, darin, kling, rniwa
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=135631
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch none

Description Chris Dumez 2014-10-18 15:14:41 PDT
Kill toRenderedDocumentMarker() by using tighter typing. This method was doing no type validation, just a static_cast<>().
Comment 1 Chris Dumez 2014-10-18 15:21:13 PDT
Created attachment 240074 [details]
Patch
Comment 2 Chris Dumez 2014-10-18 15:54:24 PDT
Created attachment 240075 [details]
Patch
Comment 3 Chris Dumez 2014-10-18 18:27:07 PDT
Created attachment 240079 [details]
Patch
Comment 4 Darin Adler 2014-10-19 19:51:52 PDT
Comment on attachment 240079 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=240079&action=review

> Source/WebCore/dom/DocumentMarkerController.cpp:409
> +        Vector<RenderedDocumentMarker*> markers = markersFor(node);
> +        for (auto* marker : markers) {

Believe it or not, we don’t even need the local variable here. This will work:

    for (auto* marker : markersFor(node)) {

However, some other similar constructions wouldn’t work. Only the result of the entire expression on the right gets its lifetime extended in the right way. So maybe you don’t want to do this?

> Source/WebCore/dom/DocumentMarkerController.cpp:681
> +        Vector<RenderedDocumentMarker*> markers = markersFor(node);
> +        for (auto* marker : markers) {

Same thing again.

> Source/WebCore/editing/AlternativeTextController.cpp:474
> +    Vector<RenderedDocumentMarker*> markers = node->document().markers().markersFor(node);
> +    for (const auto* marker : markers) {

Same thing again. Also not sure why we bother putting the const here; doesn’t add much.

> Source/WebCore/editing/AlternativeTextController.cpp:554
> +    Vector<RenderedDocumentMarker*> correctedOnceMarkers = markers.markersInRange(rangeOfCorrection, DocumentMarker::Autocorrected);

A line like this is where other people hate, and I love, auto.

> Source/WebCore/editing/AlternativeTextController.cpp:735
>      for (size_t i = 0; i < dictationAlternativesMarkers.size(); ++i)

Could use a modern for loop here.

> Source/WebCore/rendering/InlineTextBox.h:161
> -    void paintDocumentMarker(GraphicsContext*, const FloatPoint& boxOrigin, DocumentMarker*, const RenderStyle&, const Font&, bool grammar);
> -    void paintTextMatchMarker(GraphicsContext*, const FloatPoint& boxOrigin, DocumentMarker*, const RenderStyle&, const Font&);
> +    void paintDocumentMarker(GraphicsContext*, const FloatPoint& boxOrigin, RenderedDocumentMarker*, const RenderStyle&, const Font&, bool grammar);
> +    void paintTextMatchMarker(GraphicsContext*, const FloatPoint& boxOrigin, RenderedDocumentMarker*, const RenderStyle&, const Font&);
>  
> -    void computeRectForReplacementMarker(DocumentMarker*, const RenderStyle&, const Font&);
> +    void computeRectForReplacementMarker(RenderedDocumentMarker*, const RenderStyle&, const Font&);

Seems like these should all take references, not pointers.
Comment 5 Chris Dumez 2014-10-19 20:52:32 PDT
Created attachment 240096 [details]
Patch
Comment 6 WebKit Commit Bot 2014-10-19 22:17:06 PDT
Comment on attachment 240096 [details]
Patch

Clearing flags on attachment: 240096

Committed r174876: <http://trac.webkit.org/changeset/174876>
Comment 7 WebKit Commit Bot 2014-10-19 22:17:13 PDT
All reviewed patches have been landed.  Closing bug.
Comment 8 Ryosuke Niwa 2017-10-19 13:25:32 PDT
Nice!