зеркало из https://github.com/mozilla/pjs.git
- fix ReplaceObjectAt to properly account for existing null entries
- make nsCOMArray_base accessible from nsCOMArray<T> so that a nsCOMArray<T> can passed to NS_NewArray for bug 162115, not part of build
This commit is contained in:
Родитель
faf8498d08
Коммит
e3d65d86d6
|
@ -38,10 +38,8 @@
|
||||||
|
|
||||||
#include "nsCOMArray.h"
|
#include "nsCOMArray.h"
|
||||||
|
|
||||||
static PRBool AddRefObjects(void* aElement, void*);
|
|
||||||
static PRBool ReleaseObjects(void* aElement, void*);
|
static PRBool ReleaseObjects(void* aElement, void*);
|
||||||
|
|
||||||
|
|
||||||
// implementations of non-trivial methods in nsCOMArray_base
|
// implementations of non-trivial methods in nsCOMArray_base
|
||||||
|
|
||||||
// copy constructor - we can't just memcpy here, because
|
// copy constructor - we can't just memcpy here, because
|
||||||
|
@ -55,6 +53,7 @@ nsCOMArray_base::nsCOMArray_base(const nsCOMArray_base& aOther)
|
||||||
|
|
||||||
PRInt32 i;
|
PRInt32 i;
|
||||||
for (i=0; i<count; i++) {
|
for (i=0; i<count; i++) {
|
||||||
|
// ReplaceObjectAt will handle existing null entries for us
|
||||||
ReplaceObjectAt(aOther[i], i);
|
ReplaceObjectAt(aOther[i], i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,19 +69,18 @@ nsCOMArray_base::InsertObjectAt(nsISupports* aObject, PRInt32 aIndex) {
|
||||||
PRBool
|
PRBool
|
||||||
nsCOMArray_base::ReplaceObjectAt(nsISupports* aObject, PRInt32 aIndex)
|
nsCOMArray_base::ReplaceObjectAt(nsISupports* aObject, PRInt32 aIndex)
|
||||||
{
|
{
|
||||||
|
// its ok if oldObject is null here
|
||||||
nsISupports *oldObject = ObjectAt(aIndex);
|
nsISupports *oldObject = ObjectAt(aIndex);
|
||||||
if (oldObject) {
|
|
||||||
PRBool result = mArray.ReplaceElementAt(aObject, aIndex);
|
|
||||||
|
|
||||||
// ReplaceElementAt could fail, such as if the array grows
|
PRBool result = mArray.ReplaceElementAt(aObject, aIndex);
|
||||||
// so only release the existing object if the replacement succeeded
|
|
||||||
if (result) {
|
// ReplaceElementAt could fail, such as if the array grows
|
||||||
NS_IF_RELEASE(oldObject);
|
// so only release the existing object if the replacement succeeded
|
||||||
NS_IF_ADDREF(aObject);
|
if (result) {
|
||||||
}
|
NS_IF_RELEASE(oldObject);
|
||||||
return result;
|
NS_IF_ADDREF(aObject);
|
||||||
}
|
}
|
||||||
return PR_FALSE;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,16 +115,6 @@ nsCOMArray_base::RemoveObjectAt(PRInt32 aIndex)
|
||||||
return PR_FALSE;
|
return PR_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// useful for copy constructors
|
|
||||||
PRBool
|
|
||||||
AddRefObjects(void* aElement, void*)
|
|
||||||
{
|
|
||||||
nsISupports* element = NS_STATIC_CAST(nsISupports*,aElement);
|
|
||||||
NS_IF_ADDREF(element);
|
|
||||||
return PR_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// useful for destructors
|
// useful for destructors
|
||||||
PRBool
|
PRBool
|
||||||
ReleaseObjects(void* aElement, void*)
|
ReleaseObjects(void* aElement, void*)
|
||||||
|
|
|
@ -113,7 +113,7 @@ protected:
|
||||||
// that methods like ObjectAt() may return null when refering to an
|
// that methods like ObjectAt() may return null when refering to an
|
||||||
// existing, but null entry in the array.
|
// existing, but null entry in the array.
|
||||||
template <class T>
|
template <class T>
|
||||||
class nsCOMArray : protected nsCOMArray_base
|
class nsCOMArray : public nsCOMArray_base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
nsCOMArray() {}
|
nsCOMArray() {}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче