Changeset 149707 in webkit
- Timestamp:
- May 7, 2013 6:47:57 PM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r149706 r149707 1 2013-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 1 35 2013-05-07 Benjamin Poulain <bpoulain@apple.com> 2 36 -
trunk/Source/WebCore/rendering/style/QuotesData.cpp
r149700 r149707 25 25 namespace WebCore { 26 26 27 static size_t sizeForQuotesDataWithQuoteCount(unsigned count) 28 { 29 return sizeof(QuotesData) + sizeof(std::pair<String, String>) * count; 30 } 31 27 32 PassRefPtr<QuotesData> QuotesData::create(const String& open1, const String& close1, const String& open2, const String& close2) 28 33 { … … 37 42 PassRefPtr<QuotesData> QuotesData::create(const Vector<std::pair<String, String> >& quotes) 38 43 { 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 } 41 47 42 return quotesData.release(); 48 QuotesData::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 55 QuotesData::~QuotesData() 56 { 57 for (unsigned i = 0; i < m_quoteCount; ++i) 58 m_quotePairs[i].~pair<String, String>(); 43 59 } 44 60 45 61 const String& QuotesData::openQuote(unsigned index) const 46 62 { 47 if (!m_quote Pairs.isEmpty())63 if (!m_quoteCount) 48 64 return emptyString(); 49 65 50 if (index >= m_quote Pairs.size())51 return m_quotePairs .last().first;66 if (index >= m_quoteCount) 67 return m_quotePairs[m_quoteCount - 1].first; 52 68 53 69 return m_quotePairs[index].first; … … 56 72 const String& QuotesData::closeQuote(unsigned index) const 57 73 { 58 if ( m_quotePairs.isEmpty())74 if (!m_quoteCount) 59 75 return emptyString(); 60 76 61 if (index >= m_quote Pairs.size())62 return m_quotePairs .last().second;77 if (index >= m_quoteCount) 78 return m_quotePairs[m_quoteCount - 1].second; 63 79 64 return m_quotePairs .at(index).second;80 return m_quotePairs[index].second; 65 81 } 66 82 67 83 bool operator==(const QuotesData& a, const QuotesData& b) 68 84 { 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; 70 94 } 71 95 -
trunk/Source/WebCore/rendering/style/QuotesData.h
r149700 r149707 30 30 namespace WebCore { 31 31 32 #if COMPILER(MSVC) 33 #pragma warning(push) 34 #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" warning 35 #endif 36 32 37 class QuotesData : public RefCounted<QuotesData> { 33 38 public: 34 39 static PassRefPtr<QuotesData> create(const String& open1, const String& close1, const String& open2, const String& close2); 35 40 static PassRefPtr<QuotesData> create(const Vector<std::pair<String, String> >& quotes); 41 ~QuotesData(); 36 42 37 43 friend bool operator==(const QuotesData&, const QuotesData&); … … 41 47 42 48 private: 43 QuotesData() { }49 explicit QuotesData(const Vector<std::pair<String, String> >& quotes); 44 50 45 Vector<std::pair<String, String> > m_quotePairs; 51 unsigned m_quoteCount; 52 std::pair<String, String> m_quotePairs[0]; 46 53 }; 54 55 #if COMPILER(MSVC) 56 #pragma warning(pop) 57 #endif 47 58 48 59 inline bool operator!=(const QuotesData& a, const QuotesData& b)
Note: See TracChangeset
for help on using the changeset viewer.