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; }
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; }
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; }
bool nsSmallVoidArray::EnsureArray() { if (!HasSingle()) { return true; } void* single = GetSingle(); mImpl = nullptr; if (!AsArray()->AppendElement(single)) { SetSingle(single); return false; } return true; }
PRBool nsSmallVoidArray::AppendElement(void* aElement) { NS_ASSERTION(!(NS_PTR_TO_INT32(aElement) & 0x1), "Attempt to add element with 0x1 bit set to nsSmallVoidArray"); if (IsEmpty()) { SetSingle(aElement); return PR_TRUE; } if (!EnsureArray()) { return PR_FALSE; } return AsArray()->AppendElement(aElement); }
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); }
bool nsSmallVoidArray::InsertElementAt(void* aElement, int32_t aIndex) { NS_ASSERTION(!(NS_PTR_TO_INT32(aElement) & 0x1), "Attempt to add element with 0x1 bit set to nsSmallVoidArray"); if (aIndex == 0 && IsEmpty()) { SetSingle(aElement); return true; } if (!EnsureArray()) { return false; } return AsArray()->InsertElementAt(aElement, aIndex); }
PRBool nsSmallVoidArray::InsertElementsAt(const nsVoidArray &aOther, PRInt32 aIndex) { #ifdef DEBUG for (int i = 0; i < aOther.Count(); i++) { NS_ASSERTION(!(NS_PTR_TO_INT32(aOther.ElementAt(i)) & 0x1), "Attempt to add element with 0x1 bit set to nsSmallVoidArray"); } #endif if (aIndex == 0 && IsEmpty() && aOther.Count() == 1) { SetSingle(aOther.FastElementAt(0)); return PR_TRUE; } if (!EnsureArray()) { return PR_FALSE; } return AsArray()->InsertElementsAt(aOther, aIndex); }