PRBool nsSmallVoidArray::SizeTo(PRInt32 aMin) { if (!HasSingle()) { return AsArray()->SizeTo(aMin); } if (aMin <= 0) { mImpl = nsnull; return PR_TRUE; } if (aMin == 1) { return PR_TRUE; } void* single = GetSingle(); mImpl = nsnull; if (!AsArray()->SizeTo(aMin)) { SetSingle(single); return PR_FALSE; } AsArray()->AppendElement(single); return PR_TRUE; }
void nsSmallVoidArray::Sort(nsVoidArrayComparatorFunc aFunc, void* aData) { if (!HasSingle()) { AsArray()->Sort(aFunc,aData); } }
bool nsSmallVoidArray::SizeTo(int32_t aMin) { if (!HasSingle()) { return AsArray()->SizeTo(aMin); } if (aMin <= 0) { mImpl = nullptr; return true; } if (aMin == 1) { return true; } void* single = GetSingle(); mImpl = nullptr; if (!AsArray()->SizeTo(aMin)) { SetSingle(single); return false; } AsArray()->AppendElement(single); return true; }
void nsSmallVoidArray::Compact() { if (!HasSingle()) { AsArray()->Compact(); } }
PRBool nsSmallVoidArray::EnumerateBackwards(nsVoidArrayEnumFunc aFunc, void* aData) { if (HasSingle()) { return (*aFunc)(GetSingle(), aData); } return AsArray()->EnumerateBackwards(aFunc,aData); }
//---------------------------------------------------------------------- // NOTE: nsSmallVoidArray elements MUST all have the low bit as 0. // This means that normally it's only used for pointers, and in particular // structures or objects. nsSmallVoidArray::~nsSmallVoidArray() { if (HasSingle()) { // Have to null out mImpl before the nsVoidArray dtor runs. mImpl = nsnull; } }
PRInt32 nsSmallVoidArray::Count() const { if (HasSingle()) { return 1; } return AsArray()->Count(); }
PRInt32 nsSmallVoidArray::GetArraySize() const { if (HasSingle()) { return 1; } return AsArray()->GetArraySize(); }
PRInt32 nsSmallVoidArray::IndexOf(void* aPossibleElement) const { if (HasSingle()) { return aPossibleElement == GetSingle() ? 0 : -1; } return AsArray()->IndexOf(aPossibleElement); }
void nsSmallVoidArray::Clear() { if (HasSingle()) { mImpl = nsnull; } else { AsArray()->Clear(); } }
void* nsSmallVoidArray::FastElementAt(PRInt32 aIndex) const { NS_ASSERTION(0 <= aIndex && aIndex < Count(), "nsSmallVoidArray::FastElementAt: index out of range"); if (HasSingle()) { return GetSingle(); } return AsArray()->FastElementAt(aIndex); }
void nsSmallVoidArray::RemoveElementAt(int32_t aIndex) { if (HasSingle()) { if (aIndex == 0) { mImpl = nullptr; } return; } AsArray()->RemoveElementAt(aIndex); }
PRBool nsSmallVoidArray::RemoveElement(void* aElement) { if (HasSingle()) { if (aElement == GetSingle()) { mImpl = nsnull; return PR_TRUE; } return PR_FALSE; } return AsArray()->RemoveElement(aElement); }
bool nsSmallVoidArray::RemoveElement(void* aElement) { if (HasSingle()) { if (aElement == GetSingle()) { mImpl = nullptr; return true; } return false; } return AsArray()->RemoveElement(aElement); }
PRBool nsSmallVoidArray::RemoveElementAt(PRInt32 aIndex) { if (HasSingle()) { if (aIndex == 0) { mImpl = nsnull; return PR_TRUE; } return PR_FALSE; } return AsArray()->RemoveElementAt(aIndex); }
void nsSmallVoidArray::RemoveElementsAt(int32_t aIndex, int32_t aCount) { if (HasSingle()) { if (aIndex == 0) { if (aCount > 0) { mImpl = nullptr; } } return; } AsArray()->RemoveElementsAt(aIndex, aCount); }
bool nsSmallVoidArray::RemoveElementAt(PRInt32 aIndex) { if (HasSingle()) { if (aIndex == 0) { mImpl = nsnull; return true; } return false; } return AsArray()->RemoveElementAt(aIndex); }
bool nsSmallVoidArray::EnsureArray() { if (!HasSingle()) { return true; } void* single = GetSingle(); mImpl = nullptr; if (!AsArray()->AppendElement(single)) { SetSingle(single); return false; } return true; }
PRBool nsSmallVoidArray::EnsureArray() { if (!HasSingle()) { return PR_TRUE; } void* single = GetSingle(); mImpl = nsnull; if (!AsArray()->AppendElement(single)) { SetSingle(single); return PR_FALSE; } return PR_TRUE; }
PRBool nsSmallVoidArray::ReplaceElementAt(void* aElement, PRInt32 aIndex) { NS_ASSERTION(!(NS_PTR_TO_INT32(aElement) & 0x1), "Attempt to add element with 0x1 bit set to nsSmallVoidArray"); if (aIndex == 0 && (IsEmpty() || HasSingle())) { SetSingle(aElement); return PR_TRUE; } if (!EnsureArray()) { return PR_FALSE; } return AsArray()->ReplaceElementAt(aElement, aIndex); }