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