зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1008420, part 2 - Split out a refcountless nsArray base class. r=bsmedberg
This commit is contained in:
Родитель
57f3f97385
Коммит
a95191e7f0
|
@ -17,7 +17,7 @@
|
|||
COMPONENT(PERSISTENTPROPERTIES, nsPersistentProperties::Create)
|
||||
|
||||
COMPONENT(SUPPORTSARRAY, nsSupportsArray::Create)
|
||||
COMPONENT(ARRAY, nsArray::XPCOMConstructor)
|
||||
COMPONENT(ARRAY, nsArrayBase::XPCOMConstructor)
|
||||
COMPONENT(CONSOLESERVICE, nsConsoleServiceConstructor)
|
||||
COMPONENT(ATOMSERVICE, nsAtomServiceConstructor)
|
||||
COMPONENT(OBSERVERSERVICE, nsObserverService::Create)
|
||||
|
|
|
@ -31,7 +31,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsArrayCC)
|
|||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIMutableArray)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
nsArray::~nsArray()
|
||||
nsArrayBase::~nsArrayBase()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
@ -53,16 +53,16 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsArrayCC)
|
|||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsArray::GetLength(uint32_t* aLength)
|
||||
nsArrayBase::GetLength(uint32_t* aLength)
|
||||
{
|
||||
*aLength = mArray.Count();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsArray::QueryElementAt(uint32_t aIndex,
|
||||
const nsIID& aIID,
|
||||
void ** aResult)
|
||||
nsArrayBase::QueryElementAt(uint32_t aIndex,
|
||||
const nsIID& aIID,
|
||||
void** aResult)
|
||||
{
|
||||
nsISupports * obj = mArray.SafeObjectAt(aIndex);
|
||||
if (!obj) return NS_ERROR_ILLEGAL_VALUE;
|
||||
|
@ -73,8 +73,8 @@ nsArray::QueryElementAt(uint32_t aIndex,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsArray::IndexOf(uint32_t aStartIndex, nsISupports* aElement,
|
||||
uint32_t* aResult)
|
||||
nsArrayBase::IndexOf(uint32_t aStartIndex, nsISupports* aElement,
|
||||
uint32_t* aResult)
|
||||
{
|
||||
// optimize for the common case by forwarding to mArray
|
||||
if (aStartIndex == 0) {
|
||||
|
@ -96,7 +96,7 @@ nsArray::IndexOf(uint32_t aStartIndex, nsISupports* aElement,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsArray::Enumerate(nsISimpleEnumerator **aResult)
|
||||
nsArrayBase::Enumerate(nsISimpleEnumerator** aResult)
|
||||
{
|
||||
return NS_NewArrayEnumerator(aResult, static_cast<nsIArray*>(this));
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ nsArray::Enumerate(nsISimpleEnumerator **aResult)
|
|||
// nsIMutableArray implementation
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsArray::AppendElement(nsISupports* aElement, bool aWeak)
|
||||
nsArrayBase::AppendElement(nsISupports* aElement, bool aWeak)
|
||||
{
|
||||
bool result;
|
||||
if (aWeak) {
|
||||
|
@ -123,14 +123,14 @@ nsArray::AppendElement(nsISupports* aElement, bool aWeak)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsArray::RemoveElementAt(uint32_t aIndex)
|
||||
nsArrayBase::RemoveElementAt(uint32_t aIndex)
|
||||
{
|
||||
bool result = mArray.RemoveObjectAt(aIndex);
|
||||
return result ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsArray::InsertElementAt(nsISupports* aElement, uint32_t aIndex, bool aWeak)
|
||||
nsArrayBase::InsertElementAt(nsISupports* aElement, uint32_t aIndex, bool aWeak)
|
||||
{
|
||||
nsCOMPtr<nsISupports> elementRef;
|
||||
if (aWeak) {
|
||||
|
@ -146,7 +146,7 @@ nsArray::InsertElementAt(nsISupports* aElement, uint32_t aIndex, bool aWeak)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsArray::ReplaceElementAt(nsISupports* aElement, uint32_t aIndex, bool aWeak)
|
||||
nsArrayBase::ReplaceElementAt(nsISupports* aElement, uint32_t aIndex, bool aWeak)
|
||||
{
|
||||
nsCOMPtr<nsISupports> elementRef;
|
||||
if (aWeak) {
|
||||
|
@ -162,7 +162,7 @@ nsArray::ReplaceElementAt(nsISupports* aElement, uint32_t aIndex, bool aWeak)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsArray::Clear()
|
||||
nsArrayBase::Clear()
|
||||
{
|
||||
mArray.Clear();
|
||||
return NS_OK;
|
||||
|
@ -191,7 +191,7 @@ FindElementCallback(void *aElement, void* aClosure)
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsArray::XPCOMConstructor(nsISupports *aOuter, const nsIID& aIID, void **aResult)
|
||||
nsArrayBase::XPCOMConstructor(nsISupports* aOuter, const nsIID& aIID, void** aResult)
|
||||
{
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
@ -201,8 +201,13 @@ nsArray::XPCOMConstructor(nsISupports *aOuter, const nsIID& aIID, void **aResult
|
|||
}
|
||||
|
||||
already_AddRefed<nsIMutableArray>
|
||||
nsArray::Create()
|
||||
nsArrayBase::Create()
|
||||
{
|
||||
nsCOMPtr<nsIMutableArray> inst = NS_IsMainThread() ? new nsArrayCC : new nsArray;
|
||||
nsCOMPtr<nsIMutableArray> inst;
|
||||
if (NS_IsMainThread()) {
|
||||
inst = new nsArrayCC;
|
||||
} else {
|
||||
inst = new nsArray;
|
||||
}
|
||||
return inst.forget();
|
||||
}
|
||||
|
|
|
@ -17,10 +17,10 @@
|
|||
{ 0x35c66fd1, 0x95e9, 0x4e0a, \
|
||||
{ 0x80, 0xc5, 0xc3, 0xbd, 0x2b, 0x37, 0x54, 0x81 } }
|
||||
|
||||
class nsArray : public nsIMutableArray
|
||||
// nsArray without any refcounting declarations
|
||||
class nsArrayBase : public nsIMutableArray
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIARRAY
|
||||
NS_DECL_NSIMUTABLEARRAY
|
||||
|
||||
|
@ -33,29 +33,57 @@ public:
|
|||
static nsresult XPCOMConstructor(nsISupports* aOuter, const nsIID& aIID,
|
||||
void** aResult);
|
||||
protected:
|
||||
nsArray() { }
|
||||
nsArray(const nsArray& other);
|
||||
nsArray(const nsCOMArray_base& aBaseArray) : mArray(aBaseArray)
|
||||
{ }
|
||||
|
||||
virtual ~nsArray(); // nsArrayCC inherits from this
|
||||
nsArrayBase()
|
||||
{
|
||||
}
|
||||
nsArrayBase(const nsArrayBase& other);
|
||||
nsArrayBase(const nsCOMArray_base& aBaseArray)
|
||||
: mArray(aBaseArray)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~nsArrayBase();
|
||||
|
||||
nsCOMArray_base mArray;
|
||||
};
|
||||
|
||||
class nsArrayCC MOZ_FINAL : public nsArray
|
||||
class nsArray MOZ_FINAL : public nsArrayBase
|
||||
{
|
||||
friend class nsArray;
|
||||
friend class nsArrayBase;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
private:
|
||||
nsArray()
|
||||
: nsArrayBase()
|
||||
{
|
||||
}
|
||||
nsArray(const nsArray& other);
|
||||
nsArray(const nsCOMArray_base& aBaseArray)
|
||||
: nsArrayBase(aBaseArray)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class nsArrayCC MOZ_FINAL : public nsArrayBase
|
||||
{
|
||||
friend class nsArrayBase;
|
||||
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(nsArrayCC)
|
||||
|
||||
private:
|
||||
nsArrayCC() : nsArray() { }
|
||||
nsArrayCC()
|
||||
: nsArrayBase()
|
||||
{
|
||||
}
|
||||
nsArrayCC(const nsArrayCC& other);
|
||||
nsArrayCC(const nsCOMArray_base& aBaseArray) : nsArray(aBaseArray)
|
||||
{ }
|
||||
nsArrayCC(const nsCOMArray_base& aBaseArray)
|
||||
: nsArrayBase(aBaseArray)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
// work of this class in the XPCOM dll
|
||||
class NS_COM_GLUE nsCOMArray_base
|
||||
{
|
||||
friend class nsArray;
|
||||
friend class nsArrayBase;
|
||||
protected:
|
||||
nsCOMArray_base() {}
|
||||
nsCOMArray_base(int32_t aCount) : mArray(aCount) {}
|
||||
|
|
Загрузка…
Ссылка в новой задаче