mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 696201. Switch nsContentList to using an nsTArray as the element store. r=sicking
This commit is contained in:
parent
58dc8c785d
commit
0a2deaca87
@ -68,7 +68,6 @@ NS_NewPreContentIterator(nsIContentIterator** aInstancePtrResult);
|
||||
#define ASSERT_IN_SYNC PR_BEGIN_MACRO PR_END_MACRO
|
||||
#endif
|
||||
|
||||
|
||||
using namespace mozilla::dom;
|
||||
|
||||
nsBaseContentList::~nsBaseContentList()
|
||||
@ -77,11 +76,11 @@ nsBaseContentList::~nsBaseContentList()
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(nsBaseContentList)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsBaseContentList)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mElements)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSTARRAY(mElements)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsBaseContentList)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mElements)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY_OF_NSCOMPTR(mElements)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsBaseContentList)
|
||||
@ -113,7 +112,7 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(nsBaseContentList)
|
||||
NS_IMETHODIMP
|
||||
nsBaseContentList::GetLength(PRUint32* aLength)
|
||||
{
|
||||
*aLength = mElements.Count();
|
||||
*aLength = mElements.Length();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -135,7 +134,7 @@ nsBaseContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
|
||||
nsIContent*
|
||||
nsBaseContentList::GetNodeAt(PRUint32 aIndex)
|
||||
{
|
||||
return mElements.SafeObjectAt(aIndex);
|
||||
return mElements.SafeElementAt(aIndex);
|
||||
}
|
||||
|
||||
|
||||
@ -151,23 +150,6 @@ nsBaseContentList::IndexOf(nsIContent* aContent)
|
||||
return IndexOf(aContent, true);
|
||||
}
|
||||
|
||||
void nsBaseContentList::AppendElement(nsIContent *aContent)
|
||||
{
|
||||
mElements.AppendObject(aContent);
|
||||
}
|
||||
|
||||
void nsBaseContentList::RemoveElement(nsIContent *aContent)
|
||||
{
|
||||
mElements.RemoveObject(aContent);
|
||||
}
|
||||
|
||||
void nsBaseContentList::InsertElementAt(nsIContent* aContent, PRInt32 aIndex)
|
||||
{
|
||||
NS_ASSERTION(aContent, "Element to insert must not be null");
|
||||
mElements.InsertObjectAt(aContent, aIndex);
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(nsSimpleContentList)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsSimpleContentList,
|
||||
nsBaseContentList)
|
||||
@ -533,7 +515,7 @@ nsContentList::Length(bool aDoFlush)
|
||||
{
|
||||
BringSelfUpToDate(aDoFlush);
|
||||
|
||||
return mElements.Count();
|
||||
return mElements.Length();
|
||||
}
|
||||
|
||||
nsIContent *
|
||||
@ -555,7 +537,7 @@ nsContentList::Item(PRUint32 aIndex, bool aDoFlush)
|
||||
NS_ASSERTION(!mRootNode || mState != LIST_DIRTY,
|
||||
"PopulateSelf left the list in a dirty (useless) state!");
|
||||
|
||||
return mElements.SafeObjectAt(aIndex);
|
||||
return mElements.SafeElementAt(aIndex);
|
||||
}
|
||||
|
||||
nsIContent *
|
||||
@ -563,7 +545,7 @@ nsContentList::NamedItem(const nsAString& aName, bool aDoFlush)
|
||||
{
|
||||
BringSelfUpToDate(aDoFlush);
|
||||
|
||||
PRInt32 i, count = mElements.Count();
|
||||
PRUint32 i, count = mElements.Length();
|
||||
|
||||
// Typically IDs and names are atomized
|
||||
nsCOMPtr<nsIAtom> name = do_GetAtom(aName);
|
||||
@ -677,7 +659,7 @@ nsContentList::AttributeChanged(nsIDocument *aDocument, Element* aElement,
|
||||
}
|
||||
|
||||
if (Match(aElement)) {
|
||||
if (mElements.IndexOf(aElement) == -1) {
|
||||
if (mElements.IndexOf(aElement) == mElements.NoIndex) {
|
||||
// We match aElement now, and it's not in our list already. Just dirty
|
||||
// ourselves; this is simpler than trying to figure out where to insert
|
||||
// aElement.
|
||||
@ -688,7 +670,7 @@ nsContentList::AttributeChanged(nsIDocument *aDocument, Element* aElement,
|
||||
// already not there, this is a no-op (though a potentially
|
||||
// expensive one). Either way, no change of mState is required
|
||||
// here.
|
||||
mElements.RemoveObject(aElement);
|
||||
mElements.RemoveElement(aElement);
|
||||
}
|
||||
}
|
||||
|
||||
@ -722,7 +704,7 @@ nsContentList::ContentAppended(nsIDocument* aDocument, nsIContent* aContainer,
|
||||
PRInt32 count = aContainer->GetChildCount();
|
||||
|
||||
if (count > 0) {
|
||||
PRInt32 ourCount = mElements.Count();
|
||||
PRUint32 ourCount = mElements.Length();
|
||||
bool appendToList = false;
|
||||
if (ourCount == 0) {
|
||||
appendToList = true;
|
||||
@ -772,13 +754,13 @@ nsContentList::ContentAppended(nsIDocument* aDocument, nsIContent* aContainer,
|
||||
cur;
|
||||
cur = cur->GetNextNode(aContainer)) {
|
||||
if (cur->IsElement() && Match(cur->AsElement())) {
|
||||
mElements.AppendObject(cur);
|
||||
mElements.AppendElement(cur);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (nsIContent* cur = aFirstNewContent; cur; cur = cur->GetNextSibling()) {
|
||||
if (cur->IsElement() && Match(cur->AsElement())) {
|
||||
mElements.AppendObject(cur);
|
||||
mElements.AppendElement(cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -901,7 +883,7 @@ nsContentList::PopulateSelf(PRUint32 aNeededLength)
|
||||
|
||||
ASSERT_IN_SYNC;
|
||||
|
||||
PRUint32 count = mElements.Count();
|
||||
PRUint32 count = mElements.Length();
|
||||
NS_ASSERTION(mState != LIST_DIRTY || count == 0,
|
||||
"Reset() not called when setting state to LIST_DIRTY?");
|
||||
|
||||
@ -910,7 +892,7 @@ nsContentList::PopulateSelf(PRUint32 aNeededLength)
|
||||
|
||||
PRUint32 elementsToAppend = aNeededLength - count;
|
||||
#ifdef DEBUG
|
||||
PRUint32 invariant = elementsToAppend + mElements.Count();
|
||||
PRUint32 invariant = elementsToAppend + mElements.Length();
|
||||
#endif
|
||||
|
||||
if (mDeep) {
|
||||
@ -923,7 +905,8 @@ nsContentList::PopulateSelf(PRUint32 aNeededLength)
|
||||
break;
|
||||
}
|
||||
if (cur->IsElement() && Match(cur->AsElement())) {
|
||||
mElements.AppendObject(cur->AsElement());
|
||||
// Append AsElement() to get nsIContent instead of nsINode
|
||||
mElements.AppendElement(cur->AsElement());
|
||||
--elementsToAppend;
|
||||
}
|
||||
} while (elementsToAppend);
|
||||
@ -932,13 +915,13 @@ nsContentList::PopulateSelf(PRUint32 aNeededLength)
|
||||
count ? mElements[count-1]->GetNextSibling() : mRootNode->GetFirstChild();
|
||||
for ( ; cur && elementsToAppend; cur = cur->GetNextSibling()) {
|
||||
if (cur->IsElement() && Match(cur->AsElement())) {
|
||||
mElements.AppendObject(cur);
|
||||
mElements.AppendElement(cur);
|
||||
--elementsToAppend;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_ASSERTION(elementsToAppend + mElements.Count() == invariant,
|
||||
NS_ASSERTION(elementsToAppend + mElements.Length() == invariant,
|
||||
"Something is awry!");
|
||||
|
||||
if (elementsToAppend != 0)
|
||||
@ -1024,7 +1007,7 @@ nsContentList::AssertInSync()
|
||||
}
|
||||
|
||||
if (!mRootNode) {
|
||||
NS_ASSERTION(mElements.Count() == 0 && mState == LIST_DIRTY,
|
||||
NS_ASSERTION(mElements.Length() == 0 && mState == LIST_DIRTY,
|
||||
"Empty iterator isn't quite empty?");
|
||||
return;
|
||||
}
|
||||
@ -1046,9 +1029,9 @@ nsContentList::AssertInSync()
|
||||
iter->First();
|
||||
}
|
||||
|
||||
PRInt32 cnt = 0, index = 0;
|
||||
PRUint32 cnt = 0, index = 0;
|
||||
while (true) {
|
||||
if (cnt == mElements.Count() && mState == LIST_LAZY) {
|
||||
if (cnt == mElements.Length() && mState == LIST_LAZY) {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1059,7 +1042,7 @@ nsContentList::AssertInSync()
|
||||
}
|
||||
|
||||
if (cur->IsElement() && Match(cur->AsElement())) {
|
||||
NS_ASSERTION(cnt < mElements.Count() && mElements[cnt] == cur,
|
||||
NS_ASSERTION(cnt < mElements.Length() && mElements[cnt] == cur,
|
||||
"Elements is out of sync");
|
||||
++cnt;
|
||||
}
|
||||
@ -1069,6 +1052,6 @@ nsContentList::AssertInSync()
|
||||
}
|
||||
}
|
||||
|
||||
NS_ASSERTION(cnt == mElements.Count(), "Too few elements");
|
||||
NS_ASSERTION(cnt == mElements.Length(), "Too few elements");
|
||||
}
|
||||
#endif
|
||||
|
@ -45,7 +45,7 @@
|
||||
#define nsContentList_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIHTMLCollection.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
@ -100,12 +100,15 @@ public:
|
||||
virtual PRInt32 IndexOf(nsIContent* aContent);
|
||||
|
||||
PRUint32 Length() const {
|
||||
return mElements.Count();
|
||||
return mElements.Length();
|
||||
}
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsBaseContentList)
|
||||
|
||||
void AppendElement(nsIContent *aContent);
|
||||
void AppendElement(nsIContent *aContent)
|
||||
{
|
||||
mElements.AppendElement(aContent);
|
||||
}
|
||||
void MaybeAppendElement(nsIContent* aContent)
|
||||
{
|
||||
if (aContent)
|
||||
@ -118,9 +121,16 @@ public:
|
||||
* @param aContent Element to insert, must not be null
|
||||
* @param aIndex Index to insert the element at.
|
||||
*/
|
||||
void InsertElementAt(nsIContent* aContent, PRInt32 aIndex);
|
||||
void InsertElementAt(nsIContent* aContent, PRInt32 aIndex)
|
||||
{
|
||||
NS_ASSERTION(aContent, "Element to insert must not be null");
|
||||
mElements.InsertElementAt(aIndex, aContent);
|
||||
}
|
||||
|
||||
void RemoveElement(nsIContent *aContent);
|
||||
void RemoveElement(nsIContent *aContent)
|
||||
{
|
||||
mElements.RemoveElement(aContent);
|
||||
}
|
||||
|
||||
void Reset() {
|
||||
mElements.Clear();
|
||||
@ -132,7 +142,7 @@ public:
|
||||
bool *triedToWrap) = 0;
|
||||
|
||||
protected:
|
||||
nsCOMArray<nsIContent> mElements;
|
||||
nsTArray< nsCOMPtr<nsIContent> > mElements;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user