Title: [149707] trunk/Source/WebCore
- Revision
- 149707
- Author
- [email protected]
- Date
- 2013-05-07 18:47:57 -0700 (Tue, 07 May 2013)
Log 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:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (149706 => 149707)
--- trunk/Source/WebCore/ChangeLog 2013-05-08 01:42:59 UTC (rev 149706)
+++ trunk/Source/WebCore/ChangeLog 2013-05-08 01:47:57 UTC (rev 149707)
@@ -1,3 +1,37 @@
+2013-05-07 Anders Carlsson <[email protected]>
+
+ 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:
+
2013-05-07 Benjamin Poulain <[email protected]>
We should not ref() the RefPtr twice in CanvasStyle
Modified: trunk/Source/WebCore/rendering/style/QuotesData.cpp (149706 => 149707)
--- trunk/Source/WebCore/rendering/style/QuotesData.cpp 2013-05-08 01:42:59 UTC (rev 149706)
+++ trunk/Source/WebCore/rendering/style/QuotesData.cpp 2013-05-08 01:47:57 UTC (rev 149707)
@@ -24,6 +24,11 @@
namespace WebCore {
+static size_t sizeForQuotesDataWithQuoteCount(unsigned count)
+{
+ return sizeof(QuotesData) + sizeof(std::pair<String, String>) * count;
+}
+
PassRefPtr<QuotesData> QuotesData::create(const String& open1, const String& close1, const String& open2, const String& close2)
{
Vector<std::pair<String, String> > quotes;
@@ -36,37 +41,56 @@
PassRefPtr<QuotesData> QuotesData::create(const Vector<std::pair<String, String> >& quotes)
{
- RefPtr<QuotesData> quotesData = adoptRef(new QuotesData);
- quotesData->m_quotePairs = quotes;
+ void* slot = fastMalloc(sizeForQuotesDataWithQuoteCount(quotes.size()));
+ return adoptRef(new (NotNull, slot) QuotesData(quotes));
+}
- return quotesData.release();
+QuotesData::QuotesData(const Vector<std::pair<String, String> >& quotes)
+ : m_quoteCount(quotes.size())
+{
+ for (unsigned i = 0; i < m_quoteCount; ++i)
+ new (NotNull, &m_quotePairs[i]) std::pair<String, String>(quotes[i]);
}
+QuotesData::~QuotesData()
+{
+ for (unsigned i = 0; i < m_quoteCount; ++i)
+ m_quotePairs[i].~pair<String, String>();
+}
+
const String& QuotesData::openQuote(unsigned index) const
{
- if (!m_quotePairs.isEmpty())
+ if (!m_quoteCount)
return emptyString();
- if (index >= m_quotePairs.size())
- return m_quotePairs.last().first;
+ if (index >= m_quoteCount)
+ return m_quotePairs[m_quoteCount - 1].first;
return m_quotePairs[index].first;
}
const String& QuotesData::closeQuote(unsigned index) const
{
- if (m_quotePairs.isEmpty())
+ if (!m_quoteCount)
return emptyString();
- if (index >= m_quotePairs.size())
- return m_quotePairs.last().second;
+ if (index >= m_quoteCount)
+ return m_quotePairs[m_quoteCount - 1].second;
- return m_quotePairs.at(index).second;
+ return m_quotePairs[index].second;
}
bool operator==(const QuotesData& a, const QuotesData& b)
{
- return a.m_quotePairs == b.m_quotePairs;
+ if (a.m_quoteCount != b.m_quoteCount)
+ return false;
+
+ for (unsigned i = 0; i < a.m_quoteCount; ++i) {
+ if (a.m_quotePairs[i] != b.m_quotePairs[i])
+ return false;
+ }
+
+ return true;
}
} // namespace WebCore
Modified: trunk/Source/WebCore/rendering/style/QuotesData.h (149706 => 149707)
--- trunk/Source/WebCore/rendering/style/QuotesData.h 2013-05-08 01:42:59 UTC (rev 149706)
+++ trunk/Source/WebCore/rendering/style/QuotesData.h 2013-05-08 01:47:57 UTC (rev 149707)
@@ -29,10 +29,16 @@
namespace WebCore {
+#if COMPILER(MSVC)
+#pragma warning(push)
+#pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" warning
+#endif
+
class QuotesData : public RefCounted<QuotesData> {
public:
static PassRefPtr<QuotesData> create(const String& open1, const String& close1, const String& open2, const String& close2);
static PassRefPtr<QuotesData> create(const Vector<std::pair<String, String> >& quotes);
+ ~QuotesData();
friend bool operator==(const QuotesData&, const QuotesData&);
@@ -40,11 +46,16 @@
const String& closeQuote(unsigned index) const;
private:
- QuotesData() { }
+ explicit QuotesData(const Vector<std::pair<String, String> >& quotes);
- Vector<std::pair<String, String> > m_quotePairs;
+ unsigned m_quoteCount;
+ std::pair<String, String> m_quotePairs[0];
};
+#if COMPILER(MSVC)
+#pragma warning(pop)
+#endif
+
inline bool operator!=(const QuotesData& a, const QuotesData& b)
{
return !(a == b);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes