зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
2221342506
Коммит
d4b748fded
|
@ -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) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче