Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(488)

Unified Diff: Source/core/css/CSSPrimitiveValue.h

Issue 1265903002: CSSValue Immediates: Remove redundant isTaggedPtr() checks (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@tagged_ptrs_base
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/core/css/CSSPrimitiveValue.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/CSSPrimitiveValue.h
diff --git a/Source/core/css/CSSPrimitiveValue.h b/Source/core/css/CSSPrimitiveValue.h
index 1820b226d24c511e3c90c80db830cb3cfecda590..c589c4f9b3d50b9345a8e45c77244ccbe54c4ee0 100644
--- a/Source/core/css/CSSPrimitiveValue.h
+++ b/Source/core/css/CSSPrimitiveValue.h
@@ -181,20 +181,22 @@ public:
bool isAngle() const
{
- return type() == CSS_DEG
- || type() == CSS_RAD
- || type() == CSS_GRAD
- || type() == CSS_TURN;
+ UnitType unitType = type();
+ return unitType == CSS_DEG
+ || unitType == CSS_RAD
+ || unitType == CSS_GRAD
+ || unitType == CSS_TURN;
}
bool isAttr() const { return type() == CSS_ATTR; }
bool isCounter() const { return type() == CSS_COUNTER; }
bool isCustomIdent() const { return type() == CSS_CUSTOM_IDENT; }
bool isFontRelativeLength() const
{
- return type() == CSS_EMS
- || type() == CSS_EXS
- || type() == CSS_REMS
- || type() == CSS_CHS;
+ UnitType unitType = type();
+ return unitType == CSS_EMS
+ || unitType == CSS_EXS
+ || unitType == CSS_REMS
+ || unitType == CSS_CHS;
}
bool isViewportPercentageLength() const { return isViewportPercentageLength(type()); }
static bool isViewportPercentageLength(UnitType type) { return type >= CSS_VW && type <= CSS_VMAX; }
@@ -210,7 +212,7 @@ public:
bool isRGBColor() const { return type() == CSS_RGBCOLOR; }
bool isShape() const { return type() == CSS_SHAPE; }
bool isString() const { return type() == CSS_STRING; }
- bool isTime() const { return type() == CSS_S || type() == CSS_MS; }
+ bool isTime() const { UnitType unitType = type(); return unitType == CSS_S || unitType == CSS_MS; }
bool isURI() const { return type() == CSS_URI; }
bool isCalculated() const { return type() == CSS_CALC; }
bool isCalculatedPercentageWithNumber() const { return primitiveType() == CSS_CALC_PERCENTAGE_WITH_NUMBER; }
@@ -323,9 +325,11 @@ public:
double getDoubleValue() const
{
- if (type() == CSS_CALC)
+ if (isTaggedPtr())
+ return numTaggedValue();
+ if (m_primitiveUnitType == CSS_CALC)
return getCalcDoubleValue();
- return value().num;
+ return m_value.num;
}
double getCalcDoubleValue() const;
@@ -336,22 +340,38 @@ public:
String getStringValue() const;
- Counter* getCounterValue() const { return type() != CSS_COUNTER ? 0 : value().counter; }
+ Counter* getCounterValue() const { return type() != CSS_COUNTER ? 0 : m_value.counter; }
- Rect* getRectValue() const { return type() != CSS_RECT ? 0 : value().rect; }
+ Rect* getRectValue() const { return type() != CSS_RECT ? 0 : m_value.rect; }
- Quad* getQuadValue() const { return type() != CSS_QUAD ? 0 : value().quad; }
+ Quad* getQuadValue() const { return type() != CSS_QUAD ? 0 : m_value.quad; }
- RGBA32 getRGBA32Value() const { return type() != CSS_RGBCOLOR ? 0 : value().rgbcolor; }
+ RGBA32 getRGBA32Value() const
+ {
+ if (isTaggedPtr())
+ return taggedType() != CSS_RGBCOLOR ? 0 : rgbcolorTaggedValue();
+ return m_primitiveUnitType != CSS_RGBCOLOR ? 0 : m_value.rgbcolor;
+ }
- Pair* getPairValue() const { return type() != CSS_PAIR ? 0 : value().pair; }
+ Pair* getPairValue() const { return type() != CSS_PAIR ? 0 : m_value.pair; }
- CSSBasicShape* getShapeValue() const { return type() != CSS_SHAPE ? 0 : value().shape; }
+ CSSBasicShape* getShapeValue() const { return type() != CSS_SHAPE ? 0 : m_value.shape; }
- CSSCalcValue* cssCalcValue() const { return type() != CSS_CALC ? 0 : value().calc; }
+ CSSCalcValue* cssCalcValue() const { return type() != CSS_CALC ? 0 : m_value.calc; }
- CSSPropertyID getPropertyID() const { return type() == CSS_PROPERTY_ID ? value().propertyID : CSSPropertyInvalid; }
- CSSValueID getValueID() const { return type() == CSS_VALUE_ID ? value().valueID : CSSValueInvalid; }
+ CSSPropertyID getPropertyID() const
+ {
+ if (isTaggedPtr())
+ return taggedType() == CSS_PROPERTY_ID ? propertyIDTaggedValue() : CSSPropertyInvalid;
+ return m_primitiveUnitType == CSS_PROPERTY_ID ? m_value.propertyID : CSSPropertyInvalid;
+ }
+
+ CSSValueID getValueID() const
+ {
+ if (isTaggedPtr())
+ return taggedType() == CSS_VALUE_ID ? valueIDTaggedValue() : CSSValueInvalid;
+ return m_primitiveUnitType == CSS_VALUE_ID ? m_value.valueID : CSSValueInvalid;
+ }
template<typename T> inline operator T() const; // Defined in CSSPrimitiveValueMappings.h
@@ -458,40 +478,77 @@ private:
return static_cast<UnitType>(toTaggedPtr().type);
}
- inline CSSPrimitiveValueData value() const
+ inline double taggedType() const
{
- if (!isTaggedPtr())
- return m_value;
-
- CSSPrimitiveValueData data;
- switch (type()) {
- case CSSPrimitiveValue::CSS_PROPERTY_ID:
- data.propertyID = static_cast<CSSPropertyID>(toTaggedPtr().value);
- break;
- case CSSPrimitiveValue::CSS_VALUE_ID:
- data.valueID = static_cast<CSSValueID>(toTaggedPtr().value);
- break;
- case CSSPrimitiveValue::CSS_RGBCOLOR: {
- uintptr_t valueRawVar = toTaggedPtr().value;
- packedColor color = *reinterpret_cast<packedColor*>(&valueRawVar);
- unsigned alpha;
+ ASSERT(isTaggedPtr());
+ return static_cast<UnitType>(toTaggedPtr().type);
+ }
+
+ inline CSSPropertyID propertyIDValue() const
+ {
+ if (isTaggedPtr())
+ return propertyIDTaggedValue();
+ return m_value.propertyID;
+ }
+
+ inline CSSValueID valueIDValue() const
+ {
+ if (isTaggedPtr())
+ return valueIDTaggedValue();
+ return m_value.valueID;
+ }
+
+
+ inline double numValue() const
+ {
+ if (isTaggedPtr())
+ return numTaggedValue();
+ return m_value.num;
+ }
+
+
+ inline RGBA32 rgbcolorValue() const
+ {
+ if (isTaggedPtr())
+ return rgbcolorTaggedValue();
+ return m_value.rgbcolor;
+ }
+
+ inline CSSPropertyID propertyIDTaggedValue() const
+ {
+ ASSERT(isTaggedPtr());
+ return static_cast<CSSPropertyID>(toTaggedPtr().value);
+ }
+
+ inline CSSValueID valueIDTaggedValue() const
+ {
+ ASSERT(isTaggedPtr());
+ return static_cast<CSSValueID>(toTaggedPtr().value);
+ }
+
+ inline double numTaggedValue() const
+ {
+ ASSERT(isTaggedPtr());
+ uint64_t shiftedValue = toTaggedPtr().value;
+ shiftedValue = shiftedValue << doubleShiftAmount;
+ return *reinterpret_cast<double*>(&shiftedValue);
+ }
+
+ inline RGBA32 rgbcolorTaggedValue() const
+ {
+ ASSERT(isTaggedPtr());
+ uintptr_t valueRawVar = toTaggedPtr().value;
+ packedColor color = *reinterpret_cast<packedColor*>(&valueRawVar);
+ unsigned alpha;
#if CPU(32BIT)
- alpha = color.alpha == 1 ? 255 : 0;
+ alpha = color.alpha == 1 ? 255 : 0;
#elif CPU(64BIT)
- alpha = color.alpha;
+ alpha = color.alpha;
#endif
- data.rgbcolor = makeRGBA(color.red, color.green, color.blue, alpha);
- break;
- }
- default:
- uint64_t shiftedValue = toTaggedPtr().value;
- shiftedValue = shiftedValue << doubleShiftAmount;
- data.num = *reinterpret_cast<double*>(&shiftedValue);
- break;
- }
- return data;
+ return makeRGBA(color.red, color.green, color.blue, alpha);
}
+
CSSPrimitiveValueData m_value;
};
« no previous file with comments | « no previous file | Source/core/css/CSSPrimitiveValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698