Bug 1665373 - Bail earlier if getting a null ref to NS_ReleaseOnMainThread. r=sg

This is just a minor optimization, not intended to change behavior.

Differential Revision: https://phabricator.services.mozilla.com/D90398
This commit is contained in:
Emilio Cobos Álvarez 2020-09-16 22:58:46 +00:00
parent 29b27e6d30
commit 47f53144a5

View File

@ -149,6 +149,11 @@ template <class T>
inline NS_HIDDEN_(void)
NS_ReleaseOnMainThread(const char* aName, already_AddRefed<T> aDoomed,
bool aAlwaysProxy = false) {
RefPtr<T> doomed = aDoomed;
if (!doomed) {
return; // Nothing to do.
}
// NS_ProxyRelease treats a null event target as "the current thread". So a
// handle on the main thread is only necessary when we're not already on the
// main thread or the release must happen asynchronously.
@ -158,12 +163,12 @@ inline NS_HIDDEN_(void)
if (!target) {
MOZ_ASSERT_UNREACHABLE("Could not get main thread; leaking an object!");
mozilla::Unused << aDoomed.take();
mozilla::Unused << doomed.forget().take();
return;
}
}
NS_ProxyRelease(aName, target, std::move(aDoomed), aAlwaysProxy);
NS_ProxyRelease(aName, target, doomed.forget(), aAlwaysProxy);
}
template <class T>