From 3b5f2c1e2157e8a858b1e281bfad8f76d4c2be29 Mon Sep 17 00:00:00 2001 From: "kipp%netscape.com" Date: Thu, 7 Oct 1999 20:45:56 +0000 Subject: [PATCH] r=kin; Added in ctor/dtor counts git-svn-id: svn://10.0.0.236/trunk@50126 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/editor/base/EditTxn.cpp | 4 ++ mozilla/editor/base/nsEditor.cpp | 75 ++++++++++++++-------- mozilla/editor/libeditor/base/EditTxn.cpp | 4 ++ mozilla/editor/libeditor/base/nsEditor.cpp | 75 ++++++++++++++-------- 4 files changed, 102 insertions(+), 56 deletions(-) diff --git a/mozilla/editor/base/EditTxn.cpp b/mozilla/editor/base/EditTxn.cpp index ecd47a5361b..dc874d252b3 100644 --- a/mozilla/editor/base/EditTxn.cpp +++ b/mozilla/editor/base/EditTxn.cpp @@ -27,15 +27,19 @@ static NS_DEFINE_IID(kITransactionIID, NS_ITRANSACTION_IID); NS_IMPL_ADDREF(EditTxn) NS_IMPL_RELEASE(EditTxn) +MOZ_DECL_CTOR_COUNTER(EditTxn); + // note that aEditor is not refcounted EditTxn::EditTxn() : mTransactionID(-1) { + MOZ_COUNT_CTOR(EditTxn); NS_INIT_REFCNT(); } EditTxn::~EditTxn() { + MOZ_COUNT_DTOR(EditTxn); } NS_IMETHODIMP EditTxn::Do(void) diff --git a/mozilla/editor/base/nsEditor.cpp b/mozilla/editor/base/nsEditor.cpp index ed6695e6d44..b9d45117a1f 100644 --- a/mozilla/editor/base/nsEditor.cpp +++ b/mozilla/editor/base/nsEditor.cpp @@ -137,6 +137,8 @@ static const PRBool gNoisy = PR_FALSE; PRInt32 nsEditor::gInstanceCount = 0; +MOZ_DECL_CTOR_COUNTER(nsEditor); + //class implementations are in order they are declared in nsEditor.h @@ -144,16 +146,18 @@ nsEditor::nsEditor() : mPresShellWeak(nsnull) , mViewManager(nsnull) , mUpdateCount(0) -, mActionListeners(nsnull) -, mDocDirtyState(-1) -, mDocWeak(nsnull) , mPlaceHolderTxn(nsnull) , mPlaceHolderName(nsnull) , mPlaceHolderBatch(0) , mTxnStartNode(nsnull) , mTxnStartOffset(0) +, mActionListeners(nsnull) +, mDocDirtyState(-1) +, mDocWeak(nsnull) { + MOZ_COUNT_CTOR(nsEditor); + //initialize member variables here NS_INIT_REFCNT(); PR_EnterMonitor(GetEditorMonitor()); @@ -163,6 +167,8 @@ nsEditor::nsEditor() nsEditor::~nsEditor() { + MOZ_COUNT_DTOR(nsEditor); + // not sure if this needs to be called earlier. NotifyDocumentListeners(eDocumentToBeDestroyed); @@ -353,9 +359,10 @@ nsEditor::Do(nsITransaction *aTxn) { // it's pretty darn amazing how many different types of pointers // this transcation goes through here. I bet this is a record. - EditTxn *editTxn; + nsCOMPtr editTxn; nsCOMPtr plcTxn; - result = TransactionFactory::GetNewTransaction(PlaceholderTxn::GetCID(), &editTxn); + result = TransactionFactory::GetNewTransaction(PlaceholderTxn::GetCID(), + getter_AddRefs(editTxn)); if (NS_FAILED(result)) { return result; } if (!editTxn) { return NS_ERROR_NULL_POINTER; } editTxn->QueryInterface(nsIAbsorbingTransaction::GetIID(), getter_AddRefs(plcTxn)); @@ -368,6 +375,7 @@ nsEditor::Do(nsITransaction *aTxn) // we will recurse, but will not hit this case in the nested call nsCOMPtr theTxn = do_QueryInterface(plcTxn); nsITransaction* txn = theTxn; + // we want to escape from this routine with a positive refcount txn->AddRef(); Do(txn); @@ -844,8 +852,9 @@ nsEditor::GetProperties(nsVoidArray *aPropList) NS_IMETHODIMP nsEditor::SetAttribute(nsIDOMElement *aElement, const nsString& aAttribute, const nsString& aValue) { - ChangeAttributeTxn *txn; - nsresult result = CreateTxnForSetAttribute(aElement, aAttribute, aValue, &txn); + nsCOMPtr txn; + nsresult result = CreateTxnForSetAttribute(aElement, aAttribute, aValue, + getter_AddRefs(txn)); if (NS_SUCCEEDED(result)) { result = Do(txn); } @@ -877,8 +886,9 @@ nsEditor::GetAttributeValue(nsIDOMElement *aElement, NS_IMETHODIMP nsEditor::RemoveAttribute(nsIDOMElement *aElement, const nsString& aAttribute) { - ChangeAttributeTxn *txn; - nsresult result = CreateTxnForRemoveAttribute(aElement, aAttribute, &txn); + nsCOMPtr txn; + nsresult result = CreateTxnForRemoveAttribute(aElement, aAttribute, + getter_AddRefs(txn)); if (NS_SUCCEEDED(result)) { result = Do(txn); } @@ -891,8 +901,9 @@ NS_IMETHODIMP nsEditor::CreateNode(const nsString& aTag, PRInt32 aPosition, nsIDOMNode ** aNewNode) { - CreateElementTxn *txn; - nsresult result = CreateTxnForCreateElement(aTag, aParent, aPosition, &txn); + nsCOMPtr txn; + nsresult result = CreateTxnForCreateElement(aTag, aParent, aPosition, + getter_AddRefs(txn)); if (NS_SUCCEEDED(result)) { result = Do(txn); @@ -1004,8 +1015,9 @@ nsEditor::InsertNoneditableTextNode(nsIDOMNode* parent, PRInt32 offset, // Can't call CreateNode, because that will call us recursively. // So duplicate what it does: - CreateElementTxn *txn; - res = CreateTxnForCreateElement(textNodeTag, parent, offset, &txn); + nsCOMPtr txn; + res = CreateTxnForCreateElement(textNodeTag, parent, offset, + getter_AddRefs(txn)); if (NS_FAILED(res)) return res; @@ -1137,8 +1149,8 @@ NS_IMETHODIMP nsEditor::DeleteNode(nsIDOMNode * aElement) } } - DeleteElementTxn *txn; - nsresult result = CreateTxnForDeleteElement(aElement, &txn); + nsCOMPtr txn; + nsresult result = CreateTxnForDeleteElement(aElement, getter_AddRefs(txn)); if (NS_SUCCEEDED(result)) { result = Do(txn); } @@ -1599,14 +1611,18 @@ nsresult nsEditor::GetTextNodeTag(nsString& aOutString) NS_IMETHODIMP nsEditor::InsertTextImpl(const nsString& aStringToInsert) { - EditAggregateTxn *aggTxn = nsnull; + nsCOMPtr aggTxn; // Create the "delete current selection" txn - nsresult result = CreateAggregateTxnForDeleteSelection(InsertTextTxn::gInsertTextTxnName, &aggTxn); - if ((NS_FAILED(result)) || (nsnull==aggTxn)) { + nsresult result = CreateAggregateTxnForDeleteSelection(InsertTextTxn::gInsertTextTxnName, + getter_AddRefs(aggTxn)); + if (NS_FAILED(result) || !aggTxn) { return NS_ERROR_OUT_OF_MEMORY; } - InsertTextTxn *txn; - result = CreateTxnForInsertText(aStringToInsert, nsnull, &txn); // insert at the current selection + + // insert at the current selection + nsCOMPtr txn; + result = CreateTxnForInsertText(aStringToInsert, nsnull, + getter_AddRefs(txn)); if ((NS_SUCCEEDED(result)) && txn) { BeginUpdateViewBatch(); // aggTxn->AppendChild(txn); @@ -1981,11 +1997,12 @@ NS_IMETHODIMP nsEditor::DoInitialInsert(const nsString & aStringToInsert) { // now we've got the body tag. // create transaction to insert the text node, // and create a transaction to insert the text - CreateElementTxn *txn; + nsCOMPtr txn; nsAutoString textNodeTag; result = GetTextNodeTag(textNodeTag); if (NS_FAILED(result)) { return result; } - result = CreateTxnForCreateElement(textNodeTag, node, 0, &txn); + result = CreateTxnForCreateElement(textNodeTag, node, 0, + getter_AddRefs(txn)); if ((NS_SUCCEEDED(result)) && txn) { result = Do(txn); @@ -2020,8 +2037,9 @@ NS_IMETHODIMP nsEditor::DeleteText(nsIDOMCharacterData *aElement, PRUint32 aOffset, PRUint32 aLength) { - DeleteTextTxn *txn; - nsresult result = CreateTxnForDeleteText(aElement, aOffset, aLength, &txn); + nsCOMPtr txn; + nsresult result = CreateTxnForDeleteText(aElement, aOffset, aLength, + getter_AddRefs(txn)); if (NS_SUCCEEDED(result)) { result = Do(txn); // HACKForceRedraw(); @@ -3323,11 +3341,12 @@ NS_IMETHODIMP nsEditor::DoInitialInputMethodInsert(const nsString & aStringToIns { // now we've got the body tag. // create transaction to insert the text node, // and create a transaction to insert the text - CreateElementTxn *txn; + nsCOMPtr txn; nsAutoString textNodeTag; result = GetTextNodeTag(textNodeTag); if (NS_FAILED(result)) { return result; } - result = CreateTxnForCreateElement(textNodeTag, node, 0, &txn); + result = CreateTxnForCreateElement(textNodeTag, node, 0, + getter_AddRefs(txn)); if ((NS_SUCCEEDED(result)) && txn) { result = Do(txn); @@ -4090,8 +4109,8 @@ nsEditor::DeleteSelectionImpl(ESelectionCollapseDirection aAction) { nsresult result; - EditAggregateTxn *txn; - result = CreateTxnForDeleteSelection(aAction, &txn); + nsCOMPtr txn; + result = CreateTxnForDeleteSelection(aAction, getter_AddRefs(txn)); if (NS_SUCCEEDED(result)) { result = Do(txn); } diff --git a/mozilla/editor/libeditor/base/EditTxn.cpp b/mozilla/editor/libeditor/base/EditTxn.cpp index ecd47a5361b..dc874d252b3 100644 --- a/mozilla/editor/libeditor/base/EditTxn.cpp +++ b/mozilla/editor/libeditor/base/EditTxn.cpp @@ -27,15 +27,19 @@ static NS_DEFINE_IID(kITransactionIID, NS_ITRANSACTION_IID); NS_IMPL_ADDREF(EditTxn) NS_IMPL_RELEASE(EditTxn) +MOZ_DECL_CTOR_COUNTER(EditTxn); + // note that aEditor is not refcounted EditTxn::EditTxn() : mTransactionID(-1) { + MOZ_COUNT_CTOR(EditTxn); NS_INIT_REFCNT(); } EditTxn::~EditTxn() { + MOZ_COUNT_DTOR(EditTxn); } NS_IMETHODIMP EditTxn::Do(void) diff --git a/mozilla/editor/libeditor/base/nsEditor.cpp b/mozilla/editor/libeditor/base/nsEditor.cpp index ed6695e6d44..b9d45117a1f 100644 --- a/mozilla/editor/libeditor/base/nsEditor.cpp +++ b/mozilla/editor/libeditor/base/nsEditor.cpp @@ -137,6 +137,8 @@ static const PRBool gNoisy = PR_FALSE; PRInt32 nsEditor::gInstanceCount = 0; +MOZ_DECL_CTOR_COUNTER(nsEditor); + //class implementations are in order they are declared in nsEditor.h @@ -144,16 +146,18 @@ nsEditor::nsEditor() : mPresShellWeak(nsnull) , mViewManager(nsnull) , mUpdateCount(0) -, mActionListeners(nsnull) -, mDocDirtyState(-1) -, mDocWeak(nsnull) , mPlaceHolderTxn(nsnull) , mPlaceHolderName(nsnull) , mPlaceHolderBatch(0) , mTxnStartNode(nsnull) , mTxnStartOffset(0) +, mActionListeners(nsnull) +, mDocDirtyState(-1) +, mDocWeak(nsnull) { + MOZ_COUNT_CTOR(nsEditor); + //initialize member variables here NS_INIT_REFCNT(); PR_EnterMonitor(GetEditorMonitor()); @@ -163,6 +167,8 @@ nsEditor::nsEditor() nsEditor::~nsEditor() { + MOZ_COUNT_DTOR(nsEditor); + // not sure if this needs to be called earlier. NotifyDocumentListeners(eDocumentToBeDestroyed); @@ -353,9 +359,10 @@ nsEditor::Do(nsITransaction *aTxn) { // it's pretty darn amazing how many different types of pointers // this transcation goes through here. I bet this is a record. - EditTxn *editTxn; + nsCOMPtr editTxn; nsCOMPtr plcTxn; - result = TransactionFactory::GetNewTransaction(PlaceholderTxn::GetCID(), &editTxn); + result = TransactionFactory::GetNewTransaction(PlaceholderTxn::GetCID(), + getter_AddRefs(editTxn)); if (NS_FAILED(result)) { return result; } if (!editTxn) { return NS_ERROR_NULL_POINTER; } editTxn->QueryInterface(nsIAbsorbingTransaction::GetIID(), getter_AddRefs(plcTxn)); @@ -368,6 +375,7 @@ nsEditor::Do(nsITransaction *aTxn) // we will recurse, but will not hit this case in the nested call nsCOMPtr theTxn = do_QueryInterface(plcTxn); nsITransaction* txn = theTxn; + // we want to escape from this routine with a positive refcount txn->AddRef(); Do(txn); @@ -844,8 +852,9 @@ nsEditor::GetProperties(nsVoidArray *aPropList) NS_IMETHODIMP nsEditor::SetAttribute(nsIDOMElement *aElement, const nsString& aAttribute, const nsString& aValue) { - ChangeAttributeTxn *txn; - nsresult result = CreateTxnForSetAttribute(aElement, aAttribute, aValue, &txn); + nsCOMPtr txn; + nsresult result = CreateTxnForSetAttribute(aElement, aAttribute, aValue, + getter_AddRefs(txn)); if (NS_SUCCEEDED(result)) { result = Do(txn); } @@ -877,8 +886,9 @@ nsEditor::GetAttributeValue(nsIDOMElement *aElement, NS_IMETHODIMP nsEditor::RemoveAttribute(nsIDOMElement *aElement, const nsString& aAttribute) { - ChangeAttributeTxn *txn; - nsresult result = CreateTxnForRemoveAttribute(aElement, aAttribute, &txn); + nsCOMPtr txn; + nsresult result = CreateTxnForRemoveAttribute(aElement, aAttribute, + getter_AddRefs(txn)); if (NS_SUCCEEDED(result)) { result = Do(txn); } @@ -891,8 +901,9 @@ NS_IMETHODIMP nsEditor::CreateNode(const nsString& aTag, PRInt32 aPosition, nsIDOMNode ** aNewNode) { - CreateElementTxn *txn; - nsresult result = CreateTxnForCreateElement(aTag, aParent, aPosition, &txn); + nsCOMPtr txn; + nsresult result = CreateTxnForCreateElement(aTag, aParent, aPosition, + getter_AddRefs(txn)); if (NS_SUCCEEDED(result)) { result = Do(txn); @@ -1004,8 +1015,9 @@ nsEditor::InsertNoneditableTextNode(nsIDOMNode* parent, PRInt32 offset, // Can't call CreateNode, because that will call us recursively. // So duplicate what it does: - CreateElementTxn *txn; - res = CreateTxnForCreateElement(textNodeTag, parent, offset, &txn); + nsCOMPtr txn; + res = CreateTxnForCreateElement(textNodeTag, parent, offset, + getter_AddRefs(txn)); if (NS_FAILED(res)) return res; @@ -1137,8 +1149,8 @@ NS_IMETHODIMP nsEditor::DeleteNode(nsIDOMNode * aElement) } } - DeleteElementTxn *txn; - nsresult result = CreateTxnForDeleteElement(aElement, &txn); + nsCOMPtr txn; + nsresult result = CreateTxnForDeleteElement(aElement, getter_AddRefs(txn)); if (NS_SUCCEEDED(result)) { result = Do(txn); } @@ -1599,14 +1611,18 @@ nsresult nsEditor::GetTextNodeTag(nsString& aOutString) NS_IMETHODIMP nsEditor::InsertTextImpl(const nsString& aStringToInsert) { - EditAggregateTxn *aggTxn = nsnull; + nsCOMPtr aggTxn; // Create the "delete current selection" txn - nsresult result = CreateAggregateTxnForDeleteSelection(InsertTextTxn::gInsertTextTxnName, &aggTxn); - if ((NS_FAILED(result)) || (nsnull==aggTxn)) { + nsresult result = CreateAggregateTxnForDeleteSelection(InsertTextTxn::gInsertTextTxnName, + getter_AddRefs(aggTxn)); + if (NS_FAILED(result) || !aggTxn) { return NS_ERROR_OUT_OF_MEMORY; } - InsertTextTxn *txn; - result = CreateTxnForInsertText(aStringToInsert, nsnull, &txn); // insert at the current selection + + // insert at the current selection + nsCOMPtr txn; + result = CreateTxnForInsertText(aStringToInsert, nsnull, + getter_AddRefs(txn)); if ((NS_SUCCEEDED(result)) && txn) { BeginUpdateViewBatch(); // aggTxn->AppendChild(txn); @@ -1981,11 +1997,12 @@ NS_IMETHODIMP nsEditor::DoInitialInsert(const nsString & aStringToInsert) { // now we've got the body tag. // create transaction to insert the text node, // and create a transaction to insert the text - CreateElementTxn *txn; + nsCOMPtr txn; nsAutoString textNodeTag; result = GetTextNodeTag(textNodeTag); if (NS_FAILED(result)) { return result; } - result = CreateTxnForCreateElement(textNodeTag, node, 0, &txn); + result = CreateTxnForCreateElement(textNodeTag, node, 0, + getter_AddRefs(txn)); if ((NS_SUCCEEDED(result)) && txn) { result = Do(txn); @@ -2020,8 +2037,9 @@ NS_IMETHODIMP nsEditor::DeleteText(nsIDOMCharacterData *aElement, PRUint32 aOffset, PRUint32 aLength) { - DeleteTextTxn *txn; - nsresult result = CreateTxnForDeleteText(aElement, aOffset, aLength, &txn); + nsCOMPtr txn; + nsresult result = CreateTxnForDeleteText(aElement, aOffset, aLength, + getter_AddRefs(txn)); if (NS_SUCCEEDED(result)) { result = Do(txn); // HACKForceRedraw(); @@ -3323,11 +3341,12 @@ NS_IMETHODIMP nsEditor::DoInitialInputMethodInsert(const nsString & aStringToIns { // now we've got the body tag. // create transaction to insert the text node, // and create a transaction to insert the text - CreateElementTxn *txn; + nsCOMPtr txn; nsAutoString textNodeTag; result = GetTextNodeTag(textNodeTag); if (NS_FAILED(result)) { return result; } - result = CreateTxnForCreateElement(textNodeTag, node, 0, &txn); + result = CreateTxnForCreateElement(textNodeTag, node, 0, + getter_AddRefs(txn)); if ((NS_SUCCEEDED(result)) && txn) { result = Do(txn); @@ -4090,8 +4109,8 @@ nsEditor::DeleteSelectionImpl(ESelectionCollapseDirection aAction) { nsresult result; - EditAggregateTxn *txn; - result = CreateTxnForDeleteSelection(aAction, &txn); + nsCOMPtr txn; + result = CreateTxnForDeleteSelection(aAction, getter_AddRefs(txn)); if (NS_SUCCEEDED(result)) { result = Do(txn); }