diff --git a/xpcom/ds/nsCOMArray.cpp b/xpcom/ds/nsCOMArray.cpp index b8700449cdca..9c28266c36cc 100644 --- a/xpcom/ds/nsCOMArray.cpp +++ b/xpcom/ds/nsCOMArray.cpp @@ -66,6 +66,19 @@ nsCOMArray_base::InsertObjectAt(nsISupports* aObject, PRInt32 aIndex) { return result; } +PRBool +nsCOMArray_base::InsertObjectsAt(const nsCOMArray_base& aObjects, PRInt32 aIndex) { + PRBool result = mArray.InsertElementsAt(aObjects.mArray, aIndex); + if (result) { + // need to addref all these + PRInt32 count = aObjects.Count(); + for (PRInt32 i = 0; i < count; ++i) { + NS_IF_ADDREF(aObjects.ObjectAt(i)); + } + } + return result; +} + PRBool nsCOMArray_base::ReplaceObjectAt(nsISupports* aObject, PRInt32 aIndex) { diff --git a/xpcom/ds/nsCOMArray.h b/xpcom/ds/nsCOMArray.h index 3fa9c8b00cd8..b400232bd467 100644 --- a/xpcom/ds/nsCOMArray.h +++ b/xpcom/ds/nsCOMArray.h @@ -71,9 +71,13 @@ protected: // all over the place void Clear(); PRBool InsertObjectAt(nsISupports* aObject, PRInt32 aIndex); + PRBool InsertObjectsAt(const nsCOMArray_base& aObjects, PRInt32 aIndex); PRBool ReplaceObjectAt(nsISupports* aObject, PRInt32 aIndex); PRBool AppendObject(nsISupports *aObject) { - return InsertObjectAt(aObject, Count()); + return InsertObjectAt(aObject, Count()); + } + PRBool AppendObjects(const nsCOMArray_base& aObjects) { + return InsertObjectsAt(aObjects, Count()); } PRBool RemoveObject(nsISupports *aObject); PRBool RemoveObjectAt(PRInt32 aIndex); @@ -148,12 +152,18 @@ class nsCOMArray : public nsCOMArray_base return nsCOMArray_base::IndexOf(aObject); } - // inserts the object at aIndex, and move all objects after aIndex - // to the right + // inserts aObject at aIndex, shifting the objects at aIndex and + // later to make space PRBool InsertObjectAt(T* aObject, PRInt32 aIndex) { return nsCOMArray_base::InsertObjectAt(aObject, aIndex); } + // inserts the objects from aObject at aIndex, shifting the + // objects at aIndex and later to make space + PRBool InsertObjectsAt(const nsCOMArray& aObjects, PRInt32 aIndex) { + return nsCOMArray_base::InsertObjectsAt(aObjects, aIndex); + } + // replaces an existing element. Warning: if the array grows, // the newly created entries will all be null PRBool ReplaceObjectAt(T* aObject, PRInt32 aIndex) { @@ -195,6 +205,11 @@ class nsCOMArray : public nsCOMArray_base return nsCOMArray_base::AppendObject(aObject); } + // append objects, growing the array as necessary + PRBool AppendObjects(const nsCOMArray& aObjects) { + return nsCOMArray_base::AppendObjects(aObjects); + } + // remove the first instance of the given object and shrink the // array as necessary // Warning: if you pass null here, it will remove the first null element