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

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
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 friend class UniqueElementData; 104 friend class UniqueElementData;
105 friend class SVGElement; 105 friend class SVGElement;
106 106
107 #if !ENABLE(OILPAN) 107 #if !ENABLE(OILPAN)
108 void destroy(); 108 void destroy();
109 #endif 109 #endif
110 110
111 PassRefPtrWillBeRawPtr<UniqueElementData> makeUniqueCopy() const; 111 PassRefPtrWillBeRawPtr<UniqueElementData> makeUniqueCopy() const;
112 }; 112 };
113 113
114 #define DEFINE_ELEMENT_DATA_TYPE_CASTS(thisType, predicate) \
115 DEFINE_TYPE_CASTS(thisType, ElementData, data, data->isUnique() == predicate , data.isUnique() == predicate)
116
114 #if COMPILER(MSVC) 117 #if COMPILER(MSVC)
115 #pragma warning(push) 118 #pragma warning(push)
116 #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" war ning 119 #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" war ning
117 #endif 120 #endif
118 121
119 // SharableElementData is managed by ElementDataCache and is produced by 122 // SharableElementData is managed by ElementDataCache and is produced by
120 // the parser during page load for elements that have identical attributes. This 123 // 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 124 // is a memory optimization since it's very common for many elements to have
122 // duplicate sets of attributes (ex. the same classes). 125 // duplicate sets of attributes (ex. the same classes).
123 class ShareableElementData FINAL : public ElementData { 126 class ShareableElementData FINAL : public ElementData {
(...skipping 14 matching lines...) Expand all
138 void* operator new(std::size_t, void* location) 141 void* operator new(std::size_t, void* location)
139 { 142 {
140 return location; 143 return location;
141 } 144 }
142 145
143 AttributeCollection attributes() const; 146 AttributeCollection attributes() const;
144 147
145 Attribute m_attributeArray[0]; 148 Attribute m_attributeArray[0];
146 }; 149 };
147 150
151 DEFINE_ELEMENT_DATA_TYPE_CASTS(ShareableElementData, false);
Inactive 2014/07/21 12:14:00 nit: I would have introduced a "isShareable()" met
152
148 #if COMPILER(MSVC) 153 #if COMPILER(MSVC)
149 #pragma warning(pop) 154 #pragma warning(pop)
150 #endif 155 #endif
151 156
152 // UniqueElementData is created when an element needs to mutate its attributes 157 // 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 158 // 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 159 // 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 160 // attributes. For example populating the m_inlineStyle from the style attribute
156 // doesn't require a UniqueElementData as all elements with the same style 161 // doesn't require a UniqueElementData as all elements with the same style
157 // attribute will have the same inline style. 162 // attribute will have the same inline style.
(...skipping 18 matching lines...) Expand all
176 void traceAfterDispatch(Visitor*); 181 void traceAfterDispatch(Visitor*);
177 182
178 // FIXME: We might want to support sharing element data for elements with 183 // FIXME: We might want to support sharing element data for elements with
179 // presentation attribute style. Lots of table cells likely have the same 184 // presentation attribute style. Lots of table cells likely have the same
180 // attributes. Most modern pages don't use presentation attributes though 185 // attributes. Most modern pages don't use presentation attributes though
181 // so this might not make sense. 186 // so this might not make sense.
182 mutable RefPtrWillBeMember<StylePropertySet> m_presentationAttributeStyle; 187 mutable RefPtrWillBeMember<StylePropertySet> m_presentationAttributeStyle;
183 Vector<Attribute, 4> m_attributeVector; 188 Vector<Attribute, 4> m_attributeVector;
184 }; 189 };
185 190
191 DEFINE_ELEMENT_DATA_TYPE_CASTS(UniqueElementData, true);
Inactive 2014/07/21 12:14:00 ditto: s/true/isUnique
192
186 #if !ENABLE(OILPAN) 193 #if !ENABLE(OILPAN)
187 inline void ElementData::deref() 194 inline void ElementData::deref()
188 { 195 {
189 if (!derefBase()) 196 if (!derefBase())
190 return; 197 return;
191 destroy(); 198 destroy();
192 } 199 }
193 #endif 200 #endif
194 201
195 inline const StylePropertySet* ElementData::presentationAttributeStyle() const 202 inline const StylePropertySet* ElementData::presentationAttributeStyle() const
196 { 203 {
197 if (!m_isUnique) 204 if (!m_isUnique)
198 return 0; 205 return 0;
199 return static_cast<const UniqueElementData*>(this)->m_presentationAttributeS tyle.get(); 206 return toUniqueElementData(this)->m_presentationAttributeStyle.get();
200 } 207 }
201 208
202 inline AttributeCollection ElementData::attributes() const 209 inline AttributeCollection ElementData::attributes() const
203 { 210 {
204 if (isUnique()) 211 if (isUnique())
205 return static_cast<const UniqueElementData*>(this)->attributes(); 212 return toUniqueElementData(this)->attributes();
206 return static_cast<const ShareableElementData*>(this)->attributes(); 213 return toShareableElementData(this)->attributes();
207 } 214 }
208 215
209 inline AttributeCollection ShareableElementData::attributes() const 216 inline AttributeCollection ShareableElementData::attributes() const
210 { 217 {
211 return AttributeCollection(m_attributeArray, m_arraySize); 218 return AttributeCollection(m_attributeArray, m_arraySize);
212 } 219 }
213 220
214 inline AttributeCollection UniqueElementData::attributes() const 221 inline AttributeCollection UniqueElementData::attributes() const
215 { 222 {
216 return AttributeCollection(m_attributeVector.data(), m_attributeVector.size( )); 223 return AttributeCollection(m_attributeVector.data(), m_attributeVector.size( ));
(...skipping 10 matching lines...) Expand all
227 } 234 }
228 235
229 inline Attribute& UniqueElementData::attributeAt(unsigned index) 236 inline Attribute& UniqueElementData::attributeAt(unsigned index)
230 { 237 {
231 return m_attributeVector.at(index); 238 return m_attributeVector.at(index);
232 } 239 }
233 240
234 } // namespace blink 241 } // namespace blink
235 242
236 #endif // ElementData_h 243 #endif // ElementData_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698