Bug 1157803 - Clean up Canonical assigment to avoid accidentally tripping the default operator= implementation. r=jww

This commit is contained in:
Bobby Holley 2015-04-28 16:56:07 -07:00
parent 4eb53fa0b1
commit aa0a30b445

View File

@ -155,12 +155,12 @@ public:
return mValue;
}
Canonical& operator=(const T& aNewValue)
void Set(const T& aNewValue)
{
MOZ_ASSERT(OwnerThread()->IsCurrentThreadIn());
if (aNewValue == mValue) {
return *this;
return;
}
// Notify same-thread watchers. The state watching machinery will make sure
@ -184,10 +184,12 @@ public:
nsCOMPtr<nsIRunnable> r = NS_NewRunnableMethod(this, &Canonical::DoNotify);
AbstractThread::GetCurrent()->TailDispatcher().AddDirectTask(r.forget());
}
return *this;
}
Canonical& operator=(const T& aNewValue) { Set(aNewValue); return *this; }
Canonical& operator=(const Canonical& aOther) { Set(aOther); return *this; }
Canonical(const Canonical& aOther) = delete;
class Holder
{
public:
@ -211,7 +213,10 @@ public:
// Access to the T.
const T& Ref() const { return *mCanonical; }
operator const T&() const { return Ref(); }
Holder& operator=(const T& aNewValue) { *mCanonical = aNewValue; return *this; }
void Set(const T& aNewValue) { mCanonical->Set(aNewValue); }
Holder& operator=(const T& aNewValue) { Set(aNewValue); return *this; }
Holder& operator=(const Holder& aOther) { Set(aOther); return *this; }
Holder(const Holder& aOther) = delete;
private:
nsRefPtr<Canonical<T>> mCanonical;