bool SpanningCellSorter::AddCell(int32_t aColSpan, int32_t aRow, int32_t aCol) { NS_ASSERTION(mState == ADDING, "cannot call AddCell after GetNext"); NS_ASSERTION(aColSpan >= ARRAY_BASE, "cannot add cells with colspan<2"); Item *i = (Item*) mozilla::AutoStackArena::Allocate(sizeof(Item)); NS_ENSURE_TRUE(i != nullptr, false); i->row = aRow; i->col = aCol; if (UseArrayForSpan(aColSpan)) { int32_t index = SpanToIndex(aColSpan); i->next = mArray[index]; mArray[index] = i; } else { HashTableEntry *entry = static_cast<HashTableEntry*> (PL_DHashTableAdd(&mHashTable, NS_INT32_TO_PTR(aColSpan), fallible)); NS_ENSURE_TRUE(entry, false); NS_ASSERTION(entry->mColSpan == 0 || entry->mColSpan == aColSpan, "wrong entry"); NS_ASSERTION((entry->mColSpan == 0) == (entry->mItems == nullptr), "entry should be either new or properly initialized"); entry->mColSpan = aColSpan; i->next = entry->mItems; entry->mItems = i; } return true; }
bool SpanningCellSorter::AddCell(PRInt32 aColSpan, PRInt32 aRow, PRInt32 aCol) { NS_ASSERTION(mState == ADDING, "cannot call AddCell after GetNext"); NS_ASSERTION(aColSpan >= ARRAY_BASE, "cannot add cells with colspan<2"); Item *i = (Item*) mozilla::AutoStackArena::Allocate(sizeof(Item)); NS_ENSURE_TRUE(i != nsnull, false); i->row = aRow; i->col = aCol; if (UseArrayForSpan(aColSpan)) { PRInt32 index = SpanToIndex(aColSpan); i->next = mArray[index]; mArray[index] = i; } else { if (!mHashTable.entryCount && !PL_DHashTableInit(&mHashTable, &HashTableOps, nsnull, sizeof(HashTableEntry), PL_DHASH_MIN_SIZE)) { NS_NOTREACHED("table init failed"); mHashTable.entryCount = 0; return false; } HashTableEntry *entry = static_cast<HashTableEntry*> (PL_DHashTableOperate(&mHashTable, NS_INT32_TO_PTR(aColSpan), PL_DHASH_ADD)); NS_ENSURE_TRUE(entry, false); NS_ASSERTION(entry->mColSpan == 0 || entry->mColSpan == aColSpan, "wrong entry"); NS_ASSERTION((entry->mColSpan == 0) == (entry->mItems == nsnull), "entry should be either new or properly initialized"); entry->mColSpan = aColSpan; i->next = entry->mItems; entry->mItems = i; } return true; }