Bug 211058

Summary: Replace more uses of live ranges with SimpleRange
Product: WebKit Reporter: Darin Adler <darin>
Component: DOMAssignee: Darin Adler <darin>
Status: RESOLVED FIXED    
Severity: Normal CC: aboxhall, andersca, apinheiro, cdumez, cfleizach, dmazzoni, eric.carlson, esprehn+autocc, ews-watchlist, glenn, japhet, jcraig, jdiggs, jer.noble, kangil.han, koivisto, mifenton, philipj, samuel_white, sam, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch koivisto: review+

Description Darin Adler 2020-04-26 17:37:15 PDT
Replace more uses of live ranges with SimpleRange
Comment 1 Darin Adler 2020-04-26 17:57:24 PDT Comment hidden (obsolete)
Comment 2 Darin Adler 2020-04-26 17:59:39 PDT Comment hidden (obsolete)
Comment 3 Darin Adler 2020-04-26 22:02:00 PDT Comment hidden (obsolete)
Comment 4 Darin Adler 2020-04-26 22:35:41 PDT
Created attachment 397645 [details]
Patch
Comment 5 Darin Adler 2020-04-26 22:37:57 PDT
Reducing live ranges is going to take a while, it seems. Might decide to set a breakpoint and prioritize paths that are called during normal webpage loads next. For this patch I just searched for instances of Range::create and then followed up with whatever changes were needed to make them go away.
Comment 6 Antti Koivisto 2020-04-27 00:11:23 PDT
Comment on attachment 397645 [details]
Patch

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

> Source/WebCore/dom/Node.cpp:2624
> +RefPtr<Node> commonInclusiveAncestor(Node& a, Node& b)
> +{
> +    for (auto ancestorA = &a; ancestorA; ancestorA = ancestorA->parentNode()) {
> +        for (auto ancestorB = &b; ancestorB; ancestorB = ancestorB->parentNode()) {
> +            if (ancestorA == ancestorB)
> +                return ancestorA;
> +        }
> +    }
> +    return nullptr;
> +}

This is a pretty inefficient implementation (I know it is not new in this patch).

> Source/WebCore/editing/VisibleSelection.cpp:210
> +    if (!scope)
> +        return WTF::nullopt;

I would just return { };

> Source/WebCore/editing/cocoa/DataDetection.h:52
> +enum class DataDetectorTypes : uint32_t {
> +    None = 0,
> +    PhoneNumber = 1 << 0,
> +    Link = 1 << 1,
> +    Address = 1 << 2,
> +    CalendarEvent = 1 << 3,
> +    TrackingNumber = 1 << 4,
> +    FlightNumber = 1 << 5,
> +    LookupSuggestion = 1 << 6,
> +};

Simon would tell you to line these up.
Comment 7 Darin Adler 2020-04-27 07:21:05 PDT
Comment on attachment 397645 [details]
Patch

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

>> Source/WebCore/dom/Node.cpp:2624
>> +}
> 
> This is a pretty inefficient implementation (I know it is not new in this patch).

Yes definitely. I noticed that, too. Do you have ideas for a better one? I didn’t immediately think of one.

>> Source/WebCore/editing/VisibleSelection.cpp:210
>> +        return WTF::nullopt;
> 
> I would just return { };

That does seem appealing. Although I have checked in a lot of “return nullopt” in patches recently.
Comment 8 Darin Adler 2020-04-27 07:25:06 PDT
Comment on attachment 397645 [details]
Patch

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

>>> Source/WebCore/dom/Node.cpp:2624
>>> +}
>> 
>> This is a pretty inefficient implementation (I know it is not new in this patch).
> 
> Yes definitely. I noticed that, too. Do you have ideas for a better one? I didn’t immediately think of one.

I looked at https://en.wikipedia.org/wiki/Lowest_common_ancestor and did not immediately find something useful.
Comment 9 Darin Adler 2020-04-27 07:31:29 PDT
Maybe one trip each to find the roots and distance to the root, return null if the roots are different, then walk up both at the same time, keeping distance from root constant.
Comment 10 Darin Adler 2020-04-27 07:53:54 PDT
Comment on attachment 397645 [details]
Patch

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

>>>> Source/WebCore/dom/Node.cpp:2624
>>>> +}
>>> 
>>> This is a pretty inefficient implementation (I know it is not new in this patch).
>> 
>> Yes definitely. I noticed that, too. Do you have ideas for a better one? I didn’t immediately think of one.
> 
> I looked at https://en.wikipedia.org/wiki/Lowest_common_ancestor and did not immediately find something useful.

I’m going to fix this in a follow-up patch now that I figured out how.

>>> Source/WebCore/editing/VisibleSelection.cpp:210
>>> +        return WTF::nullopt;
>> 
>> I would just return { };
> 
> That does seem appealing. Although I have checked in a lot of “return nullopt” in patches recently.

Will do this before landing.

>> Source/WebCore/editing/cocoa/DataDetection.h:52
>> +};
> 
> Simon would tell you to line these up.

Not sure how to resolve this minor code style disagreement.
Comment 11 Darin Adler 2020-04-27 08:05:13 PDT
Committed r260753: <https://trac.webkit.org/changeset/260753>
Comment 12 Radar WebKit Bug Importer 2020-04-27 08:06:15 PDT
<rdar://problem/62452499>
Comment 13 Darin Adler 2020-04-27 08:25:27 PDT
Comment on attachment 397645 [details]
Patch

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

>>>>> Source/WebCore/dom/Node.cpp:2624
>>>>> +}
>>>> 
>>>> This is a pretty inefficient implementation (I know it is not new in this patch).
>>> 
>>> Yes definitely. I noticed that, too. Do you have ideas for a better one? I didn’t immediately think of one.
>> 
>> I looked at https://en.wikipedia.org/wiki/Lowest_common_ancestor and did not immediately find something useful.
> 
> I’m going to fix this in a follow-up patch now that I figured out how.

Bug 211078.
Comment 14 Antti Koivisto 2020-04-27 09:14:23 PDT
> That does seem appealing. Although I have checked in a lot of “return
> nullopt” in patches recently.

I know and think both approaches are fine.
Comment 15 Darin Adler 2020-05-06 11:56:13 PDT
Comment on attachment 397645 [details]
Patch

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

> Source/WebCore/page/TextIndicator.cpp:200
> -        auto* node = iterator.node();
> -        if (!is<Text>(node) || !is<RenderText>(node->renderer()))
> -            continue;
> -
> -        colors.add(node->renderer()->style().color());
> +        auto renderer = iterator.node()->renderer();
> +        if (is<RenderText>(renderer))
> +            colors.add(renderer->style().color());

This change accidentally removed the null check done by is<Text>(node). We don’t need and is<Text> check, but we do need a null check.