Changeset 149700 in webkit


Ignore:
Timestamp:
May 7, 2013 4:07:14 PM (11 years ago)
Author:
andersca@apple.com
Message:

Begin unraveling the mess that is QuotesData
https://bugs.webkit.org/show_bug.cgi?id=115765

Reviewed by Andreas Kling.

Change QuotesData to be an immutable object and fix other things that are broken.

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::applyProperty):
QuotesData::addPair is gone. Instead, create the Vector up front and pass it to QuotesData.

  • rendering/RenderQuote.cpp:

(WebCore::RenderQuote::originalText):
Update for renames.

  • rendering/style/QuotesData.cpp:

(WebCore::QuotesData::create):
Remove the create overload that wasn't used. Add a new create overload that takes a Vector.

(WebCore::QuotesData::openQuote):
Rename this from getOpenQuote and clean it up.

(WebCore::QuotesData::closeQuote):
Rename this from getCloseQuote and clean it up.

(WebCore::operator==):
Replace the equals member function with a proper equality operator.

  • rendering/style/RenderStyle.cpp:

(WebCore::RenderStyle::diff):
Stop calling QuotesData::equals. Use the same idiom as used for other properties.

(WebCore::RenderStyle::setQuotes):

  • rendering/style/StyleRareInheritedData.cpp:

Use operator==.

(WebCore::quotesDataEquivalent):
Add helper function.

(WebCore::StyleRareInheritedData::operator==):
Call quotesDataEquivalent.

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r149698 r149700  
     12013-05-07  Anders Carlsson  <andersca@apple.com>
     2
     3        Begin unraveling the mess that is QuotesData
     4        https://bugs.webkit.org/show_bug.cgi?id=115765
     5
     6        Reviewed by Andreas Kling.
     7
     8        Change QuotesData to be an immutable object and fix other things that are broken.
     9
     10        * css/StyleResolver.cpp:
     11        (WebCore::StyleResolver::applyProperty):
     12        QuotesData::addPair is gone. Instead, create the Vector up front and pass it to QuotesData.
     13
     14        * rendering/RenderQuote.cpp:
     15        (WebCore::RenderQuote::originalText):
     16        Update for renames.
     17
     18        * rendering/style/QuotesData.cpp:
     19        (WebCore::QuotesData::create):
     20        Remove the create overload that wasn't used. Add a new create overload that takes a Vector.
     21
     22        (WebCore::QuotesData::openQuote):
     23        Rename this from getOpenQuote and clean it up.
     24
     25        (WebCore::QuotesData::closeQuote):
     26        Rename this from getCloseQuote and clean it up.
     27
     28        (WebCore::operator==):
     29        Replace the equals member function with a proper equality operator.
     30
     31        * rendering/style/RenderStyle.cpp:
     32        (WebCore::RenderStyle::diff):
     33        Stop calling QuotesData::equals. Use the same idiom as used for other properties.
     34
     35        (WebCore::RenderStyle::setQuotes):
     36        * rendering/style/StyleRareInheritedData.cpp:
     37        Use operator==.
     38
     39        (WebCore::quotesDataEquivalent):
     40        Add helper function.
     41
     42        (WebCore::StyleRareInheritedData::operator==):
     43        Call quotesDataEquivalent.
     44
    1452013-05-06  Enrica Casucci  <enrica@apple.com>
    246
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r149665 r149700  
    23572357        if (value->isValueList()) {
    23582358            CSSValueList* list = static_cast<CSSValueList*>(value);
    2359             RefPtr<QuotesData> quotes = QuotesData::create();
     2359            Vector<std::pair<String, String> > quotes;
    23602360            for (size_t i = 0; i < list->length(); i += 2) {
    23612361                CSSValue* first = list->itemWithoutBoundsCheck(i);
     
    23682368                String startQuote = static_cast<CSSPrimitiveValue*>(first)->getStringValue();
    23692369                String endQuote = static_cast<CSSPrimitiveValue*>(second)->getStringValue();
    2370                 quotes->addPair(std::make_pair(startQuote, endQuote));
     2370                quotes.append(std::make_pair(startQuote, endQuote));
    23712371            }
    2372             state.style()->setQuotes(quotes);
     2372            state.style()->setQuotes(QuotesData::create(quotes));
    23732373            return;
    23742374        }
    23752375        if (primitiveValue) {
    23762376            if (primitiveValue->getIdent() == CSSValueNone)
    2377                 state.style()->setQuotes(QuotesData::create());
     2377                state.style()->setQuotes(QuotesData::create(Vector<std::pair<String, String> >()));
    23782378        }
    23792379        return;
  • trunk/Source/WebCore/rendering/RenderQuote.cpp

    r143380 r149700  
    241241        return StringImpl::empty();
    242242    case CLOSE_QUOTE:
    243         return quotesData()->getCloseQuote(m_depth - 1).impl();
     243        return quotesData()->closeQuote(m_depth - 1).impl();
    244244    case OPEN_QUOTE:
    245         return quotesData()->getOpenQuote(m_depth).impl();
     245        return quotesData()->openQuote(m_depth).impl();
    246246    }
    247247    ASSERT_NOT_REACHED();
  • trunk/Source/WebCore/rendering/style/QuotesData.cpp

    r149080 r149700  
    2525namespace WebCore {
    2626
    27 PassRefPtr<QuotesData> QuotesData::create(String open, String close)
     27PassRefPtr<QuotesData> QuotesData::create(const String& open1, const String& close1, const String& open2, const String& close2)
    2828{
    29     RefPtr<QuotesData> data = QuotesData::create();
    30     data->addPair(std::make_pair(open, close));
    31     return data;
     29    Vector<std::pair<String, String> > quotes;
     30    quotes.reserveInitialCapacity(2);
     31    quotes.uncheckedAppend(std::make_pair(open1, close1));
     32    quotes.uncheckedAppend(std::make_pair(open2, close2));
     33
     34    return QuotesData::create(quotes);
    3235}
    3336
    34 PassRefPtr<QuotesData> QuotesData::create(String open1, String close1, String open2, String close2)
     37PassRefPtr<QuotesData> QuotesData::create(const Vector<std::pair<String, String> >& quotes)
    3538{
    36     RefPtr<QuotesData> data = QuotesData::create();
    37     data->addPair(std::make_pair(open1, close1));
    38     data->addPair(std::make_pair(open2, close2));
    39     return data;
     39    RefPtr<QuotesData> quotesData = adoptRef(new QuotesData);
     40    quotesData->m_quotePairs = quotes;
     41
     42    return quotesData.release();
    4043}
    4144
    42 void QuotesData::addPair(const std::pair<String, String>& quotePair)
     45const String& QuotesData::openQuote(unsigned index) const
    4346{
    44     m_quotePairs.append(quotePair);
     47    if (!m_quotePairs.isEmpty())
     48        return emptyString();
     49
     50    if (index >= m_quotePairs.size())
     51        return m_quotePairs.last().first;
     52
     53    return m_quotePairs[index].first;
    4554}
    4655
    47 const String QuotesData::getOpenQuote(int index) const
     56const String& QuotesData::closeQuote(unsigned index) const
    4857{
    49     ASSERT(index >= 0);
    50     if (!m_quotePairs.size() || index < 0)
     58    if (m_quotePairs.isEmpty())
    5159        return emptyString();
    52     if ((size_t)index >= m_quotePairs.size())
    53         return m_quotePairs.last().first;
    54     return m_quotePairs.at(index).first;
    55 }
    5660
    57 const String QuotesData::getCloseQuote(int index) const
    58 {
    59     ASSERT(index >= -1);
    60     if (!m_quotePairs.size() || index < 0)
    61         return emptyString();
    62     if ((size_t)index >= m_quotePairs.size())
     61    if (index >= m_quotePairs.size())
    6362        return m_quotePairs.last().second;
     63
    6464    return m_quotePairs.at(index).second;
    6565}
    6666
    67 bool QuotesData::equals(const QuotesData* a, const QuotesData* b)
     67bool operator==(const QuotesData& a, const QuotesData& b)
    6868{
    69     if (a == b)
    70         return true;
    71     if (!a || !b)
    72         return false;
    73     return a->m_quotePairs == b->m_quotePairs;
     69    return a.m_quotePairs == b.m_quotePairs;
    7470}
    7571
  • trunk/Source/WebCore/rendering/style/QuotesData.h

    r149080 r149700  
    3232class QuotesData : public RefCounted<QuotesData> {
    3333public:
    34     static PassRefPtr<QuotesData> create() { return adoptRef(new QuotesData()); }
    35     static PassRefPtr<QuotesData> create(const String open, const String close);
    36     static PassRefPtr<QuotesData> create(const String open1, const String close1, const String open2, const String close2);
     34    static PassRefPtr<QuotesData> create(const String& open1, const String& close1, const String& open2, const String& close2);
     35    static PassRefPtr<QuotesData> create(const Vector<std::pair<String, String> >& quotes);
    3736
    38     // FIXME: this should be an operator==.
    39     static bool equals(const QuotesData*, const QuotesData*);
     37    friend bool operator==(const QuotesData&, const QuotesData&);
    4038
    41     void addPair(const std::pair<String, String>& quotePair);
    42     const String getOpenQuote(int index) const;
    43     const String getCloseQuote(int index) const;
     39    const String& openQuote(unsigned index) const;
     40    const String& closeQuote(unsigned index) const;
    4441
    4542private:
     
    4946};
    5047
     48inline bool operator!=(const QuotesData& a, const QuotesData& b)
     49{
     50    return !(a == b);
     51}
     52
    5153} // namespace WebCore
    5254
  • trunk/Source/WebCore/rendering/style/RenderStyle.cpp

    r148921 r149700  
    614614    }
    615615
    616     if (!QuotesData::equals(rareInheritedData->quotes.get(), other->rareInheritedData->quotes.get()))
     616    const QuotesData* quotesDataA = rareInheritedData->quotes.get();
     617    const QuotesData* quotesDataB = other->rareInheritedData->quotes.get();
     618    if (!(quotesDataA == quotesDataB || (quotesDataA && quotesDataB && *quotesDataA == *quotesDataB)))
    617619        return StyleDifferenceLayout;
    618620
     
    751753void RenderStyle::setQuotes(PassRefPtr<QuotesData> q)
    752754{
    753     if (QuotesData::equals(rareInheritedData->quotes.get(), q.get()))
    754         return;
     755    if (rareInheritedData->quotes == q || (rareInheritedData->quotes && q && *rareInheritedData->quotes == *q))
     756        return;
     757
    755758    rareInheritedData.access()->quotes = q;
    756759}
  • trunk/Source/WebCore/rendering/style/StyleRareInheritedData.cpp

    r148921 r149700  
    218218}
    219219
     220static bool quotesDataEquivalent(const QuotesData* q1, const QuotesData* q2)
     221{
     222    if (q1 == q2)
     223        return true;
     224    if ((!q1 && q2) || (q1 && !q2))
     225        return false;
     226    return (*q1 == *q2);
     227}
     228
    220229bool StyleRareInheritedData::operator==(const StyleRareInheritedData& o) const
    221230{
     
    268277        && locale == o.locale
    269278        && textEmphasisCustomMark == o.textEmphasisCustomMark
    270         && QuotesData::equals(quotes.get(), o.quotes.get())
     279        && quotesDataEquivalent(quotes.get(), o.quotes.get())
    271280        && m_tabSize == o.m_tabSize
    272281        && m_lineGrid == o.m_lineGrid
Note: See TracChangeset for help on using the changeset viewer.