Fix accounting showing leak of CSS value types, and optimize CSS value constructors/destructors a bit. b=382027 r+sr=bzbarsky a1.9=roc

This commit is contained in:
dbaron@dbaron.org 2007-08-27 23:47:32 -07:00
Родитель bb16753e08
Коммит 058bdab0e5
3 изменённых файлов: 45 добавлений и 25 удалений

Просмотреть файл

@ -615,23 +615,42 @@ nsCSSExpandedDataBlock::DoExpand(nsCSSCompressedDataBlock *aBlock,
switch (nsCSSProps::kTypeTable[iProp]) { switch (nsCSSProps::kTypeTable[iProp]) {
case eCSSType_Value: { case eCSSType_Value: {
const nsCSSValue* val = ValueAtCursor(cursor); const nsCSSValue* val = ValueAtCursor(cursor);
nsCSSValue* dest = static_cast<nsCSSValue*>(prop);
NS_ASSERTION(val->GetUnit() != eCSSUnit_Null, "oops"); NS_ASSERTION(val->GetUnit() != eCSSUnit_Null, "oops");
memcpy(prop, val, sizeof(nsCSSValue)); NS_ASSERTION(dest->GetUnit() == eCSSUnit_Null,
"expanding into non-empty block");
#ifdef NS_BUILD_REFCNT_LOGGING
dest->~nsCSSValue();
#endif
memcpy(dest, val, sizeof(nsCSSValue));
cursor += CDBValueStorage_advance; cursor += CDBValueStorage_advance;
} break; } break;
case eCSSType_Rect: { case eCSSType_Rect: {
const nsCSSRect* val = RectAtCursor(cursor); const nsCSSRect* val = RectAtCursor(cursor);
nsCSSRect* dest = static_cast<nsCSSRect*>(prop);
NS_ASSERTION(val->HasValue(), "oops"); NS_ASSERTION(val->HasValue(), "oops");
memcpy(prop, val, sizeof(nsCSSRect)); NS_ASSERTION(!dest->HasValue(),
"expanding into non-empty block");
#ifdef NS_BUILD_REFCNT_LOGGING
dest->~nsCSSRect();
#endif
memcpy(dest, val, sizeof(nsCSSRect));
cursor += CDBRectStorage_advance; cursor += CDBRectStorage_advance;
} break; } break;
case eCSSType_ValuePair: { case eCSSType_ValuePair: {
const nsCSSValuePair* val = ValuePairAtCursor(cursor); const nsCSSValuePair* val = ValuePairAtCursor(cursor);
nsCSSValuePair* dest = static_cast<nsCSSValuePair*>(prop);
NS_ASSERTION(val->mXValue.GetUnit() != eCSSUnit_Null || NS_ASSERTION(val->mXValue.GetUnit() != eCSSUnit_Null ||
val->mYValue.GetUnit() != eCSSUnit_Null, "oops"); val->mYValue.GetUnit() != eCSSUnit_Null, "oops");
memcpy(prop, val, sizeof(nsCSSValuePair)); NS_ASSERTION(dest->mXValue.GetUnit() == eCSSUnit_Null &&
dest->mYValue.GetUnit() == eCSSUnit_Null,
"expanding into non-empty block");
#ifdef NS_BUILD_REFCNT_LOGGING
dest->~nsCSSValuePair();
#endif
memcpy(dest, val, sizeof(nsCSSValuePair));
cursor += CDBValuePairStorage_advance; cursor += CDBValuePairStorage_advance;
} break; } break;
@ -639,8 +658,10 @@ nsCSSExpandedDataBlock::DoExpand(nsCSSCompressedDataBlock *aBlock,
case eCSSType_CounterData: case eCSSType_CounterData:
case eCSSType_Quotes: { case eCSSType_Quotes: {
void* val = PointerAtCursor(cursor); void* val = PointerAtCursor(cursor);
void** dest = static_cast<void**>(prop);
NS_ASSERTION(val, "oops"); NS_ASSERTION(val, "oops");
*static_cast<void**>(prop) = val; NS_ASSERTION(!*dest, "expanding into non-empty block");
*dest = val;
cursor += CDBPointerStorage_advance; cursor += CDBPointerStorage_advance;
} break; } break;
} }

Просмотреть файл

@ -154,11 +154,6 @@ nsCSSValue::nsCSSValue(const nsCSSValue& aCopy)
} }
} }
nsCSSValue::~nsCSSValue()
{
Reset();
}
nsCSSValue& nsCSSValue::operator=(const nsCSSValue& aCopy) nsCSSValue& nsCSSValue::operator=(const nsCSSValue& aCopy)
{ {
if (this != &aCopy) { if (this != &aCopy) {
@ -241,6 +236,20 @@ nscoord nsCSSValue::GetLengthTwips() const
return 0; return 0;
} }
void nsCSSValue::DoReset()
{
if (eCSSUnit_String <= mUnit && mUnit <= eCSSUnit_Attr) {
mValue.mString->Release();
} else if (eCSSUnit_Array <= mUnit && mUnit <= eCSSUnit_Counters) {
mValue.mArray->Release();
} else if (eCSSUnit_URL == mUnit) {
mValue.mURL->Release();
} else if (eCSSUnit_Image == mUnit) {
mValue.mImage->Release();
}
mUnit = eCSSUnit_Null;
}
void nsCSSValue::SetIntValue(PRInt32 aValue, nsCSSUnit aUnit) void nsCSSValue::SetIntValue(PRInt32 aValue, nsCSSUnit aUnit)
{ {
NS_ASSERTION((eCSSUnit_Integer == aUnit) || NS_ASSERTION((eCSSUnit_Integer == aUnit) ||

Просмотреть файл

@ -137,10 +137,6 @@ public:
: mUnit(aUnit) : mUnit(aUnit)
{ {
NS_ASSERTION(aUnit <= eCSSUnit_System_Font, "not a valueless unit"); NS_ASSERTION(aUnit <= eCSSUnit_System_Font, "not a valueless unit");
if (aUnit > eCSSUnit_System_Font) {
mUnit = eCSSUnit_Null;
}
mValue.mInt = 0;
} }
nsCSSValue(PRInt32 aValue, nsCSSUnit aUnit) NS_HIDDEN; nsCSSValue(PRInt32 aValue, nsCSSUnit aUnit) NS_HIDDEN;
@ -151,7 +147,7 @@ public:
explicit nsCSSValue(URL* aValue) NS_HIDDEN; explicit nsCSSValue(URL* aValue) NS_HIDDEN;
explicit nsCSSValue(Image* aValue) NS_HIDDEN; explicit nsCSSValue(Image* aValue) NS_HIDDEN;
nsCSSValue(const nsCSSValue& aCopy) NS_HIDDEN; nsCSSValue(const nsCSSValue& aCopy) NS_HIDDEN;
NS_CONSTRUCTOR_FASTCALL ~nsCSSValue() NS_HIDDEN; ~nsCSSValue() { Reset(); }
NS_HIDDEN_(nsCSSValue&) operator=(const nsCSSValue& aCopy); NS_HIDDEN_(nsCSSValue&) operator=(const nsCSSValue& aCopy);
NS_HIDDEN_(PRBool) operator==(const nsCSSValue& aOther) const; NS_HIDDEN_(PRBool) operator==(const nsCSSValue& aOther) const;
@ -258,19 +254,13 @@ public:
NS_HIDDEN_(void) Reset() // sets to null NS_HIDDEN_(void) Reset() // sets to null
{ {
if (eCSSUnit_String <= mUnit && mUnit <= eCSSUnit_Attr) { if (mUnit != eCSSUnit_Null)
mValue.mString->Release(); DoReset();
} else if (eCSSUnit_Array <= mUnit && mUnit <= eCSSUnit_Counters) {
mValue.mArray->Release();
} else if (eCSSUnit_URL == mUnit) {
mValue.mURL->Release();
} else if (eCSSUnit_Image == mUnit) {
mValue.mImage->Release();
}
mUnit = eCSSUnit_Null;
mValue.mInt = 0;
} }
private:
NS_HIDDEN_(void) DoReset();
public:
NS_HIDDEN_(void) SetIntValue(PRInt32 aValue, nsCSSUnit aUnit); NS_HIDDEN_(void) SetIntValue(PRInt32 aValue, nsCSSUnit aUnit);
NS_HIDDEN_(void) SetPercentValue(float aValue); NS_HIDDEN_(void) SetPercentValue(float aValue);
NS_HIDDEN_(void) SetFloatValue(float aValue, nsCSSUnit aUnit); NS_HIDDEN_(void) SetFloatValue(float aValue, nsCSSUnit aUnit);