From e7fab38387df0f99f8bdee20c79c9c1517fd5fb9 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Thu, 5 May 2016 16:33:45 -0700 Subject: [PATCH] Bug 1270515 - Avoid synthesizing temporary nsStyleCoords in nsStyleSides::ConvertsToLength. r=dbaron --- layout/style/nsStyleCoord.h | 18 ++++++++++++++---- layout/style/nsStyleStruct.h | 4 ---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/layout/style/nsStyleCoord.h b/layout/style/nsStyleCoord.h index 986b3aa95bca..70a13e948842 100644 --- a/layout/style/nsStyleCoord.h +++ b/layout/style/nsStyleCoord.h @@ -174,9 +174,14 @@ public: (IsCalcUnit() && CalcHasPercent()); } + static bool ConvertsToLength(const nsStyleUnit aUnit, + const nsStyleUnion aValue) { + return aUnit == eStyleUnit_Coord || + (IsCalcUnit(aUnit) && !AsCalcValue(aValue)->mHasPercent); + } + bool ConvertsToLength() const { - return mUnit == eStyleUnit_Coord || - (IsCalcUnit() && !CalcHasPercent()); + return ConvertsToLength(mUnit, mValue); } nscoord ToLength() const { @@ -188,6 +193,11 @@ public: return GetCalcValue()->ToLength(); } + // Callers must verify IsCalcUnit before calling this function. + static Calc* AsCalcValue(nsStyleUnion aValue) { + return static_cast(aValue.mPointer); + } + nscoord GetCoordValue() const; int32_t GetIntValue() const; float GetPercentValue() const; @@ -292,7 +302,7 @@ public: bool ConvertsToLength() const { NS_FOR_CSS_SIDES(side) { - if (!Get(side).ConvertsToLength()) { + if (!nsStyleCoord::ConvertsToLength(mUnits[side], mValues[side])) { return false; } } @@ -435,7 +445,7 @@ inline nsStyleCoord::Calc* nsStyleCoord::GetCalcValue() const { NS_ASSERTION(IsCalcUnit(), "not a pointer value"); if (IsCalcUnit()) { - return static_cast(mValue.mPointer); + return AsCalcValue(mValue); } return nullptr; } diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index bb6b526e8636..8be0a332c26a 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -824,10 +824,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleMargin nsStyleSides mMargin; // [reset] coord, percent, calc, auto - bool IsWidthDependent() const { - return !mMargin.ConvertsToLength(); - } - bool GetMargin(nsMargin& aMargin) const { if (mMargin.ConvertsToLength()) {