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; }
/** * AddBinding * * Called from FindEntry() if we read an entry off of disk * - it may already have a generation number * - a generation number conflict is an error * * Called from BindEntry() * - a generation number needs to be assigned */ nsresult nsDiskCacheBindery::AddBinding(nsDiskCacheBinding * binding) { NS_ENSURE_ARG_POINTER(binding); NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized"); // find hash entry for key HashTableEntry * hashEntry; hashEntry = (HashTableEntry *) PL_DHashTableAdd(&table, (void *)(uintptr_t) binding->mRecord.HashNumber(), fallible); if (!hashEntry) return NS_ERROR_OUT_OF_MEMORY; if (hashEntry->mBinding == nullptr) { hashEntry->mBinding = binding; if (binding->mGeneration == 0) binding->mGeneration = 1; // if generation uninitialized, set it to 1 return NS_OK; } // insert binding in generation order nsDiskCacheBinding * p = hashEntry->mBinding; bool calcGeneration = (binding->mGeneration == 0); // do we need to calculate generation? if (calcGeneration) binding->mGeneration = 1; // initialize to 1 if uninitialized while (1) { if (binding->mGeneration < p->mGeneration) { // here we are PR_INSERT_BEFORE(binding, p); if (hashEntry->mBinding == p) hashEntry->mBinding = binding; break; } if (binding->mGeneration == p->mGeneration) { if (calcGeneration) ++binding->mGeneration; // try the next generation else { NS_ERROR("### disk cache: generations collide!"); return NS_ERROR_UNEXPECTED; } } p = (nsDiskCacheBinding *)PR_NEXT_LINK(p); if (p == hashEntry->mBinding) { // end of line: insert here or die p = (nsDiskCacheBinding *)PR_PREV_LINK(p); // back up and check generation if (p->mGeneration == 255) { NS_WARNING("### disk cache: generation capacity at full"); return NS_ERROR_UNEXPECTED; } PR_INSERT_BEFORE(binding, hashEntry->mBinding); break; } } return NS_OK; }
NS_IMETHODIMP nsPersistentProperties::SetStringProperty(const nsACString& aKey, const nsAString& aNewValue, nsAString& aOldValue) { const nsAFlatCString& flatKey = PromiseFlatCString(aKey); PropertyTableEntry* entry = static_cast<PropertyTableEntry*>( PL_DHashTableAdd(&mTable, flatKey.get())); if (entry->mKey) { aOldValue = entry->mValue; NS_WARNING(nsPrintfCString("the property %s already exists\n", flatKey.get()).get()); } else { aOldValue.Truncate(); } entry->mKey = ArenaStrdup(flatKey, &mArena); entry->mValue = ArenaStrdup(PromiseFlatString(aNewValue), &mArena); return NS_OK; }