Changeset 149707 in webkit


Ignore:
Timestamp:
May 7, 2013 6:47:57 PM (11 years ago)
Author:
andersca@apple.com
Message:

Store the quotes in the same allocation as the QuotesData object
https://bugs.webkit.org/show_bug.cgi?id=115768

Reviewed by Andreas Kling.

Since the QuotesData object is immutable we don't need a Vector to store the quote pairs,
they can just be stored after the class data.

  • rendering/style/QuotesData.cpp:

(WebCore::sizeForQuotesDataWithQuoteCount):
Helper function for computing the allocation size.

(WebCore::QuotesData::create):
Use fastMalloc + placement new.

(WebCore::QuotesData::QuotesData):
Use placement new to allocate the quote pairs.

(WebCore::QuotesData::~QuotesData):
Destroy the quote pairs.

(WebCore::QuotesData::openQuote):
Stop using Vector.

(WebCore::QuotesData::closeQuote):
Ditto.

(WebCore::operator==):
Ditto.

  • rendering/style/QuotesData.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r149706 r149707  
     12013-05-07  Anders Carlsson  <andersca@apple.com>
     2
     3        Store the quotes in the same allocation as the QuotesData object
     4        https://bugs.webkit.org/show_bug.cgi?id=115768
     5
     6        Reviewed by Andreas Kling.
     7
     8        Since the QuotesData object is immutable we don't need a Vector to store the quote pairs,
     9        they can just be stored after the class data.
     10
     11        * rendering/style/QuotesData.cpp:
     12        (WebCore::sizeForQuotesDataWithQuoteCount):
     13        Helper function for computing the allocation size.
     14
     15        (WebCore::QuotesData::create):
     16        Use fastMalloc + placement new.
     17
     18        (WebCore::QuotesData::QuotesData):
     19        Use placement new to allocate the quote pairs.
     20
     21        (WebCore::QuotesData::~QuotesData):
     22        Destroy the quote pairs.
     23
     24        (WebCore::QuotesData::openQuote):
     25        Stop using Vector.
     26
     27        (WebCore::QuotesData::closeQuote):
     28        Ditto.
     29
     30        (WebCore::operator==):
     31        Ditto.
     32
     33        * rendering/style/QuotesData.h:
     34
    1352013-05-07  Benjamin Poulain  <bpoulain@apple.com>
    236
  • trunk/Source/WebCore/rendering/style/QuotesData.cpp

    r149700 r149707  
    2525namespace WebCore {
    2626
     27static size_t sizeForQuotesDataWithQuoteCount(unsigned count)
     28{
     29    return sizeof(QuotesData) + sizeof(std::pair<String, String>) * count;
     30}
     31
    2732PassRefPtr<QuotesData> QuotesData::create(const String& open1, const String& close1, const String& open2, const String& close2)
    2833{
     
    3742PassRefPtr<QuotesData> QuotesData::create(const Vector<std::pair<String, String> >& quotes)
    3843{
    39     RefPtr<QuotesData> quotesData = adoptRef(new QuotesData);
    40     quotesData->m_quotePairs = quotes;
     44    void* slot = fastMalloc(sizeForQuotesDataWithQuoteCount(quotes.size()));
     45    return adoptRef(new (NotNull, slot) QuotesData(quotes));
     46}
    4147
    42     return quotesData.release();
     48QuotesData::QuotesData(const Vector<std::pair<String, String> >& quotes)
     49    : m_quoteCount(quotes.size())
     50{
     51    for (unsigned i = 0; i < m_quoteCount; ++i)
     52        new (NotNull, &m_quotePairs[i]) std::pair<String, String>(quotes[i]);
     53}
     54
     55QuotesData::~QuotesData()
     56{
     57    for (unsigned i = 0; i < m_quoteCount; ++i)
     58        m_quotePairs[i].~pair<String, String>();
    4359}
    4460
    4561const String& QuotesData::openQuote(unsigned index) const
    4662{
    47     if (!m_quotePairs.isEmpty())
     63    if (!m_quoteCount)
    4864        return emptyString();
    4965
    50     if (index >= m_quotePairs.size())
    51         return m_quotePairs.last().first;
     66    if (index >= m_quoteCount)
     67        return m_quotePairs[m_quoteCount - 1].first;
    5268
    5369    return m_quotePairs[index].first;
     
    5672const String& QuotesData::closeQuote(unsigned index) const
    5773{
    58     if (m_quotePairs.isEmpty())
     74    if (!m_quoteCount)
    5975        return emptyString();
    6076
    61     if (index >= m_quotePairs.size())
    62         return m_quotePairs.last().second;
     77    if (index >= m_quoteCount)
     78        return m_quotePairs[m_quoteCount - 1].second;
    6379
    64     return m_quotePairs.at(index).second;
     80    return m_quotePairs[index].second;
    6581}
    6682
    6783bool operator==(const QuotesData& a, const QuotesData& b)
    6884{
    69     return a.m_quotePairs == b.m_quotePairs;
     85    if (a.m_quoteCount != b.m_quoteCount)
     86        return false;
     87
     88    for (unsigned i = 0; i < a.m_quoteCount; ++i) {
     89        if (a.m_quotePairs[i] != b.m_quotePairs[i])
     90            return false;
     91    }
     92
     93    return true;
    7094}
    7195
  • trunk/Source/WebCore/rendering/style/QuotesData.h

    r149700 r149707  
    3030namespace WebCore {
    3131
     32#if COMPILER(MSVC)
     33#pragma warning(push)
     34#pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" warning
     35#endif
     36
    3237class QuotesData : public RefCounted<QuotesData> {
    3338public:
    3439    static PassRefPtr<QuotesData> create(const String& open1, const String& close1, const String& open2, const String& close2);
    3540    static PassRefPtr<QuotesData> create(const Vector<std::pair<String, String> >& quotes);
     41    ~QuotesData();
    3642
    3743    friend bool operator==(const QuotesData&, const QuotesData&);
     
    4147
    4248private:
    43     QuotesData() { }
     49    explicit QuotesData(const Vector<std::pair<String, String> >& quotes);
    4450
    45     Vector<std::pair<String, String> > m_quotePairs;
     51    unsigned m_quoteCount;
     52    std::pair<String, String> m_quotePairs[0];
    4653};
     54
     55#if COMPILER(MSVC)
     56#pragma warning(pop)
     57#endif
    4758
    4859inline bool operator!=(const QuotesData& a, const QuotesData& b)
Note: See TracChangeset for help on using the changeset viewer.