Title: [119097] trunk/Source/WebCore
Revision
119097
Author
[email protected]
Date
2012-05-31 06:38:47 -0700 (Thu, 31 May 2012)

Log Message

Have StylePropertySet constructor take array/length instead of vector.
<http://webkit.org/b/87876>

Reviewed by Antti Koivisto.

Remove the StylePropertyVector typedef and have StylePropertySet constructors
take CSSProperty*/length since we are copying the data into a tightly packed
array anyway. This frees up the call sites to use whatever storage they please
rather than being restricted to a vector with inlineCapacity=4.

Change said call sites to use an arbitrary high inline capacity (256) for their
stack-allocated temporary vectors.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::CSSComputedStyleDeclaration::copyPropertiesInSet):
* css/CSSParser.cpp:
(WebCore::filterProperties):
(WebCore::CSSParser::createStylePropertySet):
* css/StylePropertySet.cpp:
(WebCore::StylePropertySet::createImmutable):
(WebCore::StylePropertySet::StylePropertySet):
(WebCore::StylePropertySet::removePropertiesInSet):
(WebCore::StylePropertySet::copyPropertiesInSet):
* css/StylePropertySet.h:
(WebCore::StylePropertySet::create):
(StylePropertySet):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (119096 => 119097)


--- trunk/Source/WebCore/ChangeLog	2012-05-31 13:24:13 UTC (rev 119096)
+++ trunk/Source/WebCore/ChangeLog	2012-05-31 13:38:47 UTC (rev 119097)
@@ -1,3 +1,32 @@
+2012-05-30  Andreas Kling  <[email protected]>
+
+        Have StylePropertySet constructor take array/length instead of vector.
+        <http://webkit.org/b/87876>
+
+        Reviewed by Antti Koivisto.
+
+        Remove the StylePropertyVector typedef and have StylePropertySet constructors
+        take CSSProperty*/length since we are copying the data into a tightly packed
+        array anyway. This frees up the call sites to use whatever storage they please
+        rather than being restricted to a vector with inlineCapacity=4.
+
+        Change said call sites to use an arbitrary high inline capacity (256) for their
+        stack-allocated temporary vectors.
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::CSSComputedStyleDeclaration::copyPropertiesInSet):
+        * css/CSSParser.cpp:
+        (WebCore::filterProperties):
+        (WebCore::CSSParser::createStylePropertySet):
+        * css/StylePropertySet.cpp:
+        (WebCore::StylePropertySet::createImmutable):
+        (WebCore::StylePropertySet::StylePropertySet):
+        (WebCore::StylePropertySet::removePropertiesInSet):
+        (WebCore::StylePropertySet::copyPropertiesInSet):
+        * css/StylePropertySet.h:
+        (WebCore::StylePropertySet::create):
+        (StylePropertySet):
+
 2012-05-31  Mike West  <[email protected]>
 
         Fixing compilation with SVG disabled.

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (119096 => 119097)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2012-05-31 13:24:13 UTC (rev 119096)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2012-05-31 13:38:47 UTC (rev 119097)
@@ -2639,14 +2639,14 @@
 
 PassRefPtr<StylePropertySet> CSSComputedStyleDeclaration::copyPropertiesInSet(const CSSPropertyID* set, unsigned length) const
 {
-    StylePropertyVector list;
+    Vector<CSSProperty, 256> list;
     list.reserveInitialCapacity(length);
     for (unsigned i = 0; i < length; ++i) {
         RefPtr<CSSValue> value = getPropertyCSSValue(set[i]);
         if (value)
             list.append(CSSProperty(set[i], value.release(), false));
     }
-    return StylePropertySet::create(list);
+    return StylePropertySet::create(list.data(), list.size());
 }
 
 CSSRule* CSSComputedStyleDeclaration::parentRule() const

Modified: trunk/Source/WebCore/css/CSSParser.cpp (119096 => 119097)


--- trunk/Source/WebCore/css/CSSParser.cpp	2012-05-31 13:24:13 UTC (rev 119096)
+++ trunk/Source/WebCore/css/CSSParser.cpp	2012-05-31 13:38:47 UTC (rev 119097)
@@ -1177,7 +1177,7 @@
     return m_mediaQuery.release();
 }
 
-static inline void filterProperties(bool important, const CSSParser::ParsedPropertyVector& input, StylePropertyVector& output, size_t& unusedEntries, BitArray<numCSSProperties>& seenProperties)
+static inline void filterProperties(bool important, const CSSParser::ParsedPropertyVector& input, Vector<CSSProperty, 256>& output, size_t& unusedEntries, BitArray<numCSSProperties>& seenProperties)
 {
     // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found.
     for (int i = input.size() - 1; i >= 0; --i) {
@@ -1196,7 +1196,7 @@
 {
     BitArray<numCSSProperties> seenProperties;
     size_t unusedEntries = m_parsedProperties.size();
-    StylePropertyVector results = Vector<CSSProperty>(unusedEntries);
+    Vector<CSSProperty, 256> results(unusedEntries);
 
     // Important properties have higher priority, so add them first. Duplicate definitions can then be ignored when found.
     filterProperties(true, m_parsedProperties, results, unusedEntries, seenProperties);
@@ -1205,7 +1205,7 @@
     if (unusedEntries)
         results.remove(0, unusedEntries);
 
-    return StylePropertySet::createImmutable(results, m_context.mode);
+    return StylePropertySet::createImmutable(results.data(), results.size(), m_context.mode);
 }
 
 void CSSParser::addProperty(CSSPropertyID propId, PassRefPtr<CSSValue> value, bool important, bool implicit)

Modified: trunk/Source/WebCore/css/StylePropertySet.cpp (119096 => 119097)


--- trunk/Source/WebCore/css/StylePropertySet.cpp	2012-05-31 13:24:13 UTC (rev 119096)
+++ trunk/Source/WebCore/css/StylePropertySet.cpp	2012-05-31 13:38:47 UTC (rev 119097)
@@ -50,10 +50,10 @@
     return propertySetCSSOMWrapperMapInstance;
 }
 
-PassRefPtr<StylePropertySet> StylePropertySet::createImmutable(StylePropertyVector& properties, CSSParserMode cssParserMode)
+PassRefPtr<StylePropertySet> StylePropertySet::createImmutable(const CSSProperty* properties, unsigned count, CSSParserMode cssParserMode)
 {
-    void* slot = WTF::fastMalloc(sizeof(StylePropertySet) - sizeof(void*) + sizeof(CSSProperty) * properties.size());
-    return adoptRef(new (slot) StylePropertySet(properties, cssParserMode, /* makeMutable */ false));
+    void* slot = WTF::fastMalloc(sizeof(StylePropertySet) - sizeof(void*) + sizeof(CSSProperty) * count);
+    return adoptRef(new (slot) StylePropertySet(properties, count, cssParserMode, /* makeMutable */ false));
 }
 
 StylePropertySet::StylePropertySet(CSSParserMode cssParserMode)
@@ -65,16 +65,18 @@
 {
 }
 
-StylePropertySet::StylePropertySet(StylePropertyVector& properties, CSSParserMode cssParserMode, bool makeMutable)
+StylePropertySet::StylePropertySet(const CSSProperty* properties, unsigned count, CSSParserMode cssParserMode, bool makeMutable)
     : m_cssParserMode(cssParserMode)
     , m_ownsCSSOMWrapper(false)
     , m_isMutable(makeMutable)
 {
     if (makeMutable) {
         m_mutablePropertyVector = new Vector<CSSProperty>;
-        *m_mutablePropertyVector = properties;
+        m_mutablePropertyVector->reserveInitialCapacity(count);
+        for (unsigned i = 0; i < count; ++i)
+            m_mutablePropertyVector->uncheckedAppend(properties[i]);
     } else {
-        m_arraySize = properties.size();
+        m_arraySize = count;
         for (unsigned i = 0; i < m_arraySize; ++i)
             new (&array()[i]) CSSProperty(properties[i]);
     }
@@ -933,7 +935,7 @@
     for (unsigned i = 0; i < length; ++i)
         toRemove.add(set[i]);
 
-    StylePropertyVector newProperties;
+    Vector<CSSProperty> newProperties;
     newProperties.reserveInitialCapacity(m_mutablePropertyVector->size());
 
     unsigned size = m_mutablePropertyVector->size();
@@ -1014,14 +1016,14 @@
 
 PassRefPtr<StylePropertySet> StylePropertySet::copyPropertiesInSet(const CSSPropertyID* set, unsigned length) const
 {
-    StylePropertyVector list;
+    Vector<CSSProperty, 256> list;
     list.reserveInitialCapacity(length);
     for (unsigned i = 0; i < length; ++i) {
         RefPtr<CSSValue> value = getPropertyCSSValue(set[i]);
         if (value)
             list.append(CSSProperty(set[i], value.release(), false));
     }
-    return StylePropertySet::create(list);
+    return StylePropertySet::create(list.data(), list.size());
 }
 
 CSSStyleDeclaration* StylePropertySet::ensureCSSStyleDeclaration() const

Modified: trunk/Source/WebCore/css/StylePropertySet.h (119096 => 119097)


--- trunk/Source/WebCore/css/StylePropertySet.h	2012-05-31 13:24:13 UTC (rev 119096)
+++ trunk/Source/WebCore/css/StylePropertySet.h	2012-05-31 13:38:47 UTC (rev 119097)
@@ -39,8 +39,6 @@
 class StylePropertyShorthand;
 class StyleSheetContents;
 
-typedef Vector<CSSProperty, 4> StylePropertyVector;
-
 class StylePropertySet : public RefCounted<StylePropertySet> {
 public:
     ~StylePropertySet();
@@ -49,11 +47,11 @@
     {
         return adoptRef(new StylePropertySet(cssParserMode));
     }
-    static PassRefPtr<StylePropertySet> create(StylePropertyVector& properties)
+    static PassRefPtr<StylePropertySet> create(const CSSProperty* properties, unsigned count)
     {
-        return adoptRef(new StylePropertySet(properties, CSSStrictMode, /* makeMutable */ true));
+        return adoptRef(new StylePropertySet(properties, count, CSSStrictMode, /* makeMutable */ true));
     }
-    static PassRefPtr<StylePropertySet> createImmutable(StylePropertyVector&, CSSParserMode);
+    static PassRefPtr<StylePropertySet> createImmutable(const CSSProperty* properties, unsigned count, CSSParserMode);
 
     unsigned propertyCount() const;
     bool isEmpty() const;
@@ -119,7 +117,7 @@
     
 private:
     StylePropertySet(CSSParserMode);
-    StylePropertySet(StylePropertyVector&, CSSParserMode, bool makeMutable);
+    StylePropertySet(const CSSProperty* properties, unsigned count, CSSParserMode, bool makeMutable);
     StylePropertySet(const StylePropertySet&);
 
     void setNeedsStyleRecalc();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to