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

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

Issue 1234763007: CSSValue Immediates: Make toCSSPrimitiveValue() return a const reference (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@cssvalue_patch_3_tagged_ptrs_finally
Patch Set: Rebase 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 9f84a36b9bf1b567c16b5a5a641ccb56570fc337..30f7f6d940c0a77be6de96a4abd6ffc3c1acba49 100644
--- a/Source/core/css/CSSPrimitiveValue.h
+++ b/Source/core/css/CSSPrimitiveValue.h
@@ -190,30 +190,89 @@ public:
#endif
} packedColor;
-
// Returns true if value can be stored in the value field of the tagged pointer
// without losing information.
- inline static bool fitsWithoutDataLoss(double value)
+ inline static bool canFitWithoutDataLoss(CSSPrimitiveValueData data, UnitType type)
{
- union {
- double asDouble;
- uint64_t asBits;
- } interpretableValue;
- interpretableValue.asDouble = value;
- return (interpretableValue.asBits & mantissaTruncationMask) == 0;
+ switch (type) {
+ case CSS_PROPERTY_ID:
+ return true;
+ case CSS_VALUE_ID:
+ return true;
+ case CSS_RGBCOLOR:
+#if CPU(32BIT)
+ if (alphaChannel(data.rgbcolor) != 0 && alphaChannel(data.rgbcolor) != 255)
+ return false;
+#endif
+ return true;
+ default:
+ union {
+ double asDouble;
+ uint64_t asBits;
+ } interpretableValue;
+ interpretableValue.asDouble = data.num;
+ if ((interpretableValue.asBits & mantissaTruncationMask) != 0)
+ return false;
+ return true;
+ }
}
- inline static bool fitsWithoutDataLoss(RGBA32 color)
+ inline void setValue(CSSPrimitiveValueData data, UnitType type)
{
+ this->flag = 1;
+ this->type = static_cast<uintptr_t>(type);
+ switch (type) {
+ case CSS_PROPERTY_ID:
+ valueRaw = static_cast<uintptr_t>(data.propertyID);
+ return;
+ case CSS_VALUE_ID:
+ valueRaw = static_cast<uintptr_t>(data.valueID);
+ return;
+ case CSS_RGBCOLOR:
+ packedColor color;
+ color.red = static_cast<uintptr_t>(redChannel(data.rgbcolor));
+ color.green = static_cast<uintptr_t>(greenChannel(data.rgbcolor));
+ color.blue = static_cast<uintptr_t>(blueChannel(data.rgbcolor));
#if CPU(32BIT)
- return alphaChannel(color) == 0 || alphaChannel(color) == 255;
+ color.alpha = static_cast<uintptr_t>(alphaChannel(data.rgbcolor) == 255 ? 1 : 0);
#elif CPU(64BIT)
- return true;
+ color.alpha = static_cast<uintptr_t>(alphaChannel(data.rgbcolor));
#endif
+ valueRaw = *reinterpret_cast<uintptr_t*>(&color);
+ return;
+ default:
+ union {
+ double asDouble;
+ uint64_t asBits;
+ } interpretableValue;
+ interpretableValue.asDouble = data.num;
+ valueRaw = interpretableValue.asBits >> doubleShiftAmount;
+ return;
+ }
+ }
+
+ inline CSSPrimitiveValueData getValue() const
+ {
+ CSSPrimitiveValueData data;
+ switch (type) {
+ case CSS_PROPERTY_ID:
+ data.propertyID = getPropertyIDValue();
+ break;
+ case CSS_VALUE_ID:
+ data.valueID = getValueIDValue();
+ break;
+ case CSS_RGBCOLOR:
+ data.rgbcolor = getColorValue();
+ break;
+ default:
+ data.num = getDoubleValue();
+ break;
+ }
+ return data;
}
// Convenience methods for getting/setting the value field, which is truncated.
- inline double getValue() const
+ inline double getDoubleValue() const
{
uint64_t shiftedValue = valueRaw;
shiftedValue = shiftedValue << doubleShiftAmount;
@@ -432,40 +491,40 @@ public:
static CSSPrimitiveValue createIdentifier(CSSValueID valueID)
{
- CSSTaggedPtrValue taggedPointer;
- taggedPointer.flag = 1;
- taggedPointer.type = CSS_VALUE_ID;
- taggedPointer.setValue(valueID);
- return CSSPrimitiveValue(taggedPointer);
+ CSSPrimitiveValueData data;
+ data.valueID = valueID;
+ CSSTaggedPtrValue taggedPtr;
+ taggedPtr.setValue(data, CSS_VALUE_ID);
+ return CSSPrimitiveValue(taggedPtr);
}
static CSSPrimitiveValue createIdentifier(CSSPropertyID propertyID)
{
- CSSTaggedPtrValue taggedPointer;
- taggedPointer.flag = 1;
- taggedPointer.type = CSS_PROPERTY_ID;
- taggedPointer.setValue(propertyID);
- return CSSPrimitiveValue(taggedPointer);
+ CSSPrimitiveValueData data;
+ data.propertyID = propertyID;
+ CSSTaggedPtrValue taggedPtr;
+ taggedPtr.setValue(data, CSS_PROPERTY_ID);
+ return CSSPrimitiveValue(taggedPtr);
}
static CSSPrimitiveValue createColor(RGBA32 rgbValue)
{
- if (CSSTaggedPtrValue::fitsWithoutDataLoss(rgbValue)) {
- CSSTaggedPtrValue taggedPointer;
- taggedPointer.flag = 1;
- taggedPointer.type = CSS_RGBCOLOR;
- taggedPointer.setValue(rgbValue);
- return CSSPrimitiveValue(taggedPointer);
+ CSSPrimitiveValueData data;
+ data.rgbcolor = rgbValue;
+ if (CSSTaggedPtrValue::canFitWithoutDataLoss(data, CSS_RGBCOLOR)) {
+ CSSTaggedPtrValue taggedPtr;
+ taggedPtr.setValue(data, CSS_RGBCOLOR);
+ return CSSPrimitiveValue(taggedPtr);
}
return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(rgbValue)));
}
static CSSPrimitiveValue create(double value, UnitType type)
{
- if (CSSTaggedPtrValue::fitsWithoutDataLoss(value)) {
- CSSTaggedPtrValue taggedPointer;
- taggedPointer.flag = 1;
- taggedPointer.type = type;
- taggedPointer.setValue(value);
- return CSSPrimitiveValue(taggedPointer);
+ CSSPrimitiveValueData data;
+ data.num = value;
+ if (CSSTaggedPtrValue::canFitWithoutDataLoss(data, type)) {
+ CSSTaggedPtrValue taggedPtr;
+ taggedPtr.setValue(data, type);
+ return CSSPrimitiveValue(taggedPtr);
}
return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(value, type)));
}
@@ -498,13 +557,13 @@ public:
UnitType primitiveType() const;
double computeDegrees() const;
- double computeSeconds();
+ double computeSeconds() const;
// Computes a length in pixels, resolving relative lengths
- template<typename T> T computeLength(const CSSToLengthConversionData&);
+ template<typename T> T computeLength(const CSSToLengthConversionData&) const;
// Converts to a Length (Fixed, Percent or Calculated)
- Length convertToLength(const CSSToLengthConversionData&);
+ Length convertToLength(const CSSToLengthConversionData&) const;
double getDoubleValue() const;
float getFloatValue() const { return getValue<float>(); }
@@ -579,7 +638,7 @@ private:
static void create(unsigned); // compile-time guard
template<typename T> operator T*(); // compile-time guard
- double computeLengthDouble(const CSSToLengthConversionData&);
+ double computeLengthDouble(const CSSToLengthConversionData&) const;
union CSSPrimitivePointerValue {
CSSTaggedPtrValue asTaggedPtr;
@@ -609,16 +668,8 @@ private:
if (isObject())
return m_rawValue.asPtr->m_value;
- CSSPrimitiveValueData result;
- if (m_rawValue.asTaggedPtr.type == CSS_RGBCOLOR)
- result.rgbcolor = m_rawValue.asTaggedPtr.getColorValue();
- else if (m_rawValue.asTaggedPtr.type == CSS_PROPERTY_ID)
- result.propertyID = m_rawValue.asTaggedPtr.getPropertyIDValue();
- else if (m_rawValue.asTaggedPtr.type == CSS_VALUE_ID)
- result.valueID = m_rawValue.asTaggedPtr.getValueIDValue();
- else
- result.num = m_rawValue.asTaggedPtr.getValue();
- return result;
+
+ return m_rawValue.asTaggedPtr.getValue();
}
UnitType type() const
« 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