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

Side by Side Diff: Source/core/css/CSSValue.h

Issue 1226273002: CSSValue Immediates: Make CSSPrimitiveValue store a tagged pointer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@cssvalue_patch_2_attempt_2
Patch Set: Rebase Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « Source/core/css/CSSPrimitiveValueTest.cpp ('k') | Source/core/css/CSSValueObject.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 23 matching lines...) Expand all
34 // CSSValueObject. 34 // CSSValueObject.
35 class CORE_EXPORT CSSValue { 35 class CORE_EXPORT CSSValue {
36 ALLOW_ONLY_INLINE_ALLOCATION(); 36 ALLOW_ONLY_INLINE_ALLOCATION();
37 friend class NullableCSSValue; 37 friend class NullableCSSValue;
38 public: 38 public:
39 // Not explicit to allow for casting. 39 // Not explicit to allow for casting.
40 CSSValue(const CSSValueObject& cssValueObject) 40 CSSValue(const CSSValueObject& cssValueObject)
41 : m_data(const_cast<CSSValueObject*>(&cssValueObject)) 41 : m_data(const_cast<CSSValueObject*>(&cssValueObject))
42 { 42 {
43 ASSERT(m_data); 43 ASSERT(m_data);
44 ASSERT(isObject());
44 ref(); 45 ref();
45 } 46 }
46 47
47 // TODO(sashab): Remove these; construction should only be available with 48 // TODO(sashab): Remove these; construction should only be available with
48 // CSSValueObject&. 49 // CSSValueObject&.
49 template<class T> CSSValue(PassRefPtrWillBeRawPtr<T> cssValueObject) 50 template<class T> CSSValue(PassRefPtrWillBeRawPtr<T> cssValueObject)
50 : m_data(cssValueObject.leakRef()) 51 : m_data(cssValueObject.leakRef())
51 { 52 {
52 static_assert(WTF::IsSubclass<T, CSSValueObject>::value, "Parameter must be a container for CSSValueObject"); 53 static_assert(WTF::IsSubclass<T, CSSValueObject>::value, "Parameter must be a container for CSSValueObject");
54 ASSERT(isObject());
53 ASSERT(m_data); 55 ASSERT(m_data);
54 } 56 }
55 57
56 #if !ENABLE(OILPAN) 58 #if !ENABLE(OILPAN)
57 template<class T> CSSValue(RefPtrWillBeRawPtr<T> cssValueObject) 59 template<class T> CSSValue(RefPtrWillBeRawPtr<T> cssValueObject)
58 : m_data(cssValueObject.release().leakRef()) 60 : m_data(cssValueObject.release().leakRef())
59 { 61 {
60 static_assert(WTF::IsSubclass<T, CSSValueObject>::value, "Parameter must be a container for CSSValueObject"); 62 static_assert(WTF::IsSubclass<T, CSSValueObject>::value, "Parameter must be a container for CSSValueObject");
63 ASSERT(isObject());
61 ASSERT(m_data); 64 ASSERT(m_data);
62 } 65 }
63 #endif 66 #endif
64 67
65 CSSValue(const CSSValue& cssValue) 68 CSSValue(const CSSValue& cssValue)
66 : m_data(cssValue.m_data) 69 : m_data(cssValue.m_data)
67 { 70 {
68 ref(); 71 ref();
69 } 72 }
70 73
(...skipping 12 matching lines...) Expand all
83 CSSValue& operator=(const CSSValue& rhs) 86 CSSValue& operator=(const CSSValue& rhs)
84 { 87 {
85 rhs.ref(); 88 rhs.ref();
86 deref(); 89 deref();
87 m_data = rhs.m_data; 90 m_data = rhs.m_data;
88 return *this; 91 return *this;
89 } 92 }
90 93
91 bool operator==(const CSSValue& other) const 94 bool operator==(const CSSValue& other) const
92 { 95 {
96 if (m_data == other.m_data)
97 return true;
98 if (!isObject() || !other.isObject())
99 return false;
93 return m_data->equals(*other.m_data); 100 return m_data->equals(*other.m_data);
94 } 101 }
95 102
96 // TODO: Remove this and update callsites to use operator== instead. 103 // TODO: Remove this and update callsites to use operator== instead.
97 bool equals(const CSSValue& other) const 104 bool equals(const CSSValue& other) const
98 { 105 {
106 if (m_data == other.m_data)
107 return true;
108 if (!isObject() || !other.isObject())
109 return false;
99 return m_data->equals(*other.m_data); 110 return m_data->equals(*other.m_data);
100 } 111 }
101 112
102 bool ptrEquals(const CSSValue& other) const 113 bool ptrEquals(const CSSValue& other) const
103 { 114 {
104 return m_data == other.m_data; 115 return m_data == other.m_data;
105 } 116 }
106 117
107 // Methods that proxy to CSSValueObject. 118 // Methods that proxy to CSSValueObject.
108 String cssText() const { return m_data->cssText(); } 119 String cssText() const
109 bool hasFailedOrCanceledSubresources() const { return m_data->hasFailedOrCan celedSubresources(); }; 120 {
110 bool isPrimitiveValue() const { return m_data->isPrimitiveValue(); } 121 if (isObject())
111 bool isValueList() const { return m_data->isValueList(); } 122 return m_data->cssText();
112 bool isBaseValueList() const { return m_data->isBaseValueList(); } 123 return CSSPrimitiveValue(reinterpret_cast<CSSPrimitiveValue::CSSLargePri mitiveValue*>(m_data.get())).cssText();
113 bool isBorderImageSliceValue() const { return m_data->isBorderImageSliceValu e(); } 124 }
114 bool isCanvasValue() const { return m_data->isCanvasValue(); } 125
115 bool isCursorImageValue() const { return m_data->isCursorImageValue(); } 126 bool hasFailedOrCanceledSubresources() const { return isObject() ? m_data->h asFailedOrCanceledSubresources() : false; };
116 bool isCrossfadeValue() const { return m_data->isCrossfadeValue(); } 127 bool isPrimitiveValue() const { return isObject() ? m_data->isPrimitiveValue () : true; }
117 bool isFontFeatureValue() const { return m_data->isFontFeatureValue(); } 128 bool isValueList() const { return isObject() ? m_data->isValueList() : false ; }
118 bool isFontFaceSrcValue() const { return m_data->isFontFaceSrcValue(); } 129 bool isBaseValueList() const { return isObject() ? m_data->isBaseValueList() : false; }
119 bool isFunctionValue() const { return m_data->isFunctionValue(); } 130 bool isBorderImageSliceValue() const { return isObject() ? m_data->isBorderI mageSliceValue() : false; }
120 bool isImageGeneratorValue() const { return m_data->isImageGeneratorValue(); } 131 bool isCanvasValue() const { return isObject() ? m_data->isCanvasValue() : f alse; }
121 bool isGradientValue() const { return m_data->isGradientValue(); } 132 bool isCursorImageValue() const { return isObject() ? m_data->isCursorImageV alue() : false; }
122 bool isImageSetValue() const { return m_data->isImageSetValue(); } 133 bool isCrossfadeValue() const { return isObject() ? m_data->isCrossfadeValue () : false; }
123 bool isImageValue() const { return m_data->isImageValue(); } 134 bool isFontFeatureValue() const { return isObject() ? m_data->isFontFeatureV alue(): false; }
124 bool isImplicitInitialValue() const { return m_data->isImplicitInitialValue( ); }; 135 bool isFontFaceSrcValue() const { return isObject() ? m_data->isFontFaceSrcV alue(): false; }
125 bool isInheritedValue() const { return m_data->isInheritedValue(); }; 136 bool isFunctionValue() const { return isObject() ? m_data->isFunctionValue() : false; }
126 bool isInitialValue() const { return m_data->isInitialValue(); }; 137 bool isImageGeneratorValue() const { return isObject() ? m_data->isImageGene ratorValue(): false; }
127 bool isUnsetValue() const { return m_data->isUnsetValue(); }; 138 bool isGradientValue() const { return isObject() ? m_data->isGradientValue() : false; }
128 bool isCSSWideKeyword() const { return m_data->isCSSWideKeyword(); }; 139 bool isImageSetValue() const { return isObject() ? m_data->isImageSetValue() : false; }
129 bool isLinearGradientValue() const { return m_data->isLinearGradientValue(); }; 140 bool isImageValue() const { return isObject() ? m_data->isImageValue(): fals e; }
130 bool isPathValue() const { return m_data->isPathValue(); }; 141 bool isImplicitInitialValue() const { return isObject() ? m_data->isImplicit InitialValue(): false; }
131 bool isRadialGradientValue() const { return m_data->isRadialGradientValue(); }; 142 bool isInheritedValue() const { return isObject() ? m_data->isInheritedValue (): false; }
132 bool isReflectValue() const { return m_data->isReflectValue(); }; 143 bool isInitialValue() const { return isObject() ? m_data->isInitialValue(): false; }
133 bool isShadowValue() const { return m_data->isShadowValue(); }; 144 bool isUnsetValue() const { return isObject() ? m_data->isUnsetValue(): fals e; }
134 bool isCubicBezierTimingFunctionValue() const { return m_data->isCubicBezier TimingFunctionValue(); }; 145 bool isCSSWideKeyword() const { return isObject() ? m_data->isCSSWideKeyword (): false; }
135 bool isStepsTimingFunctionValue() const { return m_data->isStepsTimingFuncti onValue(); }; 146 bool isLinearGradientValue() const { return isObject() ? m_data->isLinearGra dientValue(): false; }
136 bool isLineBoxContainValue() const { return m_data->isLineBoxContainValue(); }; 147 bool isPathValue() const { return isObject() ? m_data->isPathValue(): false; }
137 bool isCalcValue() const { return m_data->isCalcValue(); }; 148 bool isRadialGradientValue() const { return isObject() ? m_data->isRadialGra dientValue(): false; }
138 bool isGridTemplateAreasValue() const { return m_data->isGridTemplateAreasVa lue(); }; 149 bool isReflectValue() const { return isObject() ? m_data->isReflectValue(): false; }
139 bool isSVGDocumentValue() const { return m_data->isSVGDocumentValue(); }; 150 bool isShadowValue() const { return isObject() ? m_data->isShadowValue(): fa lse; }
140 bool isContentDistributionValue() const { return m_data->isContentDistributi onValue(); }; 151 bool isCubicBezierTimingFunctionValue() const { return isObject() ? m_data-> isCubicBezierTimingFunctionValue(): false; }
141 bool isUnicodeRangeValue() const { return m_data->isUnicodeRangeValue(); }; 152 bool isStepsTimingFunctionValue() const { return isObject() ? m_data->isStep sTimingFunctionValue(): false; }
142 bool isGridLineNamesValue() const { return m_data->isGridLineNamesValue(); } ; 153 bool isLineBoxContainValue() const { return isObject() ? m_data->isLineBoxCo ntainValue(): false; }
154 bool isCalcValue() const { return isObject() ? m_data->isCalcValue(): false; }
155 bool isGridTemplateAreasValue() const { return isObject() ? m_data->isGridTe mplateAreasValue(): false; }
156 bool isSVGDocumentValue() const { return isObject() ? m_data->isSVGDocumentV alue(): false; }
157 bool isContentDistributionValue() const { return isObject() ? m_data->isCont entDistributionValue(): false; }
158 bool isUnicodeRangeValue() const { return isObject() ? m_data->isUnicodeRang eValue(): false; }
159 bool isGridLineNamesValue() const { return isObject() ? m_data->isGridLineNa mesValue(): false; }
143 160
144 DEFINE_INLINE_TRACE() 161 DEFINE_INLINE_TRACE()
145 { 162 {
146 ASSERT(m_data); 163 ASSERT(m_data);
147 visitor->trace(m_data); 164 if (isObject())
165 visitor->trace(m_data);
148 } 166 }
149 167
150 // Only for use by the toFooCSSValue() macros. Don't use this. 168 // Only for use by the toFooCSSValue() macros. Don't use this.
151 // TODO(sashab): Remove this and use value.to<Type> and value.isValid<Type> 169 // TODO(sashab): Remove this and use value.to<Type> and value.isValid<Type>
152 // like WebNode. 170 // like WebNode.
153 CSSValueObject* get() const 171 CSSValueObject* get() const
154 { 172 {
155 return m_data.get(); 173 return m_data.get();
156 } 174 }
157 175
158 private: 176 private:
159 CSSValue() = delete; // compile-time guard 177 CSSValue() = delete; // compile-time guard
160 CSSValue(std::nullptr_t) = delete; // compile-time guard 178 CSSValue(std::nullptr_t) = delete; // compile-time guard
161 179
162 void ref() const 180 void ref() const
163 { 181 {
164 #if !ENABLE(OILPAN) 182 #if !ENABLE(OILPAN)
165 if (m_data) 183 if (m_data && isObject())
166 m_data->ref(); 184 m_data->ref();
167 #endif 185 #endif
168 } 186 }
169 187
170 void deref() const 188 void deref() const
171 { 189 {
172 #if !ENABLE(OILPAN) 190 #if !ENABLE(OILPAN)
173 if (m_data) 191 if (m_data && isObject())
174 m_data->deref(); 192 m_data->deref();
175 #endif 193 #endif
176 } 194 }
177 195
196 bool isObject() const
197 {
198 return !(*reinterpret_cast<const uintptr_t*>(&m_data) & 1);
199 }
200
178 RawPtrWillBeMember<CSSValueObject> m_data; 201 RawPtrWillBeMember<CSSValueObject> m_data;
179 }; 202 };
180 203
181 // A nullable container for CSSValueObject. Contents are the same as CSSValue. 204 // A nullable container for CSSValueObject. Contents are the same as CSSValue.
182 // Behavior is similar to a CSSValue*. 205 // Behavior is similar to a CSSValue*.
183 class CORE_EXPORT NullableCSSValue { 206 class CORE_EXPORT NullableCSSValue {
184 ALLOW_ONLY_INLINE_ALLOCATION(); 207 ALLOW_ONLY_INLINE_ALLOCATION();
185 public: 208 public:
186 // Not explicit to allow for casting. 209 // Not explicit to allow for casting.
187 NullableCSSValue() 210 NullableCSSValue()
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 NullableCSSValue& operator=(const NullableCSSValue& rhs) 272 NullableCSSValue& operator=(const NullableCSSValue& rhs)
250 { 273 {
251 rhs.ref(); 274 rhs.ref();
252 deref(); 275 deref();
253 m_data = rhs.m_data; 276 m_data = rhs.m_data;
254 return *this; 277 return *this;
255 } 278 }
256 279
257 bool operator==(const NullableCSSValue& rhs) const 280 bool operator==(const NullableCSSValue& rhs) const
258 { 281 {
282 if (m_data == rhs.m_data)
283 return true;
284 if (!isObject() || (rhs && !rhs.isObject()))
285 return false;
259 return m_data ? rhs.m_data && m_data->equals(*rhs.m_data) : !bool(rhs.m_ data); 286 return m_data ? rhs.m_data && m_data->equals(*rhs.m_data) : !bool(rhs.m_ data);
260 } 287 }
261 288
262 bool operator!=(const NullableCSSValue& rhs) const 289 bool operator!=(const NullableCSSValue& rhs) const
263 { 290 {
264 return !(*this == rhs); 291 return !(*this == rhs);
265 } 292 }
266 293
267 CSSValue& operator*() 294 CSSValue& operator*()
268 { 295 {
(...skipping 20 matching lines...) Expand all
289 return reinterpret_cast<const CSSValue*>(this); 316 return reinterpret_cast<const CSSValue*>(this);
290 } 317 }
291 318
292 void swap(NullableCSSValue& rhs) 319 void swap(NullableCSSValue& rhs)
293 { 320 {
294 std::swap(this->m_data, rhs.m_data); 321 std::swap(this->m_data, rhs.m_data);
295 } 322 }
296 323
297 DEFINE_INLINE_TRACE() 324 DEFINE_INLINE_TRACE()
298 { 325 {
299 visitor->trace(m_data); 326 if (isObject())
327 visitor->trace(m_data);
300 } 328 }
301 329
302 // Only for use by the toFooCSSValue() macros. Don't use this. 330 // Only for use by the toFooCSSValue() macros. Don't use this.
303 // TODO(sashab): Remove this and use value.to<Type> and value.isValid<Type> 331 // TODO(sashab): Remove this and use value.to<Type> and value.isValid<Type>
304 // like WebNode. 332 // like WebNode.
305 CSSValueObject* get() const 333 CSSValueObject* get() const
306 { 334 {
307 return m_data.get(); 335 return m_data.get();
308 } 336 }
309 337
310 private: 338 private:
311 void ref() const 339 void ref() const
312 { 340 {
313 #if !ENABLE(OILPAN) 341 #if !ENABLE(OILPAN)
314 if (m_data) 342 if (m_data && isObject())
315 m_data->ref(); 343 m_data->ref();
316 #endif 344 #endif
317 } 345 }
318 346
319 void deref() const 347 void deref() const
320 { 348 {
321 #if !ENABLE(OILPAN) 349 #if !ENABLE(OILPAN)
322 if (m_data) 350 if (m_data && isObject())
323 m_data->deref(); 351 m_data->deref();
324 #endif 352 #endif
325 } 353 }
326 354
355 bool isObject() const
356 {
357 return !(*reinterpret_cast<const uintptr_t*>(&m_data) & 1);
358 }
359
327 RawPtrWillBeMember<CSSValueObject> m_data; 360 RawPtrWillBeMember<CSSValueObject> m_data;
328 }; 361 };
329 362
330 static_assert(sizeof(CSSValue) == sizeof(void*), "CSSValue should be pointer-siz ed"); 363 static_assert(sizeof(CSSValue) == sizeof(void*), "CSSValue should be pointer-siz ed");
331 static_assert(sizeof(NullableCSSValue) == sizeof(void*), "CSSValue should be poi nter-sized"); 364 static_assert(sizeof(NullableCSSValue) == sizeof(void*), "CSSValue should be poi nter-sized");
332 static_assert(sizeof(CSSValue) == sizeof(NullableCSSValue), "Both CSSValue conta iners must contain the same data"); 365 static_assert(sizeof(CSSValue) == sizeof(NullableCSSValue), "Both CSSValue conta iners must contain the same data");
333 366
334 template<size_t inlineCapacity> 367 template<size_t inlineCapacity>
335 inline bool compareCSSValueVector(const WillBeHeapVector<CSSValue, inlineCapacit y>& firstVector, const WillBeHeapVector<CSSValue, inlineCapacity>& secondVector) 368 inline bool compareCSSValueVector(const WillBeHeapVector<CSSValue, inlineCapacit y>& firstVector, const WillBeHeapVector<CSSValue, inlineCapacity>& secondVector)
336 { 369 {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 ASSERT_WITH_SECURITY_IMPLICATION(value.isPrimitiveValue()); 402 ASSERT_WITH_SECURITY_IMPLICATION(value.isPrimitiveValue());
370 return CSSPrimitiveValue(static_cast<CSSPrimitiveValue::CSSLargePrimitiveVal ue*>(value.get())); 403 return CSSPrimitiveValue(static_cast<CSSPrimitiveValue::CSSLargePrimitiveVal ue*>(value.get()));
371 } 404 }
372 405
373 } // namespace blink 406 } // namespace blink
374 407
375 WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS(blink::CSSValue); 408 WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS(blink::CSSValue);
376 WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS(blink::NullableCSSValue); 409 WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS(blink::NullableCSSValue);
377 410
378 #endif // CSSValue_h 411 #endif // CSSValue_h
OLDNEW
« no previous file with comments | « Source/core/css/CSSPrimitiveValueTest.cpp ('k') | Source/core/css/CSSValueObject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698