Bug 210396

Summary: Stop using live ranges in functions that return range of the selection
Product: WebKit Reporter: Darin Adler <darin>
Component: HTML EditingAssignee: Darin Adler <darin>
Status: RESOLVED FIXED    
Severity: Normal CC: aboxhall, apinheiro, cdumez, cfleizach, dmazzoni, eric.carlson, esprehn+autocc, ews-watchlist, glenn, gyuyoung.kim, jcraig, jdiggs, jer.noble, kangil.han, kondapallykalyan, mifenton, pdr, philipj, samuel_white, sam, sergio, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch sam: review+

Description Darin Adler 2020-04-11 16:52:08 PDT
Stop using live ranges in functions that return range of the selection
Comment 1 Darin Adler 2020-04-11 17:39:29 PDT Comment hidden (obsolete)
Comment 2 Darin Adler 2020-04-11 17:40:04 PDT Comment hidden (obsolete)
Comment 3 Darin Adler 2020-04-11 17:46:16 PDT Comment hidden (obsolete)
Comment 4 Darin Adler 2020-04-11 17:51:54 PDT Comment hidden (obsolete)
Comment 5 Darin Adler 2020-04-12 10:23:30 PDT Comment hidden (obsolete)
Comment 6 Darin Adler 2020-04-21 12:04:29 PDT Comment hidden (obsolete)
Comment 7 Darin Adler 2020-04-21 12:07:00 PDT Comment hidden (obsolete)
Comment 8 Darin Adler 2020-04-21 12:23:32 PDT Comment hidden (obsolete)
Comment 9 Darin Adler 2020-04-21 18:48:32 PDT Comment hidden (obsolete)
Comment 10 Darin Adler 2020-04-21 21:32:22 PDT Comment hidden (obsolete)
Comment 11 Darin Adler 2020-04-22 18:16:18 PDT Comment hidden (obsolete)
Comment 12 Darin Adler 2020-04-22 22:05:08 PDT
Created attachment 397317 [details]
Patch
Comment 13 Sam Weinig 2020-04-25 18:41:55 PDT
Comment on attachment 397317 [details]
Patch

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

So many good and juicy follow ups here. Very nice.

> Source/WebCore/editing/cocoa/HTMLConverter.mm:422
>      if (documentAttributes)
> -        *documentAttributes = [[_documentAttrs retain] autorelease];
> +        *documentAttributes = _documentAttrs;

Makes me wonder if this family of functions should always return a std::pair<RetainPtr<NSAttributedString>, RetainPtr<NSDictionary>>, rather than making this optional. Will trade off a branch for a retain. Doesn't really matter, but the out parameter has always bugged me and now that we can use structured bindings, the pair is not a mess anymore.
Comment 14 Darin Adler 2020-04-26 08:03:22 PDT
Comment on attachment 397317 [details]
Patch

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

> Source/WebCore/ChangeLog:12
> +          against tree changes while iteratoring; it will now always stop at the

misspelled iterating

> Source/WebCore/editing/cocoa/EditorCocoa.mm:111
> +    return range ? attributedString(*range) : adoptNS([[NSAttributedString alloc] initWithString:@""]);

I think init instead of initWithString: here.

>> Source/WebCore/editing/cocoa/HTMLConverter.mm:422
>> +        *documentAttributes = _documentAttrs;
> 
> Makes me wonder if this family of functions should always return a std::pair<RetainPtr<NSAttributedString>, RetainPtr<NSDictionary>>, rather than making this optional. Will trade off a branch for a retain. Doesn't really matter, but the out parameter has always bugged me and now that we can use structured bindings, the pair is not a mess anymore.

And I suppose there is no savings here when the caller doesn’t ask for the attributes. They are simply computed and dumped on the floor. I think I’d use a named struct rather than a tuple  or pair though. While the string is self explanatory for the type NSAttributedString I don’t think that NSDictionary for “document attributes” is clear without a name.

> Source/WebKitLegacy/mac/WebView/WebHTMLRepresentation.mm:272
> +        return [[[NSAttributedString alloc] initWithString:@""] autorelease];

I think init instead of initWithString: here.

> Source/WebKitLegacy/mac/WebView/WebHTMLView.mm:7017
> +        return [[[NSAttributedString alloc] initWithString:@""] autorelease];

I think init instead of initWithString: here.

> Source/WebKitLegacy/mac/WebView/WebHTMLView.mm:7026
> +        return [[[NSAttributedString alloc] initWithString:@""] autorelease];

I think init instead of initWithString: here.
Comment 15 Darin Adler 2020-04-26 08:31:40 PDT
I decided to fix the misspelling and do everything else in a separate follow-up patch.
Comment 16 Darin Adler 2020-04-26 08:33:11 PDT
Committed r260725: <https://trac.webkit.org/changeset/260725>
Comment 17 Radar WebKit Bug Importer 2020-04-26 08:34:15 PDT
<rdar://problem/62396029>