Depend on assignment and copy construction of unions in nsStyleCoord. (Bug 730240) r=bzbarsky

This commit is contained in:
L. David Baron 2012-02-24 21:23:14 -08:00
parent ea13f42a2a
commit 095914432d
2 changed files with 8 additions and 22 deletions

View File

@ -82,24 +82,6 @@ nsStyleCoord::nsStyleCoord(float aValue, nsStyleUnit aUnit)
}
}
// FIXME: In C++0x we can rely on the default copy constructor since
// default copy construction is defined properly for unions. But when
// can we actually use that? (It seems to work in gcc 4.4.)
nsStyleCoord& nsStyleCoord::operator=(const nsStyleCoord& aCopy)
{
mUnit = aCopy.mUnit;
if ((eStyleUnit_Percent <= mUnit) && (mUnit < eStyleUnit_Coord)) {
mValue.mFloat = aCopy.mValue.mFloat;
}
else if (IsPointerValue()) {
mValue.mPointer = aCopy.mValue.mPointer;
}
else {
mValue.mInt = aCopy.mValue.mInt;
}
return *this;
}
bool nsStyleCoord::operator==(const nsStyleCoord& aOther) const
{
if (mUnit != aOther.mUnit) {

View File

@ -111,7 +111,12 @@ public:
inline nsStyleCoord(const nsStyleCoord& aCopy);
inline nsStyleCoord(const nsStyleUnion& aValue, nsStyleUnit aUnit);
nsStyleCoord& operator=(const nsStyleCoord& aCopy);
nsStyleCoord& operator=(const nsStyleCoord& aOther)
{
mUnit = aOther.mUnit;
mValue = aOther.mValue;
return *this;
}
bool operator==(const nsStyleCoord& aOther) const;
bool operator!=(const nsStyleCoord& aOther) const;
@ -273,9 +278,8 @@ inline nsStyleCoord::nsStyleCoord(const nsStyleCoord& aCopy)
}
inline nsStyleCoord::nsStyleCoord(const nsStyleUnion& aValue, nsStyleUnit aUnit)
: mUnit(aUnit)
: mUnit(aUnit), mValue(aValue)
{
memcpy(&mValue, &aValue, sizeof(nsStyleUnion));
}
inline bool nsStyleCoord::operator!=(const nsStyleCoord& aOther) const
@ -343,7 +347,7 @@ inline nsStyleCoord::Calc* nsStyleCoord::GetCalcValue() const
inline void nsStyleCoord::GetUnionValue(nsStyleUnion& aValue) const
{
memcpy(&aValue, &mValue, sizeof(nsStyleUnion));
aValue = mValue;
}
// -------------------------