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

Side by Side Diff: Source/core/dom/ElementData.h

Issue 405923002: Introduce DEFINE_ELEMENT_DATA_TYPE_CASTS, and use it (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 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 unified diff | Download patch
« no previous file with comments | « Source/core/dom/Element.cpp ('k') | Source/core/dom/ElementData.cpp » ('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 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * Copyright (C) 2014 Apple Inc. All rights reserved. 3 * Copyright (C) 2014 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 const StylePropertySet* presentationAttributeStyle() const; 71 const StylePropertySet* presentationAttributeStyle() const;
72 72
73 AttributeCollection attributes() const; 73 AttributeCollection attributes() const;
74 74
75 bool hasID() const { return !m_idForStyleResolution.isNull(); } 75 bool hasID() const { return !m_idForStyleResolution.isNull(); }
76 bool hasClass() const { return !m_classNames.isNull(); } 76 bool hasClass() const { return !m_classNames.isNull(); }
77 77
78 bool isEquivalent(const ElementData* other) const; 78 bool isEquivalent(const ElementData* other) const;
79 79
80 bool isUnique() const { return m_isUnique; } 80 bool isUnique() const { return m_isUnique; }
81 bool isShareable() const { return !m_isUnique; }
81 82
82 void traceAfterDispatch(Visitor*); 83 void traceAfterDispatch(Visitor*);
83 void trace(Visitor*); 84 void trace(Visitor*);
84 85
85 protected: 86 protected:
86 ElementData(); 87 ElementData();
87 explicit ElementData(unsigned arraySize); 88 explicit ElementData(unsigned arraySize);
88 ElementData(const ElementData&, bool isUnique); 89 ElementData(const ElementData&, bool isUnique);
89 90
90 // Keep the type in a bitfield instead of using virtual destructors to avoid adding a vtable. 91 // Keep the type in a bitfield instead of using virtual destructors to avoid adding a vtable.
(...skipping 13 matching lines...) Expand all
104 friend class UniqueElementData; 105 friend class UniqueElementData;
105 friend class SVGElement; 106 friend class SVGElement;
106 107
107 #if !ENABLE(OILPAN) 108 #if !ENABLE(OILPAN)
108 void destroy(); 109 void destroy();
109 #endif 110 #endif
110 111
111 PassRefPtrWillBeRawPtr<UniqueElementData> makeUniqueCopy() const; 112 PassRefPtrWillBeRawPtr<UniqueElementData> makeUniqueCopy() const;
112 }; 113 };
113 114
115 #define DEFINE_ELEMENT_DATA_TYPE_CASTS(thisType, predicate) \
116 template<typename T> inline thisType* to##thisType(const RefPtr<T>& data) { return to##thisType(data.get()); } \
Inactive 2014/07/21 19:37:47 Sorry, I thought the macro was doing this for us a
gyuyoung-inactive 2014/07/22 00:20:32 I removed .get() in issue 401553002 as well. I wou
Inactive 2014/07/22 00:44:29 Ok, I see tkent's comment on the other CL, fine th
tkent 2014/07/22 00:57:12 I agree with Chris. Adding the intermediate macro
117 DEFINE_TYPE_CASTS(thisType, ElementData, data, data->predicate, data.predica te)
118
114 #if COMPILER(MSVC) 119 #if COMPILER(MSVC)
115 #pragma warning(push) 120 #pragma warning(push)
116 #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" war ning 121 #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" war ning
117 #endif 122 #endif
118 123
119 // SharableElementData is managed by ElementDataCache and is produced by 124 // SharableElementData is managed by ElementDataCache and is produced by
120 // the parser during page load for elements that have identical attributes. This 125 // the parser during page load for elements that have identical attributes. This
121 // is a memory optimization since it's very common for many elements to have 126 // is a memory optimization since it's very common for many elements to have
122 // duplicate sets of attributes (ex. the same classes). 127 // duplicate sets of attributes (ex. the same classes).
123 class ShareableElementData FINAL : public ElementData { 128 class ShareableElementData FINAL : public ElementData {
(...skipping 14 matching lines...) Expand all
138 void* operator new(std::size_t, void* location) 143 void* operator new(std::size_t, void* location)
139 { 144 {
140 return location; 145 return location;
141 } 146 }
142 147
143 AttributeCollection attributes() const; 148 AttributeCollection attributes() const;
144 149
145 Attribute m_attributeArray[0]; 150 Attribute m_attributeArray[0];
146 }; 151 };
147 152
153 DEFINE_ELEMENT_DATA_TYPE_CASTS(ShareableElementData, isShareable());
154
148 #if COMPILER(MSVC) 155 #if COMPILER(MSVC)
149 #pragma warning(pop) 156 #pragma warning(pop)
150 #endif 157 #endif
151 158
152 // UniqueElementData is created when an element needs to mutate its attributes 159 // UniqueElementData is created when an element needs to mutate its attributes
153 // or gains presentation attribute style (ex. width="10"). It does not need to 160 // or gains presentation attribute style (ex. width="10"). It does not need to
154 // be created to fill in values in the ElementData that are derived from 161 // be created to fill in values in the ElementData that are derived from
155 // attributes. For example populating the m_inlineStyle from the style attribute 162 // attributes. For example populating the m_inlineStyle from the style attribute
156 // doesn't require a UniqueElementData as all elements with the same style 163 // doesn't require a UniqueElementData as all elements with the same style
157 // attribute will have the same inline style. 164 // attribute will have the same inline style.
(...skipping 18 matching lines...) Expand all
176 void traceAfterDispatch(Visitor*); 183 void traceAfterDispatch(Visitor*);
177 184
178 // FIXME: We might want to support sharing element data for elements with 185 // FIXME: We might want to support sharing element data for elements with
179 // presentation attribute style. Lots of table cells likely have the same 186 // presentation attribute style. Lots of table cells likely have the same
180 // attributes. Most modern pages don't use presentation attributes though 187 // attributes. Most modern pages don't use presentation attributes though
181 // so this might not make sense. 188 // so this might not make sense.
182 mutable RefPtrWillBeMember<StylePropertySet> m_presentationAttributeStyle; 189 mutable RefPtrWillBeMember<StylePropertySet> m_presentationAttributeStyle;
183 Vector<Attribute, 4> m_attributeVector; 190 Vector<Attribute, 4> m_attributeVector;
184 }; 191 };
185 192
193 DEFINE_ELEMENT_DATA_TYPE_CASTS(UniqueElementData, isUnique());
194
186 #if !ENABLE(OILPAN) 195 #if !ENABLE(OILPAN)
187 inline void ElementData::deref() 196 inline void ElementData::deref()
188 { 197 {
189 if (!derefBase()) 198 if (!derefBase())
190 return; 199 return;
191 destroy(); 200 destroy();
192 } 201 }
193 #endif 202 #endif
194 203
195 inline const StylePropertySet* ElementData::presentationAttributeStyle() const 204 inline const StylePropertySet* ElementData::presentationAttributeStyle() const
196 { 205 {
197 if (!m_isUnique) 206 if (!m_isUnique)
198 return 0; 207 return 0;
199 return static_cast<const UniqueElementData*>(this)->m_presentationAttributeS tyle.get(); 208 return toUniqueElementData(this)->m_presentationAttributeStyle.get();
200 } 209 }
201 210
202 inline AttributeCollection ElementData::attributes() const 211 inline AttributeCollection ElementData::attributes() const
203 { 212 {
204 if (isUnique()) 213 if (isUnique())
205 return static_cast<const UniqueElementData*>(this)->attributes(); 214 return toUniqueElementData(this)->attributes();
206 return static_cast<const ShareableElementData*>(this)->attributes(); 215 return toShareableElementData(this)->attributes();
207 } 216 }
208 217
209 inline AttributeCollection ShareableElementData::attributes() const 218 inline AttributeCollection ShareableElementData::attributes() const
210 { 219 {
211 return AttributeCollection(m_attributeArray, m_arraySize); 220 return AttributeCollection(m_attributeArray, m_arraySize);
212 } 221 }
213 222
214 inline AttributeCollection UniqueElementData::attributes() const 223 inline AttributeCollection UniqueElementData::attributes() const
215 { 224 {
216 return AttributeCollection(m_attributeVector.data(), m_attributeVector.size( )); 225 return AttributeCollection(m_attributeVector.data(), m_attributeVector.size( ));
(...skipping 10 matching lines...) Expand all
227 } 236 }
228 237
229 inline Attribute& UniqueElementData::attributeAt(unsigned index) 238 inline Attribute& UniqueElementData::attributeAt(unsigned index)
230 { 239 {
231 return m_attributeVector.at(index); 240 return m_attributeVector.at(index);
232 } 241 }
233 242
234 } // namespace blink 243 } // namespace blink
235 244
236 #endif // ElementData_h 245 #endif // ElementData_h
OLDNEW
« no previous file with comments | « Source/core/dom/Element.cpp ('k') | Source/core/dom/ElementData.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698