void nsCSSExpandedDataBlock::Expand(nsCSSCompressedDataBlock *aNormalBlock, nsCSSCompressedDataBlock *aImportantBlock) { NS_ABORT_IF_FALSE(aNormalBlock, "unexpected null block"); AssertInitialState(); DoExpand(aNormalBlock, false); if (aImportantBlock) { DoExpand(aImportantBlock, true); } }
void nsCSSExpandedDataBlock::Clear() { for (size_t iHigh = 0; iHigh < nsCSSPropertySet::kChunkCount; ++iHigh) { if (!mPropertiesSet.HasPropertyInChunk(iHigh)) continue; for (size_t iLow = 0; iLow < nsCSSPropertySet::kBitsInChunk; ++iLow) { if (!mPropertiesSet.HasPropertyAt(iHigh, iLow)) continue; nsCSSProperty iProp = nsCSSPropertySet::CSSPropertyAt(iHigh, iLow); ClearLonghandProperty(iProp); } } AssertInitialState(); }
void nsCSSExpandedDataBlock::Compress(nsCSSCompressedDataBlock **aNormalBlock, nsCSSCompressedDataBlock **aImportantBlock) { nsAutoPtr<nsCSSCompressedDataBlock> result_normal, result_important; uint32_t i_normal = 0, i_important = 0; uint32_t numPropsNormal, numPropsImportant; ComputeNumProps(&numPropsNormal, &numPropsImportant); result_normal = new(numPropsNormal) nsCSSCompressedDataBlock(numPropsNormal); if (numPropsImportant != 0) { result_important = new(numPropsImportant) nsCSSCompressedDataBlock(numPropsImportant); } else { result_important = nullptr; } /* * Save needless copying and allocation by copying the memory * corresponding to the stored data in the expanded block, and then * clearing the data in the expanded block. */ for (size_t iHigh = 0; iHigh < nsCSSPropertySet::kChunkCount; ++iHigh) { if (!mPropertiesSet.HasPropertyInChunk(iHigh)) continue; for (size_t iLow = 0; iLow < nsCSSPropertySet::kBitsInChunk; ++iLow) { if (!mPropertiesSet.HasPropertyAt(iHigh, iLow)) continue; nsCSSProperty iProp = nsCSSPropertySet::CSSPropertyAt(iHigh, iLow); NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(iProp), "out of range"); bool important = mPropertiesImportant.HasPropertyAt(iHigh, iLow); nsCSSCompressedDataBlock *result = important ? result_important : result_normal; uint32_t* ip = important ? &i_important : &i_normal; nsCSSValue* val = PropertyAt(iProp); NS_ABORT_IF_FALSE(val->GetUnit() != eCSSUnit_Null, "Null value while compressing"); result->SetPropertyAtIndex(*ip, iProp); result->RawCopyValueToIndex(*ip, val); new (val) nsCSSValue(); (*ip)++; result->mStyleBits |= nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[iProp]); } } NS_ABORT_IF_FALSE(numPropsNormal == i_normal, "bad numProps"); if (result_important) { NS_ABORT_IF_FALSE(numPropsImportant == i_important, "bad numProps"); } ClearSets(); AssertInitialState(); *aNormalBlock = result_normal.forget(); *aImportantBlock = result_important.forget(); }
nsCSSExpandedDataBlock::~nsCSSExpandedDataBlock() { AssertInitialState(); }
void nsCSSExpandedDataBlock::Compress(nsCSSCompressedDataBlock **aNormalBlock, nsCSSCompressedDataBlock **aImportantBlock) { nsAutoPtr<nsCSSCompressedDataBlock> result_normal, result_important; char *cursor_normal, *cursor_important; ComputeSizeResult size = ComputeSize(); result_normal = new(size.normal) nsCSSCompressedDataBlock(); cursor_normal = result_normal->Block(); if (size.important != 0) { result_important = new(size.important) nsCSSCompressedDataBlock(); cursor_important = result_important->Block(); } else { result_important = nsnull; cursor_important = nsnull; } /* * Save needless copying and allocation by copying the memory * corresponding to the stored data in the expanded block, and then * clearing the data in the expanded block. */ for (size_t iHigh = 0; iHigh < nsCSSPropertySet::kChunkCount; ++iHigh) { if (!mPropertiesSet.HasPropertyInChunk(iHigh)) continue; for (size_t iLow = 0; iLow < nsCSSPropertySet::kBitsInChunk; ++iLow) { if (!mPropertiesSet.HasPropertyAt(iHigh, iLow)) continue; nsCSSProperty iProp = nsCSSPropertySet::CSSPropertyAt(iHigh, iLow); NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(iProp), "out of range"); bool important = mPropertiesImportant.HasPropertyAt(iHigh, iLow); char *&cursor = important ? cursor_important : cursor_normal; nsCSSCompressedDataBlock *result = important ? result_important : result_normal; nsCSSValue* val = PropertyAt(iProp); NS_ABORT_IF_FALSE(val->GetUnit() != eCSSUnit_Null, "Null value while compressing"); CDBValueStorage *storage = reinterpret_cast<CDBValueStorage*>(cursor); storage->property = iProp; memcpy(&storage->value, val, sizeof(nsCSSValue)); new (val) nsCSSValue(); cursor += CDBValueStorage_advance; result->mStyleBits |= nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[iProp]); } } result_normal->SetBlockEnd(cursor_normal); NS_ABORT_IF_FALSE(result_normal->DataSize() == ptrdiff_t(size.normal), "size miscalculation"); if (result_important) { result_important->SetBlockEnd(cursor_important); NS_ABORT_IF_FALSE(result_important->DataSize() == ptrdiff_t(size.important), "size miscalculation"); } ClearSets(); AssertInitialState(); *aNormalBlock = result_normal.forget(); *aImportantBlock = result_important.forget(); }