Changeset 143726 in webkit
- Timestamp:
- Feb 22, 2013 6:39:42 AM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r143724 r143726 1 2013-02-22 Andreas Kling <akling@apple.com> 2 3 ShareableElementData should use zero-length array for storage. 4 <http://webkit.org/b/109959> 5 6 Reviewed by Anders Carlsson. 7 8 Use a zero-length Attribute array instead of always casting from void* to an array. 9 It was done this way originally because I didn't know we could sidestep the MSVC 10 build error with some #pragma hackery and a default constructor for Attribute. 11 12 * dom/Attribute.cpp: 13 (WebCore::Attribute::Attribute): 14 * dom/DocumentSharedObjectPool.cpp: 15 (WebCore::DocumentSharedObjectPool::cachedShareableElementDataWithAttributes): 16 * dom/Element.cpp: 17 (WebCore::sizeForShareableElementDataWithAttributeCount): 18 (WebCore::ShareableElementData::ShareableElementData): 19 (WebCore::ShareableElementData::~ShareableElementData): 20 (WebCore::UniqueElementData::UniqueElementData): 21 * dom/Element.h: 22 (ShareableElementData): 23 (WebCore::ElementData::attributeItem): 24 1 25 2013-02-22 Andreas Kling <akling@apple.com> 2 26 -
trunk/Source/WebCore/dom/Attribute.h
r141570 r143726 70 70 } 71 71 72 #if COMPILER(MSVC) 73 // NOTE: This constructor is not actually implemented, it's just defined so MSVC 74 // will let us use a zero-length array of Attributes. 75 Attribute(); 76 #endif 77 72 78 private: 73 79 QualifiedName m_name; -
trunk/Source/WebCore/dom/DocumentSharedObjectPool.cpp
r143054 r143726 87 87 return elementData.release(); 88 88 89 cacheIterator->value = adoptPtr(new ShareableElementDataCacheEntry(ShareableElementDataCacheKey(elementData-> immutableAttributeArray(), elementData->length()), elementData));89 cacheIterator->value = adoptPtr(new ShareableElementDataCacheEntry(ShareableElementDataCacheKey(elementData->m_attributeArray, elementData->length()), elementData)); 90 90 91 91 return elementData.release(); -
trunk/Source/WebCore/dom/Element.cpp
r143114 r143726 2897 2897 static size_t sizeForShareableElementDataWithAttributeCount(unsigned count) 2898 2898 { 2899 return sizeof(ShareableElementData) - sizeof(void*)+ sizeof(Attribute) * count;2899 return sizeof(ShareableElementData) + sizeof(Attribute) * count; 2900 2900 } 2901 2901 … … 2915 2915 { 2916 2916 for (unsigned i = 0; i < m_arraySize; ++i) 2917 new (& reinterpret_cast<Attribute*>(&m_attributeArray)[i]) Attribute(attributes[i]);2917 new (&m_attributeArray[i]) Attribute(attributes[i]); 2918 2918 } 2919 2919 … … 2921 2921 { 2922 2922 for (unsigned i = 0; i < m_arraySize; ++i) 2923 (reinterpret_cast<Attribute*>(&m_attributeArray)[i]).~Attribute();2923 m_attributeArray[i].~Attribute(); 2924 2924 } 2925 2925 … … 2935 2935 2936 2936 for (unsigned i = 0; i < m_arraySize; ++i) 2937 new (& reinterpret_cast<Attribute*>(&m_attributeArray)[i]) Attribute(other.m_attributeVector.at(i));2937 new (&m_attributeArray[i]) Attribute(other.m_attributeVector.at(i)); 2938 2938 } 2939 2939 … … 2973 2973 m_attributeVector.reserveCapacity(other.length()); 2974 2974 for (unsigned i = 0; i < other.length(); ++i) 2975 m_attributeVector.uncheckedAppend(other. immutableAttributeArray()[i]);2975 m_attributeVector.uncheckedAppend(other.m_attributeArray[i]); 2976 2976 } 2977 2977 -
trunk/Source/WebCore/dom/Element.h
r143724 r143726 120 120 }; 121 121 122 #if COMPILER(MSVC) 123 #pragma warning(push) 124 #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" warning 125 #endif 126 122 127 class ShareableElementData : public ElementData { 123 128 public: 124 129 static PassRefPtr<ShareableElementData> createWithAttributes(const Vector<Attribute>&); 125 130 126 const Attribute* immutableAttributeArray() const { return reinterpret_cast<const Attribute*>(&m_attributeArray); }127 128 131 explicit ShareableElementData(const Vector<Attribute>&); 129 132 explicit ShareableElementData(const UniqueElementData&); 130 133 ~ShareableElementData(); 131 134 132 void* m_attributeArray;135 Attribute m_attributeArray[0]; 133 136 }; 137 138 #if COMPILER(MSVC) 139 #pragma warning(pop) 140 #endif 134 141 135 142 class UniqueElementData : public ElementData { … … 1000 1007 if (m_isUnique) 1001 1008 return &static_cast<const UniqueElementData*>(this)->m_attributeVector.at(index); 1002 return &static_cast<const ShareableElementData*>(this)-> immutableAttributeArray()[index];1009 return &static_cast<const ShareableElementData*>(this)->m_attributeArray[index]; 1003 1010 } 1004 1011
Note: See TracChangeset
for help on using the changeset viewer.