Changeset 143044 in webkit


Ignore:
Timestamp:
Feb 15, 2013 1:30:17 PM (11 years ago)
Author:
akling@apple.com
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):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r143043 r143044  
     12013-02-15  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.
     11
     12        * dom/DocumentSharedObjectPool.cpp:
     13        (WebCore::DocumentSharedObjectPool::cachedShareableElementDataWithAttributes):
     14        * dom/Element.cpp:
     15        (WebCore::sizeForShareableElementDataWithAttributeCount):
     16        (WebCore::ShareableElementData::ShareableElementData):
     17        (WebCore::ShareableElementData::~ShareableElementData):
     18        (WebCore::UniqueElementData::UniqueElementData):
     19        * dom/Element.h:
     20        (ShareableElementData):
     21        (WebCore::ElementData::attributeItem):
     22
    1232013-02-14  Ojan Vafai  <ojan@chromium.org>
    224
  • trunk/Source/WebCore/dom/DocumentSharedObjectPool.cpp

    r142826 r143044  
    8787        return elementData.release();
    8888
    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));
    9090
    9191    return elementData.release();
  • trunk/Source/WebCore/dom/Element.cpp

    r143014 r143044  
    28642864static size_t sizeForShareableElementDataWithAttributeCount(unsigned count)
    28652865{
    2866     return sizeof(ShareableElementData) - sizeof(void*) + sizeof(Attribute) * count;
     2866    return sizeof(ShareableElementData) + sizeof(Attribute) * count;
    28672867}
    28682868
     
    28822882{
    28832883    for (unsigned i = 0; i < m_arraySize; ++i)
    2884         new (&reinterpret_cast<Attribute*>(&m_attributeArray)[i]) Attribute(attributes[i]);
     2884        new (&m_attributeArray[i]) Attribute(attributes[i]);
    28852885}
    28862886
     
    28882888{
    28892889    for (unsigned i = 0; i < m_arraySize; ++i)
    2890         (reinterpret_cast<Attribute*>(&m_attributeArray)[i]).~Attribute();
     2890        m_attributeArray[i].~Attribute();
    28912891}
    28922892
     
    29022902
    29032903    for (unsigned i = 0; i < m_arraySize; ++i)
    2904         new (&reinterpret_cast<Attribute*>(&m_attributeArray)[i]) Attribute(other.m_attributeVector.at(i));
     2904        new (&m_attributeArray[i]) Attribute(other.m_attributeVector.at(i));
    29052905}
    29062906
     
    29402940    m_attributeVector.reserveCapacity(other.length());
    29412941    for (unsigned i = 0; i < other.length(); ++i)
    2942         m_attributeVector.uncheckedAppend(other.immutableAttributeArray()[i]);
     2942        m_attributeVector.uncheckedAppend(other.m_attributeArray[i]);
    29432943}
    29442944
  • trunk/Source/WebCore/dom/Element.h

    r143014 r143044  
    120120};
    121121
     122#if COMPILER(MSVC)
     123#pragma warning(push)
     124#pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" warning
     125#endif
     126
    122127class ShareableElementData : public ElementData {
    123128public:
    124129    static PassRefPtr<ShareableElementData> createWithAttributes(const Vector<Attribute>&);
    125130
    126     const Attribute* immutableAttributeArray() const { return reinterpret_cast<const Attribute*>(&m_attributeArray); }
    127 
    128131    explicit ShareableElementData(const Vector<Attribute>&);
    129132    explicit ShareableElementData(const UniqueElementData&);
    130133    ~ShareableElementData();
    131134
    132     void* m_attributeArray;
     135    Attribute m_attributeArray[0];
    133136};
     137
     138#if COMPILER(MSVC)
     139#pragma warning(pop)
     140#endif
    134141
    135142class UniqueElementData : public ElementData {
     
    10351042    if (m_isUnique)
    10361043        return &static_cast<const UniqueElementData*>(this)->m_attributeVector.at(index);
    1037     return &static_cast<const ShareableElementData*>(this)->immutableAttributeArray()[index];
     1044    return &static_cast<const ShareableElementData*>(this)->m_attributeArray[index];
    10381045}
    10391046
Note: See TracChangeset for help on using the changeset viewer.