From e5321f0f4c4a404def8146d7dbac2dc294b160ed Mon Sep 17 00:00:00 2001 From: "bryner%netscape.com" Date: Sat, 29 Dec 2001 22:05:16 +0000 Subject: [PATCH] Bug 116499 - convert nsIOutlinerView::GetCellText to return an nsAString, so we can avoid copying strings. r=blake, sr=jag. --- .../templates/src/nsXULOutlinerBuilder.cpp | 8 ++-- .../templates/src/nsXULTemplateBuilder.cpp | 6 +-- .../xul/templates/src/nsXULTemplateBuilder.h | 2 +- .../xul/templates/src/nsXULTreeBuilder.cpp | 8 ++-- extensions/inspector/base/src/inDOMView.cpp | 40 +++++++--------- layout/xul/base/src/nsXULTooltipListener.cpp | 7 +-- .../src/outliner/public/nsIOutlinerView.idl | 2 +- .../src/outliner/src/nsOutlinerBodyFrame.cpp | 48 ++++++++----------- .../outliner/src/nsOutlinerContentView.cpp | 8 ++-- .../xul/base/src/tree/public/nsITreeView.idl | 2 +- .../xul/base/src/tree/src/nsTreeBodyFrame.cpp | 48 ++++++++----------- .../base/src/tree/src/nsTreeContentView.cpp | 8 ++-- mailnews/addrbook/src/nsAbView.cpp | 8 +++- mailnews/base/src/nsMsgDBView.cpp | 30 +++++++----- mailnews/base/src/nsMsgSearchDBView.cpp | 8 +++- mailnews/base/src/nsMsgSearchDBView.h | 2 +- mailnews/news/src/nsNntpIncomingServer.cpp | 7 ++- security/manager/pki/src/nsASN1Outliner.cpp | 9 ++-- security/manager/pki/src/nsASN1Tree.cpp | 9 ++-- security/manager/ssl/src/nsCertOutliner.cpp | 14 +++--- security/manager/ssl/src/nsCertTree.cpp | 14 +++--- xpfe/components/filepicker/src/nsFileView.cpp | 20 ++++---- 22 files changed, 150 insertions(+), 158 deletions(-) diff --git a/content/xul/templates/src/nsXULOutlinerBuilder.cpp b/content/xul/templates/src/nsXULOutlinerBuilder.cpp index dce02301449..fcc8dd6e8a1 100644 --- a/content/xul/templates/src/nsXULOutlinerBuilder.cpp +++ b/content/xul/templates/src/nsXULOutlinerBuilder.cpp @@ -611,7 +611,7 @@ nsXULOutlinerBuilder::GetLevel(PRInt32 aRowIndex, PRInt32* aResult) } NS_IMETHODIMP -nsXULOutlinerBuilder::GetCellText(PRInt32 aRow, const PRUnichar* aColID, PRUnichar** aResult) +nsXULOutlinerBuilder::GetCellText(PRInt32 aRow, const PRUnichar* aColID, nsAString& aResult) { NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad index"); if (aRow < 0 || aRow >= mRows.Count()) @@ -624,13 +624,11 @@ nsXULOutlinerBuilder::GetCellText(PRInt32 aRow, const PRUnichar* aColID, PRUnich nsAutoString raw; cell->GetAttr(kNameSpaceID_None, nsXULAtoms::label, raw); - nsAutoString cooked; - SubstituteText(*(mRows[aRow]->mMatch), raw, cooked); + SubstituteText(*(mRows[aRow]->mMatch), raw, aResult); - *aResult = nsCRT::strdup(cooked.get()); } else - *aResult = nsnull; + aResult.SetCapacity(0); return NS_OK; } diff --git a/content/xul/templates/src/nsXULTemplateBuilder.cpp b/content/xul/templates/src/nsXULTemplateBuilder.cpp index 7bcee09875f..bcdb5049f3f 100644 --- a/content/xul/templates/src/nsXULTemplateBuilder.cpp +++ b/content/xul/templates/src/nsXULTemplateBuilder.cpp @@ -1095,17 +1095,17 @@ nsXULTemplateBuilder::ParseAttribute(const nsAReadableString& aAttributeValue, struct SubstituteTextClosure { - SubstituteTextClosure(nsTemplateMatch& aMatch, nsString& aResult) + SubstituteTextClosure(nsTemplateMatch& aMatch, nsAString& aResult) : match(aMatch), result(aResult) {} nsTemplateMatch& match; - nsString& result; + nsAString& result; }; nsresult nsXULTemplateBuilder::SubstituteText(nsTemplateMatch& aMatch, const nsAReadableString& aAttributeValue, - nsString& aResult) + nsAString& aResult) { // See if it's the special value "..." if (aAttributeValue == NS_LITERAL_STRING("...")) { diff --git a/content/xul/templates/src/nsXULTemplateBuilder.h b/content/xul/templates/src/nsXULTemplateBuilder.h index 9eb54fc0f49..489d655f7ac 100644 --- a/content/xul/templates/src/nsXULTemplateBuilder.h +++ b/content/xul/templates/src/nsXULTemplateBuilder.h @@ -310,7 +310,7 @@ public: nsresult SubstituteText(nsTemplateMatch& aMatch, const nsAReadableString& aAttributeValue, - nsString& aResult); + nsAString& aResult); static void SubstituteTextAppendText(nsXULTemplateBuilder* aThis, const nsAReadableString& aText, void* aClosure); diff --git a/content/xul/templates/src/nsXULTreeBuilder.cpp b/content/xul/templates/src/nsXULTreeBuilder.cpp index dce02301449..fcc8dd6e8a1 100644 --- a/content/xul/templates/src/nsXULTreeBuilder.cpp +++ b/content/xul/templates/src/nsXULTreeBuilder.cpp @@ -611,7 +611,7 @@ nsXULOutlinerBuilder::GetLevel(PRInt32 aRowIndex, PRInt32* aResult) } NS_IMETHODIMP -nsXULOutlinerBuilder::GetCellText(PRInt32 aRow, const PRUnichar* aColID, PRUnichar** aResult) +nsXULOutlinerBuilder::GetCellText(PRInt32 aRow, const PRUnichar* aColID, nsAString& aResult) { NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad index"); if (aRow < 0 || aRow >= mRows.Count()) @@ -624,13 +624,11 @@ nsXULOutlinerBuilder::GetCellText(PRInt32 aRow, const PRUnichar* aColID, PRUnich nsAutoString raw; cell->GetAttr(kNameSpaceID_None, nsXULAtoms::label, raw); - nsAutoString cooked; - SubstituteText(*(mRows[aRow]->mMatch), raw, cooked); + SubstituteText(*(mRows[aRow]->mMatch), raw, aResult); - *aResult = nsCRT::strdup(cooked.get()); } else - *aResult = nsnull; + aResult.SetCapacity(0); return NS_OK; } diff --git a/extensions/inspector/base/src/inDOMView.cpp b/extensions/inspector/base/src/inDOMView.cpp index c40d0ab8095..20e741f2516 100644 --- a/extensions/inspector/base/src/inDOMView.cpp +++ b/extensions/inspector/base/src/inDOMView.cpp @@ -371,7 +371,7 @@ inDOMView::GetColumnProperties(const PRUnichar *colID, nsIDOMElement *colElt, ns } NS_IMETHODIMP -inDOMView::GetCellText(PRInt32 row, const PRUnichar *colID, PRUnichar **_retval) +inDOMView::GetCellText(PRInt32 row, const PRUnichar *colID, nsAString& _retval) { inDOMViewNode* node = nsnull; RowToNode(row, &node); @@ -379,36 +379,30 @@ inDOMView::GetCellText(PRInt32 row, const PRUnichar *colID, PRUnichar **_retval) nsIDOMNode* domNode = node->node; - nsAutoString value; nsAutoString col(colID); - if (col.Equals(NS_LITERAL_STRING("colNodeName"))) { - domNode->GetNodeName(value); - *_retval = ToNewUnicode(value); - } else if (col.Equals(NS_LITERAL_STRING("colLocalName"))) { - domNode->GetLocalName(value); - *_retval = ToNewUnicode(value); - } else if (col.Equals(NS_LITERAL_STRING("colPrefix"))) { - domNode->GetPrefix(value); - *_retval = ToNewUnicode(value); - } else if (col.Equals(NS_LITERAL_STRING("colNamespaceURI"))) { - domNode->GetNamespaceURI(value); - *_retval = ToNewUnicode(value); - } else if (col.Equals(NS_LITERAL_STRING("colNodeType"))) { + if (col.Equals(NS_LITERAL_STRING("colNodeName"))) + domNode->GetNodeName(_retval); + else if (col.Equals(NS_LITERAL_STRING("colLocalName"))) + domNode->GetLocalName(_retval); + else if (col.Equals(NS_LITERAL_STRING("colPrefix"))) + domNode->GetPrefix(_retval); + else if (col.Equals(NS_LITERAL_STRING("colNamespaceURI"))) + domNode->GetNamespaceURI(_retval); + else if (col.Equals(NS_LITERAL_STRING("colNodeType"))) { PRUint16 nodeType; domNode->GetNodeType(&nodeType); - value.AppendInt(PRInt32(nodeType)); - *_retval = ToNewUnicode(value); - } else if (col.Equals(NS_LITERAL_STRING("colNodeValue"))) { - domNode->GetNodeValue(value); - *_retval = ToNewUnicode(value); - } else { + nsAutoString temp; + temp.AppendInt(PRInt32(nodeType)); + _retval = temp; + } else if (col.Equals(NS_LITERAL_STRING("colNodeValue"))) + domNode->GetNodeValue(_retval); + else { if (Substring(col, 0, 4).Equals(NS_LITERAL_STRING("col@"))) { nsCOMPtr el = do_QueryInterface(node->node); if (el) { nsAutoString attr; col.Right(attr, col.Length()-4); // have to use this because Substring is crashing on me! - el->GetAttribute(attr, value); - *_retval = ToNewUnicode(value); + el->GetAttribute(attr, _retval); } } } diff --git a/layout/xul/base/src/nsXULTooltipListener.cpp b/layout/xul/base/src/nsXULTooltipListener.cpp index fbce3b4ee6b..fc22ac79656 100644 --- a/layout/xul/base/src/nsXULTooltipListener.cpp +++ b/layout/xul/base/src/nsXULTooltipListener.cpp @@ -448,12 +448,9 @@ SetTitletipLabel(nsIOutlinerBoxObject* aOutlinerBox, nsIContent* aTooltip, nsCOMPtr view; aOutlinerBox->GetView(getter_AddRefs(view)); - PRUnichar* cellText = nsnull; - view->GetCellText(aRow, aCol.get(), &cellText); - nsAutoString label; - label.Assign(cellText); - + view->GetCellText(aRow, aCol.get(), label); + aTooltip->SetAttr(nsnull, nsXULAtoms::label, label, PR_FALSE); } diff --git a/layout/xul/base/src/outliner/public/nsIOutlinerView.idl b/layout/xul/base/src/outliner/public/nsIOutlinerView.idl index 5c640227866..74d3fb843b8 100644 --- a/layout/xul/base/src/outliner/public/nsIOutlinerView.idl +++ b/layout/xul/base/src/outliner/public/nsIOutlinerView.idl @@ -139,7 +139,7 @@ interface nsIOutlinerView : nsISupports * The text for a given cell. If a column consists only of an image, then * the empty string is returned. */ - wstring getCellText(in long row, in wstring colID); + AString getCellText(in long row, in wstring colID); /** * Called during initialization to link the view to the front end box object. diff --git a/layout/xul/base/src/outliner/src/nsOutlinerBodyFrame.cpp b/layout/xul/base/src/outliner/src/nsOutlinerBodyFrame.cpp index 1d33fa7d809..7ee3f2e928e 100644 --- a/layout/xul/base/src/outliner/src/nsOutlinerBodyFrame.cpp +++ b/layout/xul/base/src/outliner/src/nsOutlinerBodyFrame.cpp @@ -994,9 +994,8 @@ nsOutlinerBodyFrame::GetCoordsForCellItem(PRInt32 aRow, const PRUnichar *aColID, cellX += imageSize.width; // Cell Text - nsXPIDLString text; - mView->GetCellText(aRow, currCol->GetID(), getter_Copies(text)); - nsAutoString cellText(text); + nsAutoString cellText; + mView->GetCellText(aRow, currCol->GetID(), cellText); // Create a scratch rect to represent the text rectangle, with the current // X and Y coords, and a guess at the width and height. The width is the @@ -1229,9 +1228,8 @@ nsOutlinerBodyFrame::IsCellCropped(PRInt32 aRow, const nsAString& aColID, PRBool remainWidth -= imageSize.width; // Get the cell text. - nsXPIDLString text; - mView->GetCellText(aRow, currCol->GetID(), getter_Copies(text)); - nsAutoString cellText(text); + nsAutoString cellText; + mView->GetCellText(aRow, currCol->GetID(), cellText); nsCOMPtr textContext; GetPseudoStyleContext(nsXULAtoms::mozoutlinercelltext, getter_AddRefs(textContext)); @@ -2147,12 +2145,10 @@ NS_IMETHODIMP nsOutlinerBodyFrame::PaintText(int aRowIndex, nsFramePaintLayer aWhichLayer) { // Now obtain the text for our cell. - nsXPIDLString text; - mView->GetCellText(aRowIndex, aColumn->GetID(), getter_Copies(text)); + nsAutoString text; + mView->GetCellText(aRowIndex, aColumn->GetID(), text); - nsAutoString realText(text); - - if (realText.Length() == 0) + if (text.Length() == 0) return NS_OK; // Don't paint an empty string. XXX What about background/borders? Still paint? // Resolve style for the text. It contains all the info we need to lay ourselves @@ -2199,21 +2195,19 @@ NS_IMETHODIMP nsOutlinerBodyFrame::PaintText(int aRowIndex, aRenderingContext.SetFont(fontMet); nscoord width; - aRenderingContext.GetWidth(realText, width); - + aRenderingContext.GetWidth(text, width); + if (width > textRect.width) { // See if the width is even smaller than the ellipsis // If so, clear the text completely. nscoord ellipsisWidth; aRenderingContext.GetWidth(ELLIPSIS, ellipsisWidth); - nsAutoString ellipsis; ellipsis.AssignWithConversion(ELLIPSIS); - nscoord width = textRect.width; if (ellipsisWidth > width) - realText.SetLength(0); + text.SetLength(0); else if (ellipsisWidth == width) - realText = ellipsis; + text.Assign(NS_LITERAL_STRING(ELLIPSIS)); else { // We will be drawing an ellipsis, thank you very much. // Subtract out the required width of the ellipsis. @@ -2227,18 +2221,18 @@ NS_IMETHODIMP nsOutlinerBodyFrame::PaintText(int aRowIndex, // Crop right. nscoord cwidth; nscoord twidth = 0; - int length = realText.Length(); + int length = text.Length(); int i; for (i = 0; i < length; ++i) { - PRUnichar ch = realText.CharAt(i); + PRUnichar ch = text[i]; aRenderingContext.GetWidth(ch,cwidth); if (twidth + cwidth > width) break; twidth += cwidth; } - realText.Truncate(i); - realText += ellipsis; + text.Truncate(i); + text += NS_LITERAL_STRING(ELLIPSIS); } break; @@ -2246,10 +2240,10 @@ NS_IMETHODIMP nsOutlinerBodyFrame::PaintText(int aRowIndex, // Crop left. nscoord cwidth; nscoord twidth = 0; - int length = realText.Length(); + int length = text.Length(); int i; for (i=length-1; i >= 0; --i) { - PRUnichar ch = realText.CharAt(i); + PRUnichar ch = text[i]; aRenderingContext.GetWidth(ch,cwidth); if (twidth + cwidth > width) break; @@ -2258,9 +2252,9 @@ NS_IMETHODIMP nsOutlinerBodyFrame::PaintText(int aRowIndex, } nsAutoString copy; - realText.Right(copy, length-1-i); - realText = ellipsis; - realText += copy; + text.Right(copy, length-1-i); + text.Assign(NS_LITERAL_STRING(ELLIPSIS)); + text += copy; } break; @@ -2277,7 +2271,7 @@ NS_IMETHODIMP nsOutlinerBodyFrame::PaintText(int aRowIndex, const nsStyleColor* colorStyle = (const nsStyleColor*)textContext->GetStyleData(eStyleStruct_Color); aRenderingContext.SetColor(colorStyle->mColor); - aRenderingContext.DrawString(realText, textRect.x, textRect.y + baseline); + aRenderingContext.DrawString(text, textRect.x, textRect.y + baseline); } return NS_OK; diff --git a/layout/xul/base/src/outliner/src/nsOutlinerContentView.cpp b/layout/xul/base/src/outliner/src/nsOutlinerContentView.cpp index 6f1f89d9137..c904ba4b431 100644 --- a/layout/xul/base/src/outliner/src/nsOutlinerContentView.cpp +++ b/layout/xul/base/src/outliner/src/nsOutlinerContentView.cpp @@ -407,13 +407,13 @@ nsOutlinerContentView::GetLevel(PRInt32 aIndex, PRInt32* _retval) } NS_IMETHODIMP -nsOutlinerContentView::GetCellText(PRInt32 aRow, const PRUnichar* aColID, PRUnichar** _retval) +nsOutlinerContentView::GetCellText(PRInt32 aRow, const PRUnichar* aColID, nsAString& _retval) { NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad row"); if (aRow < 0 || aRow >= mRows.Count()) return NS_ERROR_INVALID_ARG; - *_retval = nsnull; + _retval.SetCapacity(0); Row* row = (Row*)mRows[aRow]; nsCOMPtr realRow; @@ -422,9 +422,7 @@ nsOutlinerContentView::GetCellText(PRInt32 aRow, const PRUnichar* aColID, PRUnic nsCOMPtr cell; GetNamedCell(realRow, aColID, getter_AddRefs(cell)); if (cell) { - nsAutoString label; - cell->GetAttr(kNameSpaceID_None, nsHTMLAtoms::label, label); - *_retval = ToNewUnicode(label); + cell->GetAttr(kNameSpaceID_None, nsHTMLAtoms::label, _retval); } } diff --git a/layout/xul/base/src/tree/public/nsITreeView.idl b/layout/xul/base/src/tree/public/nsITreeView.idl index 5c640227866..74d3fb843b8 100644 --- a/layout/xul/base/src/tree/public/nsITreeView.idl +++ b/layout/xul/base/src/tree/public/nsITreeView.idl @@ -139,7 +139,7 @@ interface nsIOutlinerView : nsISupports * The text for a given cell. If a column consists only of an image, then * the empty string is returned. */ - wstring getCellText(in long row, in wstring colID); + AString getCellText(in long row, in wstring colID); /** * Called during initialization to link the view to the front end box object. diff --git a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp index 1d33fa7d809..7ee3f2e928e 100644 --- a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp +++ b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp @@ -994,9 +994,8 @@ nsOutlinerBodyFrame::GetCoordsForCellItem(PRInt32 aRow, const PRUnichar *aColID, cellX += imageSize.width; // Cell Text - nsXPIDLString text; - mView->GetCellText(aRow, currCol->GetID(), getter_Copies(text)); - nsAutoString cellText(text); + nsAutoString cellText; + mView->GetCellText(aRow, currCol->GetID(), cellText); // Create a scratch rect to represent the text rectangle, with the current // X and Y coords, and a guess at the width and height. The width is the @@ -1229,9 +1228,8 @@ nsOutlinerBodyFrame::IsCellCropped(PRInt32 aRow, const nsAString& aColID, PRBool remainWidth -= imageSize.width; // Get the cell text. - nsXPIDLString text; - mView->GetCellText(aRow, currCol->GetID(), getter_Copies(text)); - nsAutoString cellText(text); + nsAutoString cellText; + mView->GetCellText(aRow, currCol->GetID(), cellText); nsCOMPtr textContext; GetPseudoStyleContext(nsXULAtoms::mozoutlinercelltext, getter_AddRefs(textContext)); @@ -2147,12 +2145,10 @@ NS_IMETHODIMP nsOutlinerBodyFrame::PaintText(int aRowIndex, nsFramePaintLayer aWhichLayer) { // Now obtain the text for our cell. - nsXPIDLString text; - mView->GetCellText(aRowIndex, aColumn->GetID(), getter_Copies(text)); + nsAutoString text; + mView->GetCellText(aRowIndex, aColumn->GetID(), text); - nsAutoString realText(text); - - if (realText.Length() == 0) + if (text.Length() == 0) return NS_OK; // Don't paint an empty string. XXX What about background/borders? Still paint? // Resolve style for the text. It contains all the info we need to lay ourselves @@ -2199,21 +2195,19 @@ NS_IMETHODIMP nsOutlinerBodyFrame::PaintText(int aRowIndex, aRenderingContext.SetFont(fontMet); nscoord width; - aRenderingContext.GetWidth(realText, width); - + aRenderingContext.GetWidth(text, width); + if (width > textRect.width) { // See if the width is even smaller than the ellipsis // If so, clear the text completely. nscoord ellipsisWidth; aRenderingContext.GetWidth(ELLIPSIS, ellipsisWidth); - nsAutoString ellipsis; ellipsis.AssignWithConversion(ELLIPSIS); - nscoord width = textRect.width; if (ellipsisWidth > width) - realText.SetLength(0); + text.SetLength(0); else if (ellipsisWidth == width) - realText = ellipsis; + text.Assign(NS_LITERAL_STRING(ELLIPSIS)); else { // We will be drawing an ellipsis, thank you very much. // Subtract out the required width of the ellipsis. @@ -2227,18 +2221,18 @@ NS_IMETHODIMP nsOutlinerBodyFrame::PaintText(int aRowIndex, // Crop right. nscoord cwidth; nscoord twidth = 0; - int length = realText.Length(); + int length = text.Length(); int i; for (i = 0; i < length; ++i) { - PRUnichar ch = realText.CharAt(i); + PRUnichar ch = text[i]; aRenderingContext.GetWidth(ch,cwidth); if (twidth + cwidth > width) break; twidth += cwidth; } - realText.Truncate(i); - realText += ellipsis; + text.Truncate(i); + text += NS_LITERAL_STRING(ELLIPSIS); } break; @@ -2246,10 +2240,10 @@ NS_IMETHODIMP nsOutlinerBodyFrame::PaintText(int aRowIndex, // Crop left. nscoord cwidth; nscoord twidth = 0; - int length = realText.Length(); + int length = text.Length(); int i; for (i=length-1; i >= 0; --i) { - PRUnichar ch = realText.CharAt(i); + PRUnichar ch = text[i]; aRenderingContext.GetWidth(ch,cwidth); if (twidth + cwidth > width) break; @@ -2258,9 +2252,9 @@ NS_IMETHODIMP nsOutlinerBodyFrame::PaintText(int aRowIndex, } nsAutoString copy; - realText.Right(copy, length-1-i); - realText = ellipsis; - realText += copy; + text.Right(copy, length-1-i); + text.Assign(NS_LITERAL_STRING(ELLIPSIS)); + text += copy; } break; @@ -2277,7 +2271,7 @@ NS_IMETHODIMP nsOutlinerBodyFrame::PaintText(int aRowIndex, const nsStyleColor* colorStyle = (const nsStyleColor*)textContext->GetStyleData(eStyleStruct_Color); aRenderingContext.SetColor(colorStyle->mColor); - aRenderingContext.DrawString(realText, textRect.x, textRect.y + baseline); + aRenderingContext.DrawString(text, textRect.x, textRect.y + baseline); } return NS_OK; diff --git a/layout/xul/base/src/tree/src/nsTreeContentView.cpp b/layout/xul/base/src/tree/src/nsTreeContentView.cpp index 6f1f89d9137..c904ba4b431 100644 --- a/layout/xul/base/src/tree/src/nsTreeContentView.cpp +++ b/layout/xul/base/src/tree/src/nsTreeContentView.cpp @@ -407,13 +407,13 @@ nsOutlinerContentView::GetLevel(PRInt32 aIndex, PRInt32* _retval) } NS_IMETHODIMP -nsOutlinerContentView::GetCellText(PRInt32 aRow, const PRUnichar* aColID, PRUnichar** _retval) +nsOutlinerContentView::GetCellText(PRInt32 aRow, const PRUnichar* aColID, nsAString& _retval) { NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad row"); if (aRow < 0 || aRow >= mRows.Count()) return NS_ERROR_INVALID_ARG; - *_retval = nsnull; + _retval.SetCapacity(0); Row* row = (Row*)mRows[aRow]; nsCOMPtr realRow; @@ -422,9 +422,7 @@ nsOutlinerContentView::GetCellText(PRInt32 aRow, const PRUnichar* aColID, PRUnic nsCOMPtr cell; GetNamedCell(realRow, aColID, getter_AddRefs(cell)); if (cell) { - nsAutoString label; - cell->GetAttr(kNameSpaceID_None, nsHTMLAtoms::label, label); - *_retval = ToNewUnicode(label); + cell->GetAttr(kNameSpaceID_None, nsHTMLAtoms::label, _retval); } } diff --git a/mailnews/addrbook/src/nsAbView.cpp b/mailnews/addrbook/src/nsAbView.cpp index 67f09012c59..e2737a36b4e 100644 --- a/mailnews/addrbook/src/nsAbView.cpp +++ b/mailnews/addrbook/src/nsAbView.cpp @@ -451,14 +451,18 @@ nsresult nsAbView::GetCardValue(nsIAbCard *card, const PRUnichar *colID, PRUnich return rv; } -NS_IMETHODIMP nsAbView::GetCellText(PRInt32 row, const PRUnichar *colID, PRUnichar **_retval) +NS_IMETHODIMP nsAbView::GetCellText(PRInt32 row, const PRUnichar *colID, nsAString& _retval) { // XXX todo remove once #116341 is fixed if (!colID[0]) return NS_OK; nsIAbCard *card = ((AbCard *)(mCards.ElementAt(row)))->card; - return GetCardValue(card, colID, _retval); + // XXX fix me by converting GetCardValue to take an nsAString& + nsXPIDLString cellText; + nsresult rv = GetCardValue(card, colID, getter_Copies(cellText)); + _retval.Assign(cellText); + return rv; } NS_IMETHODIMP nsAbView::SetOutliner(nsIOutlinerBoxObject *outliner) diff --git a/mailnews/base/src/nsMsgDBView.cpp b/mailnews/base/src/nsMsgDBView.cpp index 9bc5611e39d..997d8e1318c 100644 --- a/mailnews/base/src/nsMsgDBView.cpp +++ b/mailnews/base/src/nsMsgDBView.cpp @@ -1260,7 +1260,7 @@ nsresult nsMsgDBView::GetDBForViewIndex(nsMsgViewIndex index, nsIMsgDatabase **d return NS_OK; } -NS_IMETHODIMP nsMsgDBView::GetCellText(PRInt32 aRow, const PRUnichar * aColID, PRUnichar ** aValue) +NS_IMETHODIMP nsMsgDBView::GetCellText(PRInt32 aRow, const PRUnichar * aColID, nsAString& aValue) { // remove once #116341 is fixed if (!aColID[0]) @@ -1279,31 +1279,35 @@ NS_IMETHODIMP nsMsgDBView::GetCellText(PRInt32 aRow, const PRUnichar * aColID, P return NS_MSG_INVALID_DBVIEW_INDEX; } - *aValue = 0; - // just a hack - nsXPIDLCString dbString; + aValue.SetCapacity(0); + // XXX fix me by making Fetch* take an nsAString& parameter + nsXPIDLString valueText; nsCOMPtr thread; switch (aColID[0]) { case 's': if (aColID[1] == 'u') // subject - rv = FetchSubject(msgHdr, m_flags[aRow], aValue); + rv = FetchSubject(msgHdr, m_flags[aRow], getter_Copies(valueText)); else if (aColID[1] == 'e') // sender - rv = FetchAuthor(msgHdr, aValue); + rv = FetchAuthor(msgHdr, getter_Copies(valueText)); else if (aColID[1] == 'i') // size - rv = FetchSize(msgHdr, aValue); + rv = FetchSize(msgHdr, getter_Copies(valueText)); else - rv = FetchStatus(m_flags[aRow], aValue); + rv = FetchStatus(m_flags[aRow], getter_Copies(valueText)); + aValue.Assign(valueText); break; case 'd': // date - rv = FetchDate(msgHdr, aValue); + rv = FetchDate(msgHdr, getter_Copies(valueText)); + aValue.Assign(valueText); break; case 'p': // priority - rv = FetchPriority(msgHdr, aValue); + rv = FetchPriority(msgHdr, getter_Copies(valueText)); + aValue.Assign(valueText); break; case 'l': // label - rv = FetchLabel(msgHdr, aValue); + rv = FetchLabel(msgHdr, getter_Copies(valueText)); + aValue.Assign(valueText); break; case 't': // total msgs in thread column @@ -1318,7 +1322,7 @@ NS_IMETHODIMP nsMsgDBView::GetCellText(PRInt32 aRow, const PRUnichar * aColID, P PRUint32 numChildren; thread->GetNumChildren(&numChildren); formattedCountString.AppendInt(numChildren); - *aValue = ToNewUnicode(formattedCountString); + aValue.Assign(formattedCountString); } } } @@ -1338,7 +1342,7 @@ NS_IMETHODIMP nsMsgDBView::GetCellText(PRInt32 aRow, const PRUnichar * aColID, P if (numUnreadChildren > 0) { formattedCountString.AppendInt(numUnreadChildren); - *aValue = ToNewUnicode(formattedCountString); + aValue.Assign(formattedCountString); } } } diff --git a/mailnews/base/src/nsMsgSearchDBView.cpp b/mailnews/base/src/nsMsgSearchDBView.cpp index 75a0c35797f..1c3141f2b27 100644 --- a/mailnews/base/src/nsMsgSearchDBView.cpp +++ b/mailnews/base/src/nsMsgSearchDBView.cpp @@ -98,11 +98,15 @@ NS_IMETHODIMP nsMsgSearchDBView::Close() return NS_OK; } -NS_IMETHODIMP nsMsgSearchDBView::GetCellText(PRInt32 aRow, const PRUnichar * aColID, PRUnichar ** aValue) +NS_IMETHODIMP nsMsgSearchDBView::GetCellText(PRInt32 aRow, const PRUnichar * aColID, nsAString& aValue) { if (aColID[0] == 'l' && aColID[1] == 'o') // location, need to check for "lo" not just "l" to avoid "label" column { - return FetchLocation(aRow, aValue); + // XXX fix me by converting Fetch* to take an nsAString& parameter + nsXPIDLString valueText; + nsresult rv = FetchLocation(aRow, getter_Copies(valueText)); + aValue.Assign(valueText); + return rv; } else return nsMsgDBView::GetCellText(aRow, aColID, aValue); diff --git a/mailnews/base/src/nsMsgSearchDBView.h b/mailnews/base/src/nsMsgSearchDBView.h index 468e0abe9fa..2b5f4e3f421 100644 --- a/mailnews/base/src/nsMsgSearchDBView.h +++ b/mailnews/base/src/nsMsgSearchDBView.h @@ -60,7 +60,7 @@ public: NS_IMETHOD DoCommandWithFolder(nsMsgViewCommandTypeValue command, nsIMsgFolder *destFolder); NS_IMETHOD GetHdrForFirstSelectedMessage(nsIMsgDBHdr **hdr); // override to get location - NS_IMETHOD GetCellText(PRInt32 aRow, const PRUnichar * aColID, PRUnichar ** aValue); + NS_IMETHOD GetCellText(PRInt32 aRow, const PRUnichar * aColID, nsAString& aValue); virtual nsresult GetMsgHdrForViewIndex(nsMsgViewIndex index, nsIMsgDBHdr **msgHdr); virtual nsresult OnNewHeader(nsMsgKey newKey, nsMsgKey parentKey, PRBool ensureListed); NS_IMETHOD GetFolderForViewIndex(nsMsgViewIndex index, nsIMsgFolder **folder); diff --git a/mailnews/news/src/nsNntpIncomingServer.cpp b/mailnews/news/src/nsNntpIncomingServer.cpp index 62b94cb9b6e..7eb7894b7e1 100644 --- a/mailnews/news/src/nsNntpIncomingServer.cpp +++ b/mailnews/news/src/nsNntpIncomingServer.cpp @@ -1869,14 +1869,17 @@ nsNntpIncomingServer::GetLevel(PRInt32 index, PRInt32 *_retval) } NS_IMETHODIMP -nsNntpIncomingServer::GetCellText(PRInt32 row, const PRUnichar *colID, PRUnichar **_retval) +nsNntpIncomingServer::GetCellText(PRInt32 row, const PRUnichar *colID, nsAString& _retval) { if (colID[0] == 'n') { nsCString str; mSubscribeSearchResult.CStringAt(row, str); // some servers have newsgroup names that are non ASCII. we store those as escaped // unescape here so the UI is consistent - nsresult rv = NS_MsgDecodeUnescapeURLPath(str.get(), _retval); + // XXX fix me by converting NS_MsgDecodeUnescapeURLPath to take an nsAString& + nsXPIDLString cellText; + nsresult rv = NS_MsgDecodeUnescapeURLPath(str.get(), getter_Copies(cellText)); + _retval.Assign(cellText); NS_ENSURE_SUCCESS(rv,rv); } return NS_OK; diff --git a/security/manager/pki/src/nsASN1Outliner.cpp b/security/manager/pki/src/nsASN1Outliner.cpp index 52a21965fe0..1e325045143 100644 --- a/security/manager/pki/src/nsASN1Outliner.cpp +++ b/security/manager/pki/src/nsASN1Outliner.cpp @@ -399,10 +399,10 @@ nsNSSASN1Outliner::GetLevel(PRInt32 index, PRInt32 *_retval) /* wstring getCellText (in long row, in wstring colID); */ NS_IMETHODIMP nsNSSASN1Outliner::GetCellText(PRInt32 row, const PRUnichar *colID, - PRUnichar **_retval) + nsAString& _retval) { nsCOMPtr object; - *_retval = nsnull; + _retval.SetCapacity(0); char *col = NS_CONST_CAST(char *, NS_ConvertUCS2toUTF8(colID).get()); nsresult rv = NS_OK; if (strcmp(col, "certDataCol") == 0) { @@ -412,7 +412,10 @@ nsNSSASN1Outliner::GetCellText(PRInt32 row, const PRUnichar *colID, return rv; //There's only one column for ASN1 dump. - rv = object->GetDisplayName(_retval); + PRUnichar* displayName = nsnull; + rv = object->GetDisplayName(&displayName); // copies + _retval = displayName; // copies again! + nsCRT::free(displayName); } return rv; } diff --git a/security/manager/pki/src/nsASN1Tree.cpp b/security/manager/pki/src/nsASN1Tree.cpp index 52a21965fe0..1e325045143 100644 --- a/security/manager/pki/src/nsASN1Tree.cpp +++ b/security/manager/pki/src/nsASN1Tree.cpp @@ -399,10 +399,10 @@ nsNSSASN1Outliner::GetLevel(PRInt32 index, PRInt32 *_retval) /* wstring getCellText (in long row, in wstring colID); */ NS_IMETHODIMP nsNSSASN1Outliner::GetCellText(PRInt32 row, const PRUnichar *colID, - PRUnichar **_retval) + nsAString& _retval) { nsCOMPtr object; - *_retval = nsnull; + _retval.SetCapacity(0); char *col = NS_CONST_CAST(char *, NS_ConvertUCS2toUTF8(colID).get()); nsresult rv = NS_OK; if (strcmp(col, "certDataCol") == 0) { @@ -412,7 +412,10 @@ nsNSSASN1Outliner::GetCellText(PRInt32 row, const PRUnichar *colID, return rv; //There's only one column for ASN1 dump. - rv = object->GetDisplayName(_retval); + PRUnichar* displayName = nsnull; + rv = object->GetDisplayName(&displayName); // copies + _retval = displayName; // copies again! + nsCRT::free(displayName); } return rv; } diff --git a/security/manager/ssl/src/nsCertOutliner.cpp b/security/manager/ssl/src/nsCertOutliner.cpp index 6b16409415e..d8ef97b1c7a 100644 --- a/security/manager/ssl/src/nsCertOutliner.cpp +++ b/security/manager/ssl/src/nsCertOutliner.cpp @@ -467,18 +467,16 @@ nsCertOutliner::GetLevel(PRInt32 index, PRInt32 *_retval) /* wstring getCellText (in long row, in wstring colID); */ NS_IMETHODIMP nsCertOutliner::GetCellText(PRInt32 row, const PRUnichar *colID, - PRUnichar **_retval) + nsAString& _retval) { nsresult rv; char *col = NS_CONST_CAST(char *, NS_ConvertUCS2toUTF8(colID).get()); outlinerArrayEl *el = GetThreadDescAtIndex(row); if (el != nsnull) { - if (strcmp(col, "certcol") == 0) { - nsAutoString oName(el->orgName); - *_retval = ToNewUnicode(oName); - } else { - *_retval = nsnull; - } + if (strcmp(col, "certcol") == 0) + _retval.Assign(el->orgName); + else + _retval.SetCapacity(0); return NS_OK; } nsCOMPtr cert = GetCertAtIndex(row); @@ -565,7 +563,7 @@ nsCertOutliner::GetCellText(PRInt32 row, const PRUnichar *colID, nsAutoString astr = NS_ConvertASCIItoUCS2(str); wstr = ToNewUnicode(astr); } - *_retval = wstr; + _retval = wstr; return rv; } diff --git a/security/manager/ssl/src/nsCertTree.cpp b/security/manager/ssl/src/nsCertTree.cpp index 6b16409415e..d8ef97b1c7a 100644 --- a/security/manager/ssl/src/nsCertTree.cpp +++ b/security/manager/ssl/src/nsCertTree.cpp @@ -467,18 +467,16 @@ nsCertOutliner::GetLevel(PRInt32 index, PRInt32 *_retval) /* wstring getCellText (in long row, in wstring colID); */ NS_IMETHODIMP nsCertOutliner::GetCellText(PRInt32 row, const PRUnichar *colID, - PRUnichar **_retval) + nsAString& _retval) { nsresult rv; char *col = NS_CONST_CAST(char *, NS_ConvertUCS2toUTF8(colID).get()); outlinerArrayEl *el = GetThreadDescAtIndex(row); if (el != nsnull) { - if (strcmp(col, "certcol") == 0) { - nsAutoString oName(el->orgName); - *_retval = ToNewUnicode(oName); - } else { - *_retval = nsnull; - } + if (strcmp(col, "certcol") == 0) + _retval.Assign(el->orgName); + else + _retval.SetCapacity(0); return NS_OK; } nsCOMPtr cert = GetCertAtIndex(row); @@ -565,7 +563,7 @@ nsCertOutliner::GetCellText(PRInt32 row, const PRUnichar *colID, nsAutoString astr = NS_ConvertASCIItoUCS2(str); wstr = ToNewUnicode(astr); } - *_retval = wstr; + _retval = wstr; return rv; } diff --git a/xpfe/components/filepicker/src/nsFileView.cpp b/xpfe/components/filepicker/src/nsFileView.cpp index f68358b22fe..3cc1d8fbbe2 100644 --- a/xpfe/components/filepicker/src/nsFileView.cpp +++ b/xpfe/components/filepicker/src/nsFileView.cpp @@ -497,7 +497,7 @@ nsFileView::GetLevel(PRInt32 aIndex, PRInt32* aLevel) NS_IMETHODIMP nsFileView::GetCellText(PRInt32 aRow, const PRUnichar* aColID, - PRUnichar** aCellText) + nsAString& aCellText) { PRUint32 dirCount, fileCount; mDirList->Count(&dirCount); @@ -514,27 +514,31 @@ nsFileView::GetCellText(PRInt32 aRow, const PRUnichar* aColID, curFile = do_QueryElementAt(mFilteredFiles, aRow - dirCount); } else { // invalid row - *aCellText = ToNewUnicode(NS_LITERAL_STRING("")); + aCellText.SetCapacity(0); return NS_OK; } if (NS_LITERAL_STRING("FilenameColumn").Equals(aColID)) { - curFile->GetUnicodeLeafName(aCellText); + // XXX fix this by making GetUnicodeLeafName take an nsAString& + nsXPIDLString temp; + curFile->GetUnicodeLeafName(getter_Copies(temp)); + aCellText = temp; } else if (NS_LITERAL_STRING("LastModifiedColumn").Equals(aColID)) { PRInt64 lastModTime; curFile->GetLastModifiedTime(&lastModTime); - nsAutoString dateString; + // XXX FormatPRTime could take an nsAString& + nsAutoString temp; mDateFormatter->FormatPRTime(nsnull, kDateFormatShort, kTimeFormatSeconds, - lastModTime * 1000, dateString); - *aCellText = ToNewUnicode(dateString); + lastModTime * 1000, temp); + aCellText = temp; } else { // file size if (isDirectory) - *aCellText = ToNewUnicode(NS_LITERAL_STRING("")); + aCellText.SetCapacity(0); else { PRInt64 fileSize; curFile->GetFileSize(&fileSize); - *aCellText = ToNewUnicode(nsPrintfCString("%lld", fileSize)); + aCellText = NS_ConvertUTF8toUCS2(nsPrintfCString("%lld", fileSize)); } }