HashMap<Ref<T>>::take should return RefPtr<T> instead of Optional<Ref<T>>.
Created attachment 407253 [details] Patch
Comment on attachment 407253 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=407253&action=review Looks like an improvement at almost every call site. > Source/WTF/wtf/HashTraits.h:215 > + typedef RefPtr<P> TakeType; Since we’re touching it we could use using instead of typedef. > Source/WebCore/dom/ScriptRunner.cpp:102 > - ASSERT(m_pendingAsyncScripts.contains(pendingScript)); > - m_scriptsToExecuteSoon.append(m_pendingAsyncScripts.take(pendingScript)->ptr()); > + auto script = m_pendingAsyncScripts.take(pendingScript); > + ASSERT(script); > + m_scriptsToExecuteSoon.append(script.releaseNonNull()); This is an example where the "after" looks worse because releaseNonNull is such a long function name. But I see that there was reference count churn in the old version! No need to assert non-null separately before calling releaseNonNull, because that asserts. I would write this as a one-liner, I think.
(In reply to Darin Adler from comment #2) > Comment on attachment 407253 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=407253&action=review > > Looks like an improvement at almost every call site. > > > Source/WTF/wtf/HashTraits.h:215 > > + typedef RefPtr<P> TakeType; > > Since we’re touching it we could use using instead of typedef. Fixed. I'm gonna also fix PeekType. > > Source/WebCore/dom/ScriptRunner.cpp:102 > > - ASSERT(m_pendingAsyncScripts.contains(pendingScript)); > > - m_scriptsToExecuteSoon.append(m_pendingAsyncScripts.take(pendingScript)->ptr()); > > + auto script = m_pendingAsyncScripts.take(pendingScript); > > + ASSERT(script); > > + m_scriptsToExecuteSoon.append(script.releaseNonNull()); > > This is an example where the "after" looks worse because releaseNonNull is > such a long function name. But I see that there was reference count churn in > the old version! > > No need to assert non-null separately before calling releaseNonNull, because > that asserts. I would write this as a one-liner, I think. Sure, I'd use the one liner.
Created attachment 407256 [details] Patch for landing
Committed r266157: <https://trac.webkit.org/changeset/266157> All reviewed patches have been landed. Closing bug and clearing flags on attachment 407256 [details].
<rdar://problem/67774006>