Bug 1598915 - [1/2] Drive-by cleanup: replace manual pointer-fiddling with RefPtr r=win-reviewers,handyman

`nsDataObj::mTransferable`'s lifecycle and ownership semantics are
trivially that of `RefPtr`. Use it.

(We do not presently extend this to `m_enumFE`, below; according to
comments in IEnumFE.h, that one's less trivial.)

No functional changes.

Differential Revision: https://phabricator.services.mozilla.com/D216624
This commit is contained in:
Ray Kraesig 2024-07-16 22:09:38 +00:00
parent c9db119981
commit 93c15cc946
2 changed files with 4 additions and 14 deletions

View File

@ -530,7 +530,7 @@ nsDataObj::nsDataObj(nsIURI* uri)
// destruction
//-----------------------------------------------------
nsDataObj::~nsDataObj() {
NS_IF_RELEASE(mTransferable);
mTransferable = nullptr;
mDataFlavors.Clear();
@ -774,7 +774,7 @@ STDMETHODIMP nsDataObj::GetData(LPFORMATETC aFormat, LPSTGMEDIUM pSTM) {
// ("***** nsDataObj::GetData - Unknown format %u\n", format));
return GetText(df, *aFormat, *pSTM);
} // switch
} // if
} // if
dfInx++;
} // while
@ -1861,16 +1861,7 @@ void nsDataObj::AddDataFlavor(const char* aDataFlavor, LPFORMATETC aFE) {
// Sets the transferable object
//-----------------------------------------------------
void nsDataObj::SetTransferable(nsITransferable* aTransferable) {
NS_IF_RELEASE(mTransferable);
mTransferable = aTransferable;
if (nullptr == mTransferable) {
return;
}
NS_ADDREF(mTransferable);
return;
}
//

View File

@ -166,9 +166,8 @@ class nsDataObj : public IDataObject, public IDataObjectAsyncCapability {
private:
nsTArray<nsCString> mDataFlavors;
nsITransferable* mTransferable; // nsDataObj owns and ref counts
// nsITransferable, the nsITransferable does
// know anything about the nsDataObj
// the nsITransferable knows nothing about the nsDataObj
RefPtr<nsITransferable> mTransferable;
protected:
CEnumFormatEtc* m_enumFE; // Ownership Rules: