Bug 1964823 - Introduce AutoTypeRef::Take to simplify code r=padenot,media-playback-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D248140
This commit is contained in:
CM
2025-05-08 19:05:00 +00:00
committed by cchang@mozilla.com
parent af987a3550
commit c8711878f8

View File

@@ -134,15 +134,11 @@ class AutoTypeRef {
}
// Move constructor
AutoTypeRef(AutoTypeRef<T, Traits>&& aOther) : mObj(aOther.mObj) {
aOther.mObj = Traits::InvalidValue();
}
AutoTypeRef(AutoTypeRef<T, Traits>&& aOther) : mObj(aOther.Take()) {}
// Move assignment
AutoTypeRef<T, Traits>& operator=(const AutoTypeRef<T, Traits>&& aOther) {
ReleaseIfNeeded();
mObj = aOther.mObj;
aOther.mObj = Traits::InvalidValue();
Reset(aOther.Take(), AutoTypePolicy::NoRetain);
return *this;
}
@@ -172,6 +168,12 @@ class AutoTypeRef {
}
private:
T Take() {
T obj = mObj;
mObj = Traits::InvalidValue();
return obj;
}
void ReleaseIfNeeded() {
if (mObj != Traits::InvalidValue()) {
Traits::Release(mObj);