Title: [143044] trunk/Source/WebCore
- Revision
- 143044
- Author
- akl...@apple.com
- Date
- 2013-02-15 13:30:17 -0800 (Fri, 15 Feb 2013)
Log Message
ShareableElementData should use zero-length array for storage.
<http://webkit.org/b/109959>
Reviewed by Anders Carlsson.
Use a zero-length Attribute array instead of always casting from void* to an array.
It was done this way originally because I didn't know we could sidestep the MSVC
build error with some #pragma hackery.
* dom/DocumentSharedObjectPool.cpp:
(WebCore::DocumentSharedObjectPool::cachedShareableElementDataWithAttributes):
* dom/Element.cpp:
(WebCore::sizeForShareableElementDataWithAttributeCount):
(WebCore::ShareableElementData::ShareableElementData):
(WebCore::ShareableElementData::~ShareableElementData):
(WebCore::UniqueElementData::UniqueElementData):
* dom/Element.h:
(ShareableElementData):
(WebCore::ElementData::attributeItem):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (143043 => 143044)
--- trunk/Source/WebCore/ChangeLog 2013-02-15 21:18:20 UTC (rev 143043)
+++ trunk/Source/WebCore/ChangeLog 2013-02-15 21:30:17 UTC (rev 143044)
@@ -1,3 +1,25 @@
+2013-02-15 Andreas Kling <akl...@apple.com>
+
+ ShareableElementData should use zero-length array for storage.
+ <http://webkit.org/b/109959>
+
+ Reviewed by Anders Carlsson.
+
+ Use a zero-length Attribute array instead of always casting from void* to an array.
+ It was done this way originally because I didn't know we could sidestep the MSVC
+ build error with some #pragma hackery.
+
+ * dom/DocumentSharedObjectPool.cpp:
+ (WebCore::DocumentSharedObjectPool::cachedShareableElementDataWithAttributes):
+ * dom/Element.cpp:
+ (WebCore::sizeForShareableElementDataWithAttributeCount):
+ (WebCore::ShareableElementData::ShareableElementData):
+ (WebCore::ShareableElementData::~ShareableElementData):
+ (WebCore::UniqueElementData::UniqueElementData):
+ * dom/Element.h:
+ (ShareableElementData):
+ (WebCore::ElementData::attributeItem):
+
2013-02-14 Ojan Vafai <o...@chromium.org>
Implement RenderGrid::computeIntrinsicLogicalWidths
Modified: trunk/Source/WebCore/dom/DocumentSharedObjectPool.cpp (143043 => 143044)
--- trunk/Source/WebCore/dom/DocumentSharedObjectPool.cpp 2013-02-15 21:18:20 UTC (rev 143043)
+++ trunk/Source/WebCore/dom/DocumentSharedObjectPool.cpp 2013-02-15 21:30:17 UTC (rev 143044)
@@ -86,7 +86,7 @@
if (!cacheHash || cacheIterator->value)
return elementData.release();
- cacheIterator->value = adoptPtr(new ShareableElementDataCacheEntry(ShareableElementDataCacheKey(elementData->immutableAttributeArray(), elementData->length()), elementData));
+ cacheIterator->value = adoptPtr(new ShareableElementDataCacheEntry(ShareableElementDataCacheKey(elementData->m_attributeArray, elementData->length()), elementData));
return elementData.release();
}
Modified: trunk/Source/WebCore/dom/Element.cpp (143043 => 143044)
--- trunk/Source/WebCore/dom/Element.cpp 2013-02-15 21:18:20 UTC (rev 143043)
+++ trunk/Source/WebCore/dom/Element.cpp 2013-02-15 21:30:17 UTC (rev 143044)
@@ -2863,7 +2863,7 @@
static size_t sizeForShareableElementDataWithAttributeCount(unsigned count)
{
- return sizeof(ShareableElementData) - sizeof(void*) + sizeof(Attribute) * count;
+ return sizeof(ShareableElementData) + sizeof(Attribute) * count;
}
PassRefPtr<ShareableElementData> ShareableElementData::createWithAttributes(const Vector<Attribute>& attributes)
@@ -2881,13 +2881,13 @@
: ElementData(attributes.size())
{
for (unsigned i = 0; i < m_arraySize; ++i)
- new (&reinterpret_cast<Attribute*>(&m_attributeArray)[i]) Attribute(attributes[i]);
+ new (&m_attributeArray[i]) Attribute(attributes[i]);
}
ShareableElementData::~ShareableElementData()
{
for (unsigned i = 0; i < m_arraySize; ++i)
- (reinterpret_cast<Attribute*>(&m_attributeArray)[i]).~Attribute();
+ m_attributeArray[i].~Attribute();
}
ShareableElementData::ShareableElementData(const UniqueElementData& other)
@@ -2901,7 +2901,7 @@
}
for (unsigned i = 0; i < m_arraySize; ++i)
- new (&reinterpret_cast<Attribute*>(&m_attributeArray)[i]) Attribute(other.m_attributeVector.at(i));
+ new (&m_attributeArray[i]) Attribute(other.m_attributeVector.at(i));
}
ElementData::ElementData(const ElementData& other, bool isUnique)
@@ -2939,7 +2939,7 @@
m_attributeVector.reserveCapacity(other.length());
for (unsigned i = 0; i < other.length(); ++i)
- m_attributeVector.uncheckedAppend(other.immutableAttributeArray()[i]);
+ m_attributeVector.uncheckedAppend(other.m_attributeArray[i]);
}
PassRefPtr<UniqueElementData> ElementData::makeUniqueCopy() const
Modified: trunk/Source/WebCore/dom/Element.h (143043 => 143044)
--- trunk/Source/WebCore/dom/Element.h 2013-02-15 21:18:20 UTC (rev 143043)
+++ trunk/Source/WebCore/dom/Element.h 2013-02-15 21:30:17 UTC (rev 143044)
@@ -119,19 +119,26 @@
PassRefPtr<UniqueElementData> makeUniqueCopy() const;
};
+#if COMPILER(MSVC)
+#pragma warning(push)
+#pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" warning
+#endif
+
class ShareableElementData : public ElementData {
public:
static PassRefPtr<ShareableElementData> createWithAttributes(const Vector<Attribute>&);
- const Attribute* immutableAttributeArray() const { return reinterpret_cast<const Attribute*>(&m_attributeArray); }
-
explicit ShareableElementData(const Vector<Attribute>&);
explicit ShareableElementData(const UniqueElementData&);
~ShareableElementData();
- void* m_attributeArray;
+ Attribute m_attributeArray[0];
};
+#if COMPILER(MSVC)
+#pragma warning(pop)
+#endif
+
class UniqueElementData : public ElementData {
public:
static PassRefPtr<UniqueElementData> create();
@@ -1034,7 +1041,7 @@
ASSERT_WITH_SECURITY_IMPLICATION(index < length());
if (m_isUnique)
return &static_cast<const UniqueElementData*>(this)->m_attributeVector.at(index);
- return &static_cast<const ShareableElementData*>(this)->immutableAttributeArray()[index];
+ return &static_cast<const ShareableElementData*>(this)->m_attributeArray[index];
}
} // namespace
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes