Depend on assignment and copy construction of unions in nsStyleCoord. (Bug 730240) r=bzbarsky
authorL. David Baron <dbaron@dbaron.org>
Fri, 24 Feb 2012 21:23:14 -0800
changeset 87708 350d812f93b9f80acf7a497c87eb692acd5cf91d
parent 87704 73a29259b8d8e8c47f094e349db67890768659ab
child 87709 b958923e04baf46fc6ae15bc57e4bc983d1113f4
push id22143
push userphilringnalda@gmail.com
push dateSun, 26 Feb 2012 23:12:35 +0000
treeherdermozilla-central@b98fc24ac54b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs730240
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Depend on assignment and copy construction of unions in nsStyleCoord. (Bug 730240) r=bzbarsky
layout/style/nsStyleCoord.cpp
layout/style/nsStyleCoord.h
--- a/layout/style/nsStyleCoord.cpp
+++ b/layout/style/nsStyleCoord.cpp
@@ -77,34 +77,16 @@ nsStyleCoord::nsStyleCoord(float aValue,
   if (aUnit < eStyleUnit_Percent || aUnit >= eStyleUnit_Coord) {
     NS_NOTREACHED("not a float value");
     Reset();
   } else {
     mValue.mFloat = aValue;
   }
 }
 
-// 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) {
     return false;
   }
   switch (mUnit) {
     case eStyleUnit_Null:
     case eStyleUnit_Normal:
--- a/layout/style/nsStyleCoord.h
+++ b/layout/style/nsStyleCoord.h
@@ -106,17 +106,22 @@ public:
   nsStyleCoord(nsStyleUnit aUnit = eStyleUnit_Null);
   enum CoordConstructorType { CoordConstructor };
   inline nsStyleCoord(nscoord aValue, CoordConstructorType);
   nsStyleCoord(PRInt32 aValue, nsStyleUnit aUnit);
   nsStyleCoord(float aValue, nsStyleUnit aUnit);
   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;
 
   nsStyleUnit GetUnit() const {
     NS_ASSERTION(mUnit != eStyleUnit_Null, "reading uninitialized value");
     return mUnit;
   }
 
@@ -268,19 +273,18 @@ inline nsStyleCoord::nsStyleCoord(const 
     mValue.mPointer = aCopy.mValue.mPointer;
   }
   else {
     mValue.mInt = aCopy.mValue.mInt;
   }
 }
 
 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
 {
   return !((*this) == aOther);
 }
 
 inline PRInt32 nsStyleCoord::GetCoordValue() const
@@ -338,17 +342,17 @@ inline nsStyleCoord::Calc* nsStyleCoord:
     return static_cast<Calc*>(mValue.mPointer);
   }
   return nsnull;
 }
 
 
 inline void nsStyleCoord::GetUnionValue(nsStyleUnion& aValue) const
 {
-  memcpy(&aValue, &mValue, sizeof(nsStyleUnion));
+  aValue = mValue;
 }
 
 // -------------------------
 // nsStyleSides inlines
 //
 inline bool nsStyleSides::operator!=(const nsStyleSides& aOther) const
 {
   return !((*this) == aOther);