Bug 198685 need nsCOMArray function like IndexOf that checks COM object identity p=bsmedberg@covad.net r=alecf (no sr needed)

This commit is contained in:
neil%parkwaycc.co.uk 2005-11-02 16:05:09 +00:00
Родитель b0a45e4a36
Коммит 100f075a91
2 изменённых файлов: 33 добавлений и 0 удалений

Просмотреть файл

@ -61,6 +61,26 @@ nsCOMArray_base::~nsCOMArray_base()
}
}
PRInt32
nsCOMArray_base::IndexOfObject(nsISupports* aObject) const {
NS_ENSURE_TRUE(aObject, -1);
nsCOMPtr<nsISupports> supports = do_QueryInterface(aObject);
NS_ENSURE_TRUE(supports, -1);
PRInt32 i, count;
PRInt32 retval = -1;
count = mArray.Count();
for (i = 0; i < count; ++i) {
nsCOMPtr<nsISupports> arrayItem =
do_QueryInterface(NS_REINTERPRET_CAST(nsISupports*,mArray.ElementAt(i)));
if (arrayItem == supports) {
retval = i;
break;
}
}
return retval;
}
PRBool
nsCOMArray_base::InsertObjectAt(nsISupports* aObject, PRInt32 aIndex) {
PRBool result = mArray.InsertElementAt(aObject, aIndex);

Просмотреть файл

@ -60,6 +60,8 @@ protected:
return mArray.IndexOf(aObject);
}
PRInt32 IndexOfObject(nsISupports* aObject) const;
PRBool EnumerateForwards(nsVoidArrayEnumFunc aFunc, void* aData) {
return mArray.EnumerateForwards(aFunc, aData);
}
@ -150,10 +152,21 @@ class nsCOMArray : public nsCOMArray_base
}
// index of the element in question.. does NOT refcount
// note: this does not check COM object identity. Use
// IndexOfObject() for that purpose
PRInt32 IndexOf(T* aObject) const {
return nsCOMArray_base::IndexOf(NS_STATIC_CAST(nsISupports*, aObject));
}
// index of the element in question.. be careful!
// this is much slower than IndexOf() because it uses
// QueryInterface to determine actual COM identity of the object
// if you need to do this frequently then consider enforcing
// COM object identity before adding/comparing elements
PRInt32 IndexOfObject(T* aObject) const {
return nsCOMArray_base::IndexOfObject(NS_STATIC_CAST(nsISupports*, aObject));
}
// inserts aObject at aIndex, shifting the objects at aIndex and
// later to make space
PRBool InsertObjectAt(T* aObject, PRInt32 aIndex) {