Bug 223030 - Use RetainPtr<> / OSObjectPtr<> more in WebKit
Summary: Use RetainPtr<> / OSObjectPtr<> more in WebKit
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks: 223049
  Show dependency treegraph
 
Reported: 2021-03-10 10:18 PST by Chris Dumez
Modified: 2021-03-10 17:40 PST (History)
28 users (show)

See Also:


Attachments
Patch (215.12 KB, patch)
2021-03-10 10:27 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (215.12 KB, patch)
2021-03-10 10:33 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (215.13 KB, patch)
2021-03-10 10:45 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (214.80 KB, patch)
2021-03-10 10:50 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (212.61 KB, patch)
2021-03-10 11:06 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (212.76 KB, patch)
2021-03-10 11:34 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (212.75 KB, patch)
2021-03-10 12:36 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (212.71 KB, patch)
2021-03-10 13:10 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (212.72 KB, patch)
2021-03-10 15:14 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (212.75 KB, patch)
2021-03-10 15:26 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2021-03-10 10:18:12 PST
Use RetainPtr<> / OSObjectPtr<> more in WebKit.
Comment 1 Chris Dumez 2021-03-10 10:27:41 PST
Created attachment 422843 [details]
Patch
Comment 2 Chris Dumez 2021-03-10 10:33:00 PST
Created attachment 422844 [details]
Patch
Comment 3 Chris Dumez 2021-03-10 10:45:11 PST
Created attachment 422845 [details]
Patch
Comment 4 Chris Dumez 2021-03-10 10:50:22 PST
Created attachment 422846 [details]
Patch
Comment 5 Chris Dumez 2021-03-10 11:06:26 PST
Created attachment 422849 [details]
Patch
Comment 6 Chris Dumez 2021-03-10 11:34:10 PST
Created attachment 422851 [details]
Patch
Comment 7 Chris Dumez 2021-03-10 12:36:00 PST
Created attachment 422858 [details]
Patch
Comment 8 Chris Dumez 2021-03-10 13:10:38 PST
Created attachment 422863 [details]
Patch
Comment 9 Darin Adler 2021-03-10 14:38:49 PST
Comment on attachment 422863 [details]
Patch

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

> Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:161
> +    inline dispatch_queue_t dispatchQueue() const { return m_notificationQueue.get(); }

Unneeded use of "inline" here and throughout this class.

> Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:1569
> +    m_avPlayer = playerRef;

Seems a slight shame that we hold one reference in the object and another in a local variable. Could we just use m_avPlayer directly throughout?

> Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:1609
> +    auto itemRef = adoptF(AVCFPlayerItemCreateWithAsset(kCFAllocatorDefault, avAsset(), m_notificationQueue.get()));
> +    m_avPlayerItem = itemRef;

Ditto.

> Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:1759
> +        static const CFStringRef keyNames[] = {
>              AVCFAssetPropertyPlayable
>          };
> -        propertyKeyName = CFArrayCreate(0, (const void**)keyNames, sizeof(keyNames) / sizeof(keyNames[0]), &kCFTypeArrayCallBacks);
> -    }
> +        return adoptCF(CFArrayCreate(0, (const void**)keyNames, sizeof(keyNames) / sizeof(keyNames[0]), &kCFTypeArrayCallBacks));

Since this code is only called once, we can write it more simply and not try to optimize so much and write such strange code. If this was Objective-C I would just write @[ AVCFAssetPropertyPlayable ] with typecasts. Here we could:

1) Type the local variable to match what the function takes, const void* elements instead of CFStringRef elements.
2) Don't use a static because this is one time code so it’s fine to dynamically allocate the array.
3) Because of (1) and (2) don’t need to typecast when calling CFArrayCreate.
4) Use std::size instead of sizeof(x) / sizeof(x[0]).

> Source/WebCore/platform/graphics/cg/PathCG.cpp:232
>      bool ret = CGPathContainsPoint(path.get(), 0, point, rule == WindRule::EvenOdd ? true : false);
>      return ret;

This code is funny. Lets write it more the way we would if it was new today:

    return CGPathContainsPoint(path.get(), nullptr, point, rule == WindRule::EvenOdd);

> Source/WebCore/platform/network/cf/CredentialStorageCFNet.cpp:49
> +    auto protectionSpaceCF = createCF(protectionSpace);
> +    auto credentialCF = copyCredentialFromProtectionSpace(protectionSpaceCF.get());
>      return core(credentialCF.get());

Would work fine in a single line:

    return core(copyCredentialFromProtectionSpace(createCF(protectionSpace).get()).get());

> Source/WebCore/platform/text/mac/TextBoundaries.mm:75
>          const char* temp = currentTextBreakLocaleID();

"temp"

> Source/WebCore/platform/text/mac/TextBoundaries.mm:80
> +    if (!locale.get())

Do we need .get() here?

> Source/WebCore/platform/text/mac/TextBoundaries.mm:86
> +    if (!tokenizer.get())

Do we need .get() here?
Comment 10 Chris Dumez 2021-03-10 15:14:23 PST
Created attachment 422878 [details]
Patch
Comment 11 Chris Dumez 2021-03-10 15:23:24 PST
(In reply to Darin Adler from comment #9)
> Comment on attachment 422863 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=422863&action=review
> 
> > Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:161
> > +    inline dispatch_queue_t dispatchQueue() const { return m_notificationQueue.get(); }
> 
> Unneeded use of "inline" here and throughout this class.
> 
> > Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:1569
> > +    m_avPlayer = playerRef;
> 
> Seems a slight shame that we hold one reference in the object and another in
> a local variable. Could we just use m_avPlayer directly throughout?
> 
> > Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:1609
> > +    auto itemRef = adoptF(AVCFPlayerItemCreateWithAsset(kCFAllocatorDefault, avAsset(), m_notificationQueue.get()));
> > +    m_avPlayerItem = itemRef;
> 
> Ditto.
> 
> > Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:1759
> > +        static const CFStringRef keyNames[] = {
> >              AVCFAssetPropertyPlayable
> >          };
> > -        propertyKeyName = CFArrayCreate(0, (const void**)keyNames, sizeof(keyNames) / sizeof(keyNames[0]), &kCFTypeArrayCallBacks);
> > -    }
> > +        return adoptCF(CFArrayCreate(0, (const void**)keyNames, sizeof(keyNames) / sizeof(keyNames[0]), &kCFTypeArrayCallBacks));
> 
> Since this code is only called once, we can write it more simply and not try
> to optimize so much and write such strange code. If this was Objective-C I
> would just write @[ AVCFAssetPropertyPlayable ] with typecasts. Here we
> could:
> 
> 1) Type the local variable to match what the function takes, const void*
> elements instead of CFStringRef elements.
> 2) Don't use a static because this is one time code so it’s fine to
> dynamically allocate the array.
> 3) Because of (1) and (2) don’t need to typecast when calling CFArrayCreate.
> 4) Use std::size instead of sizeof(x) / sizeof(x[0]).
> 
> > Source/WebCore/platform/graphics/cg/PathCG.cpp:232
> >      bool ret = CGPathContainsPoint(path.get(), 0, point, rule == WindRule::EvenOdd ? true : false);
> >      return ret;
> 
> This code is funny. Lets write it more the way we would if it was new today:
> 
>     return CGPathContainsPoint(path.get(), nullptr, point, rule ==
> WindRule::EvenOdd);
> 
> > Source/WebCore/platform/network/cf/CredentialStorageCFNet.cpp:49
> > +    auto protectionSpaceCF = createCF(protectionSpace);
> > +    auto credentialCF = copyCredentialFromProtectionSpace(protectionSpaceCF.get());
> >      return core(credentialCF.get());
> 
> Would work fine in a single line:
> 
>     return
> core(copyCredentialFromProtectionSpace(createCF(protectionSpace).get()).
> get());
> 
> > Source/WebCore/platform/text/mac/TextBoundaries.mm:75
> >          const char* temp = currentTextBreakLocaleID();
> 
> "temp"
> 
> > Source/WebCore/platform/text/mac/TextBoundaries.mm:80
> > +    if (!locale.get())
> 
> Do we need .get() here?
> 
> > Source/WebCore/platform/text/mac/TextBoundaries.mm:86
> > +    if (!tokenizer.get())
> 
> Do we need .get() here?

Yes, they were needed:
./platform/text/mac/TextBoundaries.mm:80:9: error: invalid argument type 'WTF::NeverDestroyed<WTF::RetainPtr<const __CFLocale *>, WTF::AnyThreadsAccessTraits>' to unary expression
    if (!locale)
        ^~~~~~~
./platform/text/mac/TextBoundaries.mm:86:9: error: invalid argument type 'NeverDestroyed<RetainPtr<CFStringTokenizerRef> >' (aka 'NeverDestroyed<RetainPtr<__CFStringTokenizer *> >') to unary expression
    if (!tokenizer)
        ^~~~~~~~~~
Comment 12 Chris Dumez 2021-03-10 15:26:02 PST
Created attachment 422881 [details]
Patch
Comment 13 Chris Dumez 2021-03-10 17:08:25 PST
Comment on attachment 422881 [details]
Patch

Clearing flags on attachment: 422881

Committed r274252 (235156@main): <https://commits.webkit.org/235156@main>
Comment 14 Chris Dumez 2021-03-10 17:08:29 PST
All reviewed patches have been landed.  Closing bug.
Comment 15 Radar WebKit Bug Importer 2021-03-10 17:09:15 PST
<rdar://problem/75291371>