diff --git a/mozilla/content/html/style/src/nsCSSDeclaration.cpp b/mozilla/content/html/style/src/nsCSSDeclaration.cpp index bb4fd9036cf..d3be31f70ef 100644 --- a/mozilla/content/html/style/src/nsCSSDeclaration.cpp +++ b/mozilla/content/html/style/src/nsCSSDeclaration.cpp @@ -1148,7 +1148,7 @@ CSSDeclarationImpl::CSSDeclarationImpl(const CSSDeclarationImpl& aCopy) } if (aCopy.mOrder) { - mOrder = new nsVoidArray(); + mOrder = new nsAutoVoidArray(); if (mOrder) { (*mOrder) = *(aCopy.mOrder); } @@ -1853,13 +1853,16 @@ CSSDeclarationImpl::AppendValue(nsCSSProperty aProperty, const nsCSSValue& aValu if (NS_OK == result) { if (nsnull == mOrder) { - mOrder = new nsVoidArray(); + mOrder = new nsAutoVoidArray(); } - if (nsnull != mOrder) { + else { + // order IS important for CSS, so remove and add to the end PRInt32 index = mOrder->IndexOf((void*)aProperty); if (-1 != index) { mOrder->RemoveElementAt(index); } + } + if (nsnull != mOrder) { if (eCSSUnit_Null != aValue.GetUnit()) { mOrder->AppendElement((void*)(PRInt32)aProperty); } @@ -1934,13 +1937,16 @@ CSSDeclarationImpl::AppendStructValue(nsCSSProperty aProperty, void* aStruct) if (NS_OK == result) { if (nsnull == mOrder) { - mOrder = new nsVoidArray(); + mOrder = new nsAutoVoidArray(); } - if (nsnull != mOrder) { + else { + // order IS important for CSS, so remove and add to the end PRInt32 index = mOrder->IndexOf((void*)(PRInt32)aProperty); if (-1 != index) { mOrder->RemoveElementAt(index); } + } + if (nsnull != mOrder) { mOrder->AppendElement((void*)(PRInt32)aProperty); } } @@ -3439,7 +3445,7 @@ CSSDeclarationImpl::AppendComment(const nsAReadableString& aComment) nsresult result = NS_ERROR_OUT_OF_MEMORY; if (nsnull == mOrder) { - mOrder = new nsVoidArray(); + mOrder = new nsAutoVoidArray(); } if (nsnull == mComments) { mComments = new nsStringArray(); diff --git a/mozilla/content/html/style/src/nsCSSStruct.cpp b/mozilla/content/html/style/src/nsCSSStruct.cpp index bb4fd9036cf..d3be31f70ef 100644 --- a/mozilla/content/html/style/src/nsCSSStruct.cpp +++ b/mozilla/content/html/style/src/nsCSSStruct.cpp @@ -1148,7 +1148,7 @@ CSSDeclarationImpl::CSSDeclarationImpl(const CSSDeclarationImpl& aCopy) } if (aCopy.mOrder) { - mOrder = new nsVoidArray(); + mOrder = new nsAutoVoidArray(); if (mOrder) { (*mOrder) = *(aCopy.mOrder); } @@ -1853,13 +1853,16 @@ CSSDeclarationImpl::AppendValue(nsCSSProperty aProperty, const nsCSSValue& aValu if (NS_OK == result) { if (nsnull == mOrder) { - mOrder = new nsVoidArray(); + mOrder = new nsAutoVoidArray(); } - if (nsnull != mOrder) { + else { + // order IS important for CSS, so remove and add to the end PRInt32 index = mOrder->IndexOf((void*)aProperty); if (-1 != index) { mOrder->RemoveElementAt(index); } + } + if (nsnull != mOrder) { if (eCSSUnit_Null != aValue.GetUnit()) { mOrder->AppendElement((void*)(PRInt32)aProperty); } @@ -1934,13 +1937,16 @@ CSSDeclarationImpl::AppendStructValue(nsCSSProperty aProperty, void* aStruct) if (NS_OK == result) { if (nsnull == mOrder) { - mOrder = new nsVoidArray(); + mOrder = new nsAutoVoidArray(); } - if (nsnull != mOrder) { + else { + // order IS important for CSS, so remove and add to the end PRInt32 index = mOrder->IndexOf((void*)(PRInt32)aProperty); if (-1 != index) { mOrder->RemoveElementAt(index); } + } + if (nsnull != mOrder) { mOrder->AppendElement((void*)(PRInt32)aProperty); } } @@ -3439,7 +3445,7 @@ CSSDeclarationImpl::AppendComment(const nsAReadableString& aComment) nsresult result = NS_ERROR_OUT_OF_MEMORY; if (nsnull == mOrder) { - mOrder = new nsVoidArray(); + mOrder = new nsAutoVoidArray(); } if (nsnull == mComments) { mComments = new nsStringArray(); diff --git a/mozilla/gfx/src/gtk/nsFontMetricsGTK.cpp b/mozilla/gfx/src/gtk/nsFontMetricsGTK.cpp index 1c9a38dd554..6d9e2ccb911 100644 --- a/mozilla/gfx/src/gtk/nsFontMetricsGTK.cpp +++ b/mozilla/gfx/src/gtk/nsFontMetricsGTK.cpp @@ -97,9 +97,11 @@ struct nsFontStyle; struct nsFontWeight; struct nsFontLangGroup; -class nsFontNodeArray : public nsVoidArray +class nsFontNodeArray : public nsAutoVoidArray { public: + nsFontNodeArray() {}; + nsFontNode* GetElement(PRInt32 aIndex) { return (nsFontNode*) ElementAt(aIndex); @@ -934,6 +936,11 @@ InitGlobals(void) } nsFontMetricsGTK::nsFontMetricsGTK() + : mFonts() // I'm not sure what the common size is here - I generally + // see 2-5 entries. For now, punt and let it be allocated later. We can't + // make it an nsAutoVoidArray since it's a cString array. + // XXX mFontIsGeneric will generally need to be the same size; right now + // it's an nsAutoVoidArray. If the average is under 8, that's ok. { NS_INIT_REFCNT(); gFontMetricsGTKCount++; @@ -1084,19 +1091,19 @@ NS_IMETHODIMP nsFontMetricsGTK::Init(const nsFont& aFont, nsIAtom* aLangGroup, getter_AddRefs(charset)); if (NS_SUCCEEDED(res)) { res = gCharSetManager->GetUnicodeEncoder(charset, - &gUserDefinedConverter); + &gUserDefinedConverter); if (NS_SUCCEEDED(res)) { res = gUserDefinedConverter->SetOutputErrorBehavior( - gUserDefinedConverter->kOnError_Replace, nsnull, '?'); + gUserDefinedConverter->kOnError_Replace, nsnull, '?'); nsCOMPtr mapper = - do_QueryInterface(gUserDefinedConverter); + do_QueryInterface(gUserDefinedConverter); if (mapper) { res = mapper->FillInfo(gUserDefinedMap); - } - } - else { + } + } + else { return res; - } + } } else { return res; @@ -1570,13 +1577,13 @@ DoubleByteConvert(nsFontCharSetInfo* aSelf, XFontStruct* aFont, if (count > 0) { if ((aDestBuf[0] & 0x80) && (!(aFont->max_byte1 & 0x80))) { for (PRInt32 i = 0; i < aDestLen; i++) { - aDestBuf[i] &= 0x7F; - } + aDestBuf[i] &= 0x7F; + } } else if ((!(aDestBuf[0] & 0x80)) && (aFont->min_byte1 & 0x80)) { for (PRInt32 i = 0; i < aDestLen; i++) { - aDestBuf[i] |= 0x80; - } + aDestBuf[i] |= 0x80; + } } } } @@ -2516,7 +2523,7 @@ nsFontMetricsGTK::PickASizeAndLoad(nsFontStretch* aStretch, } font->mSize = scale_size; font->mCharSetInfo = aCharSet; - aStretch->mScaledFonts.AppendElement(font); + aStretch->mScaledFonts.AppendElement(font); } else { return nsnull; @@ -3123,12 +3130,7 @@ GetFontNames(const char* aPattern, nsFontNodeArray* aNodes) found = 1; } else { - PRInt32 n = aNodes->Count(); - for (PRInt32 j = 0; j < n; j++) { - if (aNodes->GetElement(j) == node) { - found = 1; - } - } + found = (aNodes->IndexOf(node) >= 0); } previousNodeName = nodeName; if (!found) { @@ -3281,7 +3283,9 @@ static nsresult GetAllFontNames(void) { if (!gGlobalList) { - gGlobalList = new nsFontNodeArray(); + // This may well expand further (families * sizes * styles?), but it's + // only created once. + gGlobalList = new nsFontNodeArray; if (!gGlobalList) { return NS_ERROR_OUT_OF_MEMORY; } @@ -3419,6 +3423,9 @@ nsFontMetricsGTK::TryNode(nsCString* aName, PRUnichar aChar) GetFontNames(pattern.get(), &nodes); // no need to call gNodes->Put() since GetFontNames already did if (nodes.Count() > 0) { + // XXX This assertion may be spurious; you can have more than + // -*-courier-iso8859-1 font, for example, from different + // foundries. NS_ASSERTION((nodes.Count() == 1), "unexpected number of nodes"); node = nodes.GetElement(0); } @@ -3545,6 +3552,8 @@ nsFontMetricsGTK::FindStyleSheetSpecificFont(PRUnichar aChar) /* * count hyphens + * XXX It might be good to try to pre-cache this information instead + * XXX of recalculating it on every font access! */ const char* str = familyName->get(); FIND_FONT_PRINTF((" familyName = %s", str)); @@ -3824,7 +3833,7 @@ nsFontMetricsGTK::FindSubstituteFont(PRUnichar aChar) if (!mSubstituteFont) { for (int i = 0; i < mLoadedFontsCount; i++) { if (FONT_HAS_GLYPH(mLoadedFonts[i]->mMap, 'a')) { - mSubstituteFont = new nsFontGTKSubstitute(mLoadedFonts[i]); + mSubstituteFont = new nsFontGTKSubstitute(mLoadedFonts[i]); break; } } diff --git a/mozilla/gfx/src/gtk/nsFontMetricsGTK.h b/mozilla/gfx/src/gtk/nsFontMetricsGTK.h index 35c4d08e078..da621be92a8 100644 --- a/mozilla/gfx/src/gtk/nsFontMetricsGTK.h +++ b/mozilla/gfx/src/gtk/nsFontMetricsGTK.h @@ -168,7 +168,7 @@ public: nsCStringArray mFonts; PRUint16 mFontsIndex; - nsVoidArray mFontIsGeneric; + nsAutoVoidArray mFontIsGeneric; nsCAutoString mDefaultFont; nsCString *mGeneric; diff --git a/mozilla/gfx/src/nsDeviceContext.cpp b/mozilla/gfx/src/nsDeviceContext.cpp index 1732648102c..8344fc9c58c 100644 --- a/mozilla/gfx/src/nsDeviceContext.cpp +++ b/mozilla/gfx/src/nsDeviceContext.cpp @@ -615,10 +615,7 @@ nsFontCache :: GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup, if (aLangGroup == langGroup.get()) { if (cnt != 0) { // promote it to the front of the cache - for (PRInt32 i = cnt; i > 0; --i) - mFontMetrics.ReplaceElementAt(mFontMetrics[i - 1], i); - - mFontMetrics.ReplaceElementAt(metrics, 0); + mFontMetrics.MoveElement(0, cnt); } NS_ADDREF(aMetrics = metrics); return NS_OK; diff --git a/mozilla/htmlparser/src/nsDTDUtils.cpp b/mozilla/htmlparser/src/nsDTDUtils.cpp index 33a688cd788..f421ae71f06 100644 --- a/mozilla/htmlparser/src/nsDTDUtils.cpp +++ b/mozilla/htmlparser/src/nsDTDUtils.cpp @@ -1548,8 +1548,12 @@ nsresult nsObserverTopic::Notify(eHTMLTags aTag,nsIParserNode& aNode,void* aUniq PRInt32 theAttrCount =aNode.GetAttributeCount(); PRInt32 theObserversCount=theObservers->GetSize(); if(0GetViewManager(vm); + nsCOMPtr vm; + view->GetViewManager(*getter_AddRefs(vm)); const nsStyleDisplay* display; GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display); @@ -537,10 +537,10 @@ nsGfxListControlFrame::Reflow(nsIPresContext* aPresContext, } // Make sure visibility is correct - vm->SetViewVisibility(view, viewIsVisible ? nsViewVisibility_kShow : - nsViewVisibility_kHide); + if (vm) + vm->SetViewVisibility(view, viewIsVisible ? nsViewVisibility_kShow : + nsViewVisibility_kHide); - NS_RELEASE(vm); } NS_ASSERTION(aDesiredSize.width < 100000, "Width is still NS_UNCONSTRAINEDSIZE"); NS_ASSERTION(aDesiredSize.height < 100000, "Height is still NS_UNCONSTRAINEDSIZE"); @@ -2567,7 +2567,7 @@ nsGfxListControlFrame::UpdateSelection(PRBool aDoDispatchEvent, PRBool aForceUpd mSelectionCache->Clear(); for (PRInt32 i = 0; i < length; i++) { selected = IsContentSelectedByIndex(i); - mSelectionCache->InsertElementAt((void*)selected, i); + mSelectionCache->AppendElement((void*)selected); changed = PR_TRUE; } } @@ -2803,6 +2803,9 @@ nsGfxListControlFrame::SyncViewWithFrame(nsIPresContext* aPresContext) parent->GetView(aPresContext, &parentView); parentView->GetViewManager(*getter_AddRefs(viewManager)); + if (!viewManager) + return NS_ERROR_FAILURE; + GetViewOffset(viewManager, parentView, parentPos); nsIView* view = nsnull; GetView(aPresContext, &view); diff --git a/mozilla/layout/style/nsCSSDeclaration.cpp b/mozilla/layout/style/nsCSSDeclaration.cpp index bb4fd9036cf..d3be31f70ef 100644 --- a/mozilla/layout/style/nsCSSDeclaration.cpp +++ b/mozilla/layout/style/nsCSSDeclaration.cpp @@ -1148,7 +1148,7 @@ CSSDeclarationImpl::CSSDeclarationImpl(const CSSDeclarationImpl& aCopy) } if (aCopy.mOrder) { - mOrder = new nsVoidArray(); + mOrder = new nsAutoVoidArray(); if (mOrder) { (*mOrder) = *(aCopy.mOrder); } @@ -1853,13 +1853,16 @@ CSSDeclarationImpl::AppendValue(nsCSSProperty aProperty, const nsCSSValue& aValu if (NS_OK == result) { if (nsnull == mOrder) { - mOrder = new nsVoidArray(); + mOrder = new nsAutoVoidArray(); } - if (nsnull != mOrder) { + else { + // order IS important for CSS, so remove and add to the end PRInt32 index = mOrder->IndexOf((void*)aProperty); if (-1 != index) { mOrder->RemoveElementAt(index); } + } + if (nsnull != mOrder) { if (eCSSUnit_Null != aValue.GetUnit()) { mOrder->AppendElement((void*)(PRInt32)aProperty); } @@ -1934,13 +1937,16 @@ CSSDeclarationImpl::AppendStructValue(nsCSSProperty aProperty, void* aStruct) if (NS_OK == result) { if (nsnull == mOrder) { - mOrder = new nsVoidArray(); + mOrder = new nsAutoVoidArray(); } - if (nsnull != mOrder) { + else { + // order IS important for CSS, so remove and add to the end PRInt32 index = mOrder->IndexOf((void*)(PRInt32)aProperty); if (-1 != index) { mOrder->RemoveElementAt(index); } + } + if (nsnull != mOrder) { mOrder->AppendElement((void*)(PRInt32)aProperty); } } @@ -3439,7 +3445,7 @@ CSSDeclarationImpl::AppendComment(const nsAReadableString& aComment) nsresult result = NS_ERROR_OUT_OF_MEMORY; if (nsnull == mOrder) { - mOrder = new nsVoidArray(); + mOrder = new nsAutoVoidArray(); } if (nsnull == mComments) { mComments = new nsStringArray(); diff --git a/mozilla/layout/style/nsCSSStruct.cpp b/mozilla/layout/style/nsCSSStruct.cpp index bb4fd9036cf..d3be31f70ef 100644 --- a/mozilla/layout/style/nsCSSStruct.cpp +++ b/mozilla/layout/style/nsCSSStruct.cpp @@ -1148,7 +1148,7 @@ CSSDeclarationImpl::CSSDeclarationImpl(const CSSDeclarationImpl& aCopy) } if (aCopy.mOrder) { - mOrder = new nsVoidArray(); + mOrder = new nsAutoVoidArray(); if (mOrder) { (*mOrder) = *(aCopy.mOrder); } @@ -1853,13 +1853,16 @@ CSSDeclarationImpl::AppendValue(nsCSSProperty aProperty, const nsCSSValue& aValu if (NS_OK == result) { if (nsnull == mOrder) { - mOrder = new nsVoidArray(); + mOrder = new nsAutoVoidArray(); } - if (nsnull != mOrder) { + else { + // order IS important for CSS, so remove and add to the end PRInt32 index = mOrder->IndexOf((void*)aProperty); if (-1 != index) { mOrder->RemoveElementAt(index); } + } + if (nsnull != mOrder) { if (eCSSUnit_Null != aValue.GetUnit()) { mOrder->AppendElement((void*)(PRInt32)aProperty); } @@ -1934,13 +1937,16 @@ CSSDeclarationImpl::AppendStructValue(nsCSSProperty aProperty, void* aStruct) if (NS_OK == result) { if (nsnull == mOrder) { - mOrder = new nsVoidArray(); + mOrder = new nsAutoVoidArray(); } - if (nsnull != mOrder) { + else { + // order IS important for CSS, so remove and add to the end PRInt32 index = mOrder->IndexOf((void*)(PRInt32)aProperty); if (-1 != index) { mOrder->RemoveElementAt(index); } + } + if (nsnull != mOrder) { mOrder->AppendElement((void*)(PRInt32)aProperty); } } @@ -3439,7 +3445,7 @@ CSSDeclarationImpl::AppendComment(const nsAReadableString& aComment) nsresult result = NS_ERROR_OUT_OF_MEMORY; if (nsnull == mOrder) { - mOrder = new nsVoidArray(); + mOrder = new nsAutoVoidArray(); } if (nsnull == mComments) { mComments = new nsStringArray(); diff --git a/mozilla/mailnews/base/search/src/nsMsgFilterList.cpp b/mozilla/mailnews/base/search/src/nsMsgFilterList.cpp index 41d7cf3624c..593ff12ed76 100644 --- a/mozilla/mailnews/base/search/src/nsMsgFilterList.cpp +++ b/mozilla/mailnews/base/search/src/nsMsgFilterList.cpp @@ -839,11 +839,6 @@ nsresult nsMsgFilterList::MoveFilterAt(PRUint32 filterIndex, NS_ENSURE_ARG(filterCount >= filterIndex); - nsCOMPtr tempFilter; - rv = m_filters->GetElementAt(filterIndex, getter_AddRefs(tempFilter)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr oldElement; PRUint32 newIndex = filterIndex; if (motion == nsMsgFilterMotion::up) @@ -860,12 +855,7 @@ nsresult nsMsgFilterList::MoveFilterAt(PRUint32 filterIndex, // are we already at the bottom? if (newIndex > filterCount - 1) return NS_OK; } - - m_filters->GetElementAt(newIndex, getter_AddRefs(oldElement)); - m_filters->ReplaceElementAt(NS_STATIC_CAST(nsISupports*,oldElement), - filterIndex); - m_filters->ReplaceElementAt(NS_STATIC_CAST(nsISupports*,tempFilter), - newIndex); + m_filters->MoveElement(filterIndex,newIndex); return NS_OK; } diff --git a/mozilla/parser/htmlparser/src/nsDTDUtils.cpp b/mozilla/parser/htmlparser/src/nsDTDUtils.cpp index 33a688cd788..f421ae71f06 100644 --- a/mozilla/parser/htmlparser/src/nsDTDUtils.cpp +++ b/mozilla/parser/htmlparser/src/nsDTDUtils.cpp @@ -1548,8 +1548,12 @@ nsresult nsObserverTopic::Notify(eHTMLTags aTag,nsIParserNode& aNode,void* aUniq PRInt32 theAttrCount =aNode.GetAttributeCount(); PRInt32 theObserversCount=theObservers->GetSize(); if(0GetViewManager(vm); - if (nsnull != vm) + nsCOMPtr vm; + mParent->GetViewManager(*getter_AddRefs(vm)); + if (vm) { vm->RemoveChild(mParent, this); } @@ -986,6 +986,8 @@ static void ApplyZOrderStableSort(nsVoidArray &aBuffer, nsVoidArray &aMergeTmp, DisplayListElement2* e2 = NS_STATIC_CAST(DisplayListElement2*, aBuffer.ElementAt(j + 1)); if (e1->mZIndex > e2->mZIndex) { sorted = PR_FALSE; + // We could use aBuffer.MoveElement(), but it wouldn't be much of + // a win if any for swapping two elements. aBuffer.ReplaceElementAt(e2, j); aBuffer.ReplaceElementAt(e1, j + 1); } diff --git a/mozilla/xpcom/ds/nsQuickSort.h b/mozilla/xpcom/ds/nsQuickSort.h index 728dc4a2abb..cef4899dd15 100644 --- a/mozilla/xpcom/ds/nsQuickSort.h +++ b/mozilla/xpcom/ds/nsQuickSort.h @@ -36,6 +36,18 @@ */ NS_BEGIN_EXTERN_C +/** + * Parameters: + * 1. the array to sort + * 2. the number of elements in the array + * 3. the size of the array + * 4. comparison function taking two elements and parameter #5 and + * returning an integer: + * + less than zero if the first element should be before the second + * + 0 if the order of the elements does not matter + * + greater than zero if the second element should be before the first + * 5. extra data to pass to comparison function + */ PR_EXTERN(void) NS_QuickSort(void *, unsigned int, unsigned int, int (*)(const void *, const void *, void *), void *); diff --git a/mozilla/xpfe/components/shistory/src/nsSHEntry.cpp b/mozilla/xpfe/components/shistory/src/nsSHEntry.cpp index a35257b54e4..0a2c8d28a50 100644 --- a/mozilla/xpfe/components/shistory/src/nsSHEntry.cpp +++ b/mozilla/xpfe/components/shistory/src/nsSHEntry.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file @@ -299,24 +299,20 @@ nsSHEntry::AddChild(nsISHEntry * aChild, PRInt32 aOffset) NS_ENSURE_SUCCESS(aChild->SetParent(this), NS_ERROR_FAILURE); PRInt32 childCount = mChildren.Count(); - if (aOffset < childCount) - mChildren.ReplaceElementAt((void *) aChild, aOffset); - else - { - // - // Bug 52670: Ensure children are added in order. - // - // Later frames in the child list may load faster and get appended - // before earlier frames, causing session history to be scrambled. - // By growing the list here, they are added to the right position. - // - // Assert that aOffset will not be so high as to grow us a lot. - // - NS_ASSERTION(aOffset < (childCount + 1023), "Large frames array!\n"); - while (aOffset > childCount++) - mChildren.AppendElement(nsnull); - mChildren.AppendElement((void *)aChild); - } + // + // Bug 52670: Ensure children are added in order. + // + // Later frames in the child list may load faster and get appended + // before earlier frames, causing session history to be scrambled. + // By growing the list here, they are added to the right position. + // + // Assert that aOffset will not be so high as to grow us a lot. + // + NS_ASSERTION(aOffset < (childCount + 1023), "Large frames array!\n"); + + // This implicitly extends the array to include aOffset + mChildren.ReplaceElementAt(aChild, aOffset); + NS_ADDREF(aChild); return NS_OK;