Changeset 143726 in webkit


Ignore:
Timestamp:
Feb 22, 2013 6:39:42 AM (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 and a default constructor for Attribute.

  • dom/Attribute.cpp:

(WebCore::Attribute::Attribute):

  • 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:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r143724 r143726  
     12013-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
    1252013-02-22  Andreas Kling  <akling@apple.com>
    226
  • trunk/Source/WebCore/dom/Attribute.h

    r141570 r143726  
    7070    }
    7171
     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
    7278private:
    7379    QualifiedName m_name;
  • trunk/Source/WebCore/dom/DocumentSharedObjectPool.cpp

    r143054 r143726  
    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

    r143114 r143726  
    28972897static size_t sizeForShareableElementDataWithAttributeCount(unsigned count)
    28982898{
    2899     return sizeof(ShareableElementData) - sizeof(void*) + sizeof(Attribute) * count;
     2899    return sizeof(ShareableElementData) + sizeof(Attribute) * count;
    29002900}
    29012901
     
    29152915{
    29162916    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]);
    29182918}
    29192919
     
    29212921{
    29222922    for (unsigned i = 0; i < m_arraySize; ++i)
    2923         (reinterpret_cast<Attribute*>(&m_attributeArray)[i]).~Attribute();
     2923        m_attributeArray[i].~Attribute();
    29242924}
    29252925
     
    29352935
    29362936    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));
    29382938}
    29392939
     
    29732973    m_attributeVector.reserveCapacity(other.length());
    29742974    for (unsigned i = 0; i < other.length(); ++i)
    2975         m_attributeVector.uncheckedAppend(other.immutableAttributeArray()[i]);
     2975        m_attributeVector.uncheckedAppend(other.m_attributeArray[i]);
    29762976}
    29772977
  • trunk/Source/WebCore/dom/Element.h

    r143724 r143726  
    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 {
     
    10001007    if (m_isUnique)
    10011008        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];
    10031010}
    10041011
Note: See TracChangeset for help on using the changeset viewer.