| Summary: | HashMap<Ref<T>>::take should return RefPtr<T> | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | WebKit | Reporter: | Ryosuke Niwa <rniwa> | ||||||
| Component: | Web Template Framework | Assignee: | Ryosuke Niwa <rniwa> | ||||||
| Status: | RESOLVED FIXED | ||||||||
| Severity: | Normal | CC: | aboxhall, alecflett, apinheiro, beidson, benjamin, cdumez, cfleizach, cmarcelo, darin, dmazzoni, eric.carlson, esprehn+autocc, ews-watchlist, glenn, hi, hta, jcraig, jdiggs, jer.noble, jiewen_tan, joepeck, jsbell, kangil.han, mjs, philipj, samuel_white, sam, sergio, tommyw, webkit-bug-importer | ||||||
| Priority: | P2 | Keywords: | InRadar | ||||||
| Version: | WebKit Nightly Build | ||||||||
| Hardware: | All | ||||||||
| OS: | All | ||||||||
| See Also: | https://bugs.webkit.org/show_bug.cgi?id=215562 | ||||||||
| Attachments: |
|
||||||||
|
Description
Ryosuke Niwa
2020-08-25 16:50:36 PDT
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]. |