Title: [106258] trunk/Source/WebCore
Revision
106258
Author
an...@apple.com
Date
2012-01-30 10:52:16 -0800 (Mon, 30 Jan 2012)

Log Message

Kill CSSMutableStyleDeclarationConstIterator
https://bugs.webkit.org/show_bug.cgi?id=77342

Reviewed by Sam Weinig.

CSSMutableStyleDeclaration is an array and should be iterated using an index. This simplifies the code.

* css/CSSMutableStyleDeclaration.cpp:
(WebCore::CSSMutableStyleDeclaration::copyPropertiesFrom):
(WebCore::CSSMutableStyleDeclaration::removeProperty):
(WebCore::CSSMutableStyleDeclaration::setProperty):
(WebCore::CSSMutableStyleDeclaration::setPropertyInternal):
(WebCore::CSSMutableStyleDeclaration::parseDeclaration):
(WebCore::CSSMutableStyleDeclaration::addParsedProperties):
(WebCore::CSSMutableStyleDeclaration::addParsedProperty):
(WebCore::CSSMutableStyleDeclaration::merge):
(WebCore::CSSMutableStyleDeclaration::removePropertiesInSet):
* css/CSSMutableStyleDeclaration.h:
(WebCore):
(WebCore::CSSMutableStyleDeclaration::createForSVGFontFaceElement):
(CSSMutableStyleDeclaration):
* css/CSSStyleDeclaration.cpp:
(WebCore::CSSStyleDeclaration::CSSStyleDeclaration):
* css/CSSStyleDeclaration.h:
(CSSStyleDeclaration):
():
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::styleForKeyframe):
(WebCore::CSSStyleSelector::applyDeclaration):
* editing/EditingStyle.cpp:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (106257 => 106258)


--- trunk/Source/WebCore/ChangeLog	2012-01-30 18:51:36 UTC (rev 106257)
+++ trunk/Source/WebCore/ChangeLog	2012-01-30 18:52:16 UTC (rev 106258)
@@ -1,3 +1,36 @@
+2012-01-30  Antti Koivisto  <an...@apple.com>
+
+        Kill CSSMutableStyleDeclarationConstIterator
+        https://bugs.webkit.org/show_bug.cgi?id=77342
+
+        Reviewed by Sam Weinig.
+
+        CSSMutableStyleDeclaration is an array and should be iterated using an index. This simplifies the code.
+
+        * css/CSSMutableStyleDeclaration.cpp:
+        (WebCore::CSSMutableStyleDeclaration::copyPropertiesFrom):
+        (WebCore::CSSMutableStyleDeclaration::removeProperty):
+        (WebCore::CSSMutableStyleDeclaration::setProperty):
+        (WebCore::CSSMutableStyleDeclaration::setPropertyInternal):
+        (WebCore::CSSMutableStyleDeclaration::parseDeclaration):
+        (WebCore::CSSMutableStyleDeclaration::addParsedProperties):
+        (WebCore::CSSMutableStyleDeclaration::addParsedProperty):
+        (WebCore::CSSMutableStyleDeclaration::merge):
+        (WebCore::CSSMutableStyleDeclaration::removePropertiesInSet):
+        * css/CSSMutableStyleDeclaration.h:
+        (WebCore):
+        (WebCore::CSSMutableStyleDeclaration::createForSVGFontFaceElement):
+        (CSSMutableStyleDeclaration):
+        * css/CSSStyleDeclaration.cpp:
+        (WebCore::CSSStyleDeclaration::CSSStyleDeclaration):
+        * css/CSSStyleDeclaration.h:
+        (CSSStyleDeclaration):
+        ():
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::styleForKeyframe):
+        (WebCore::CSSStyleSelector::applyDeclaration):
+        * editing/EditingStyle.cpp:
+
 2012-01-30  Michael Saboff  <msab...@apple.com>
 
         Dromaeo tests call parseSimpleLengthValue() on 8 bit strings

Modified: trunk/Source/WebCore/css/CSSMutableStyleDeclaration.cpp (106257 => 106258)


--- trunk/Source/WebCore/css/CSSMutableStyleDeclaration.cpp	2012-01-30 18:51:36 UTC (rev 106257)
+++ trunk/Source/WebCore/css/CSSMutableStyleDeclaration.cpp	2012-01-30 18:52:16 UTC (rev 106258)
@@ -186,7 +186,6 @@
 
 void CSSMutableStyleDeclaration::copyPropertiesFrom(const CSSMutableStyleDeclaration& other)
 {
-    ASSERT(!m_iteratorCount);
     m_properties = other.m_properties;
 }
 
@@ -613,8 +612,6 @@
 
 String CSSMutableStyleDeclaration::removeProperty(int propertyID, bool notifyChanged, bool returnText)
 {
-    ASSERT(!m_iteratorCount);
-
 #if ENABLE(MUTATION_OBSERVERS)
     StyleAttributeMutationScope mutationScope(this);
 #endif
@@ -684,8 +681,6 @@
 
 bool CSSMutableStyleDeclaration::setProperty(int propertyID, const String& value, bool important, bool notifyChanged)
 {
-    ASSERT(!m_iteratorCount);
-
 #if ENABLE(MUTATION_OBSERVERS)
     StyleAttributeMutationScope mutationScope(this);
 #endif
@@ -718,8 +713,6 @@
 
 void CSSMutableStyleDeclaration::setPropertyInternal(const CSSProperty& property, CSSProperty* slot)
 {
-    ASSERT(!m_iteratorCount);
-
 #if ENABLE(MUTATION_OBSERVERS)
     StyleAttributeMutationScope mutationScope(this);
 #endif
@@ -758,8 +751,6 @@
 
 void CSSMutableStyleDeclaration::parseDeclaration(const String& styleDeclaration)
 {
-    ASSERT(!m_iteratorCount);
-
 #if ENABLE(MUTATION_OBSERVERS)
     StyleAttributeMutationScope mutationScope(this);
 #endif
@@ -777,8 +768,6 @@
 
 void CSSMutableStyleDeclaration::addParsedProperties(const CSSProperty* const* properties, int numProperties)
 {
-    ASSERT(!m_iteratorCount);
-
 #if ENABLE(MUTATION_OBSERVERS)
     StyleAttributeMutationScope mutationScope(this);
 #endif
@@ -797,8 +786,6 @@
 
 void CSSMutableStyleDeclaration::addParsedProperty(const CSSProperty& property)
 {
-    ASSERT(!m_iteratorCount);
-
 #if ENABLE(MUTATION_OBSERVERS)
     StyleAttributeMutationScope mutationScope(this);
 #endif
@@ -897,8 +884,6 @@
 
 void CSSMutableStyleDeclaration::merge(const CSSMutableStyleDeclaration* other, bool argOverridesOnConflict)
 {
-    ASSERT(!m_iteratorCount);
-
 #if ENABLE(MUTATION_OBSERVERS)
     StyleAttributeMutationScope mutationScope(this);
 #endif
@@ -971,8 +956,6 @@
 
 bool CSSMutableStyleDeclaration::removePropertiesInSet(const int* set, unsigned length, bool notifyChanged)
 {
-    ASSERT(!m_iteratorCount);
-
     if (m_properties.isEmpty())
         return false;
 

Modified: trunk/Source/WebCore/css/CSSMutableStyleDeclaration.h (106257 => 106258)


--- trunk/Source/WebCore/css/CSSMutableStyleDeclaration.h	2012-01-30 18:51:36 UTC (rev 106257)
+++ trunk/Source/WebCore/css/CSSMutableStyleDeclaration.h	2012-01-30 18:52:16 UTC (rev 106258)
@@ -33,28 +33,6 @@
 
 class StyledElement;
 
-class CSSMutableStyleDeclarationConstIterator {
-public:
-    CSSMutableStyleDeclarationConstIterator(const CSSMutableStyleDeclaration* decl, CSSProperty* current);
-    CSSMutableStyleDeclarationConstIterator(const CSSMutableStyleDeclarationConstIterator& o);
-    ~CSSMutableStyleDeclarationConstIterator();
-
-    const CSSProperty& operator*() const { return *m_current; }
-    const CSSProperty* operator->() const { return m_current; }
-
-    bool operator!=(const CSSMutableStyleDeclarationConstIterator& o) { ASSERT(m_decl == o.m_decl); return m_current != o.m_current; }
-    bool operator==(const CSSMutableStyleDeclarationConstIterator& o) { ASSERT(m_decl == o.m_decl); return m_current == o.m_current; }
-
-    CSSMutableStyleDeclarationConstIterator& operator=(const CSSMutableStyleDeclarationConstIterator& o);
-
-    CSSMutableStyleDeclarationConstIterator& operator++();
-    CSSMutableStyleDeclarationConstIterator& operator--();
-
-private:
-    const CSSMutableStyleDeclaration* m_decl;
-    CSSProperty* m_current;
-};
-
 class CSSMutableStyleDeclaration : public CSSStyleDeclaration {
 public:
     virtual ~CSSMutableStyleDeclaration();
@@ -83,17 +61,7 @@
     { 
         return adoptRef(new CSSMutableStyleDeclaration(element, false));
     }
-    
-    static bool isPropertyName(const String&);
 
-    // Used by StyledElement::copyNonAttributeProperties().
-    void copyPropertiesFrom(const CSSMutableStyleDeclaration&);
-
-    typedef CSSMutableStyleDeclarationConstIterator const_iterator;
-
-    const_iterator begin() { return const_iterator(this, m_properties.begin()); }
-    const_iterator end() { return const_iterator(this, m_properties.end()); }
-
     unsigned propertyCount() const { return m_properties.size(); }
     bool isEmpty() const { return m_properties.isEmpty(); }
     const CSSProperty& propertyAt(unsigned index) const { return m_properties[index]; }
@@ -131,7 +99,10 @@
     bool useStrictParsing() const { return m_strictParsing; }
 
     void addSubresourceStyleURLs(ListHashSet<KURL>&);
-    
+
+    // Used by StyledElement::copyNonAttributeProperties().
+    void copyPropertiesFrom(const CSSMutableStyleDeclaration&);
+
     void removeEquivalentProperties(const CSSStyleDeclaration*);
 
     PassRefPtr<CSSMutableStyleDeclaration> copyPropertiesInSet(const int* set, unsigned length) const;
@@ -190,62 +161,12 @@
 
     virtual bool cssPropertyMatches(const CSSProperty*) const;
 
-    Vector<CSSProperty>::const_iterator findPropertyWithId(int propertyId) const;
-    Vector<CSSProperty>::iterator findPropertyWithId(int propertyId);
+    const CSSProperty* findPropertyWithId(int propertyId) const;
+    CSSProperty* findPropertyWithId(int propertyId);
 
     Vector<CSSProperty, 4> m_properties;
-
-    friend class CSSMutableStyleDeclarationConstIterator;
 };
 
-inline CSSMutableStyleDeclarationConstIterator::CSSMutableStyleDeclarationConstIterator(const CSSMutableStyleDeclaration* decl, CSSProperty* current)
-: m_decl(decl)
-, m_current(current)
-{
-#ifndef NDEBUG
-    const_cast<CSSMutableStyleDeclaration*>(m_decl)->m_iteratorCount++;
-#endif
-}
-
-inline CSSMutableStyleDeclarationConstIterator::CSSMutableStyleDeclarationConstIterator(const CSSMutableStyleDeclarationConstIterator& o)
-: m_decl(o.m_decl)
-, m_current(o.m_current)
-{
-#ifndef NDEBUG
-    const_cast<CSSMutableStyleDeclaration*>(m_decl)->m_iteratorCount++;
-#endif
-}
-
-inline CSSMutableStyleDeclarationConstIterator::~CSSMutableStyleDeclarationConstIterator()
-{
-#ifndef NDEBUG
-    const_cast<CSSMutableStyleDeclaration*>(m_decl)->m_iteratorCount--;
-#endif
-}
-
-inline CSSMutableStyleDeclarationConstIterator& CSSMutableStyleDeclarationConstIterator::operator=(const CSSMutableStyleDeclarationConstIterator& o)
-{
-    m_decl = o.m_decl;
-    m_current = o.m_current;
-#ifndef NDEBUG
-    const_cast<CSSMutableStyleDeclaration*>(m_decl)->m_iteratorCount++;
-#endif
-    return *this;
-}
-
-inline CSSMutableStyleDeclarationConstIterator& CSSMutableStyleDeclarationConstIterator::operator++()
-{
-    ASSERT(m_current != const_cast<CSSMutableStyleDeclaration*>(m_decl)->m_properties.end());
-    ++m_current;
-    return *this;
-}
-
-inline CSSMutableStyleDeclarationConstIterator& CSSMutableStyleDeclarationConstIterator::operator--()
-{
-    --m_current;
-    return *this;
-}
-
 } // namespace WebCore
 
 #endif // CSSMutableStyleDeclaration_h

Modified: trunk/Source/WebCore/css/CSSStyleDeclaration.cpp (106257 => 106258)


--- trunk/Source/WebCore/css/CSSStyleDeclaration.cpp	2012-01-30 18:51:36 UTC (rev 106257)
+++ trunk/Source/WebCore/css/CSSStyleDeclaration.cpp	2012-01-30 18:52:16 UTC (rev 106258)
@@ -41,9 +41,6 @@
 
 CSSStyleDeclaration::CSSStyleDeclaration(CSSRule* parentRule)
     : m_strictParsing(!parentRule || parentRule->useStrictParsing())
-#ifndef NDEBUG
-    , m_iteratorCount(0)
-#endif
     , m_isElementStyleDeclaration(false)
     , m_isInlineStyleDeclaration(false)
     , m_parent(parentRule)
@@ -52,9 +49,6 @@
     
 CSSStyleDeclaration::CSSStyleDeclaration(StyledElement* parentElement, bool isInline)
     : m_strictParsing(false)
-#ifndef NDEBUG
-    , m_iteratorCount(0)
-#endif
     , m_isElementStyleDeclaration(true)
     , m_isInlineStyleDeclaration(isInline)
     , m_parent(parentElement)

Modified: trunk/Source/WebCore/css/CSSStyleDeclaration.h (106257 => 106258)


--- trunk/Source/WebCore/css/CSSStyleDeclaration.h	2012-01-30 18:51:36 UTC (rev 106257)
+++ trunk/Source/WebCore/css/CSSStyleDeclaration.h	2012-01-30 18:52:16 UTC (rev 106258)
@@ -89,9 +89,6 @@
 
     // CSSMutableStyleDeclaration bits:
     bool m_strictParsing : 1;
-#ifndef NDEBUG
-    unsigned m_iteratorCount : 4;
-#endif
     bool m_isElementStyleDeclaration : 1;
     bool m_isInlineStyleDeclaration : 1;
 

Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (106257 => 106258)


--- trunk/Source/WebCore/css/CSSStyleSelector.cpp	2012-01-30 18:51:36 UTC (rev 106257)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp	2012-01-30 18:52:16 UTC (rev 106258)
@@ -1394,10 +1394,10 @@
 #endif
 
     // Add all the animating properties to the keyframe.
-    if (keyframeRule->style()) {
-        CSSMutableStyleDeclaration::const_iterator end = keyframeRule->style()->end();
-        for (CSSMutableStyleDeclaration::const_iterator it = keyframeRule->style()->begin(); it != end; ++it) {
-            int property = (*it).id();
+    if (CSSMutableStyleDeclaration* styleDeclaration = keyframeRule->style()) {
+        unsigned propertyCount = styleDeclaration->propertyCount();
+        for (unsigned i = 0; i < propertyCount; ++i) {
+            int property = styleDeclaration->propertyAt(i).id();
             // Timing-function within keyframes is special, because it is not animated; it just
             // describes the timing function between this keyframe and the next.
             if (property != CSSPropertyWebkitAnimationTimingFunction)
@@ -2256,12 +2256,11 @@
 void CSSStyleSelector::applyDeclaration(CSSMutableStyleDeclaration* styleDeclaration, bool isImportant, bool inheritedOnly)
 {
     InspectorInstrumentationCookie cookie = InspectorInstrumentation::willProcessRule(document(), styleDeclaration->parentRule());
-    CSSMutableStyleDeclaration::const_iterator end = styleDeclaration->end();
-
     bool styleDeclarationInsideRegionRule = m_regionForStyling ? isInsideRegionRule(styleDeclaration) : false;
 
-    for (CSSMutableStyleDeclaration::const_iterator it = styleDeclaration->begin(); it != end; ++it) {
-        const CSSProperty& current = *it;
+    unsigned propertyCount = styleDeclaration->propertyCount();
+    for (unsigned i = 0; i < propertyCount; ++i) {
+        const CSSProperty& current = styleDeclaration->propertyAt(i);
         if (isImportant != current.isImportant())
             continue;
         if (inheritedOnly && !current.isInherited()) {

Modified: trunk/Source/WebCore/editing/EditingStyle.cpp (106257 => 106258)


--- trunk/Source/WebCore/editing/EditingStyle.cpp	2012-01-30 18:51:36 UTC (rev 106257)
+++ trunk/Source/WebCore/editing/EditingStyle.cpp	2012-01-30 18:52:16 UTC (rev 106258)
@@ -558,9 +558,9 @@
     RefPtr<CSSMutableStyleDeclaration> nodeStyle = editingStyleFromComputedStyle(computedStyle(node), AllEditingProperties);
     nodeStyle->removeEquivalentProperties(parentStyle.get());
 
-    CSSMutableStyleDeclaration::const_iterator end = nodeStyle->end();
-    for (CSSMutableStyleDeclaration::const_iterator it = nodeStyle->begin(); it != end; ++it)
-        m_mutableStyle->removeProperty(it->id());
+    unsigned propertyCount = nodeStyle->propertyCount();
+    for (unsigned i = 0; i < propertyCount; ++i)
+        m_mutableStyle->removeProperty(nodeStyle->propertyAt(i).id());
 }
 
 void EditingStyle::removeNonEditingProperties()
@@ -652,9 +652,9 @@
     if (!m_mutableStyle || !inlineStyle)
         return false;
 
-    CSSMutableStyleDeclaration::const_iterator end = m_mutableStyle->end();
-    for (CSSMutableStyleDeclaration::const_iterator it = m_mutableStyle->begin(); it != end; ++it) {
-        CSSPropertyID propertyID = static_cast<CSSPropertyID>(it->id());
+    unsigned propertyCount = m_mutableStyle->propertyCount();
+    for (unsigned i = 0; i < propertyCount; ++i) {
+        CSSPropertyID propertyID = static_cast<CSSPropertyID>(m_mutableStyle->propertyAt(i).id());
 
         // We don't override whitespace property of a tab span because that would collapse the tab into a space.
         if (propertyID == CSSPropertyWhiteSpace && isTabSpanNode(element))
@@ -836,9 +836,9 @@
 
     if (element->hasAttribute(HTMLNames::styleAttr)) {
         if (CSSMutableStyleDeclaration* style = element->inlineStyleDecl()) {
-            CSSMutableStyleDeclaration::const_iterator end = style->end();
-            for (CSSMutableStyleDeclaration::const_iterator it = style->begin(); it != end; ++it) {
-                if (!isEditingProperty(it->id()))
+            unsigned propertyCount = style->propertyCount();
+            for (unsigned i = 0; i < propertyCount; ++i) {
+                if (!isEditingProperty(style->propertyAt(i).id()))
                     return false;
             }
         }
@@ -992,21 +992,22 @@
         return;
     }
 
-    CSSMutableStyleDeclaration::const_iterator end = style->end();
-    for (CSSMutableStyleDeclaration::const_iterator it = style->begin(); it != end; ++it) {
-        RefPtr<CSSValue> value = m_mutableStyle->getPropertyCSSValue(it->id());
+    unsigned propertyCount = style->propertyCount();
+    for (unsigned i = 0; i < propertyCount; ++i) {
+        const CSSProperty& property = style->propertyAt(i);
+        RefPtr<CSSValue> value = m_mutableStyle->getPropertyCSSValue(property.id());
 
         // text decorations never override values
-        if ((it->id() == CSSPropertyTextDecoration || it->id() == CSSPropertyWebkitTextDecorationsInEffect) && it->value()->isValueList() && value) {
+        if ((property.id() == CSSPropertyTextDecoration || property.id() == CSSPropertyWebkitTextDecorationsInEffect) && property.value()->isValueList() && value) {
             if (value->isValueList()) {
-                mergeTextDecorationValues(static_cast<CSSValueList*>(value.get()), static_cast<CSSValueList*>(it->value()));
+                mergeTextDecorationValues(static_cast<CSSValueList*>(value.get()), static_cast<CSSValueList*>(property.value()));
                 continue;
             }
             value = 0; // text-decoration: none is equivalent to not having the property
         }
 
         if (mode == OverrideValues || (mode == DoNotOverrideValues && !value))
-            m_mutableStyle->setProperty(it->id(), it->value()->cssText(), it->isImportant());
+            m_mutableStyle->setProperty(property.id(), property.value()->cssText(), property.isImportant());
     }
 }
 
@@ -1049,9 +1050,9 @@
     RefPtr<CSSComputedStyleDeclaration> computedStyleForElement = computedStyle(element);
     RefPtr<CSSMutableStyleDeclaration> fromComputedStyle = CSSMutableStyleDeclaration::create();
     {
-        CSSMutableStyleDeclaration::const_iterator end = m_mutableStyle->end();
-        for (CSSMutableStyleDeclaration::const_iterator it = m_mutableStyle->begin(); it != end; ++it) {
-            const CSSProperty& property = *it;
+        unsigned propertyCount = m_mutableStyle->propertyCount();
+        for (unsigned i = 0; i < propertyCount; ++i) {
+            const CSSProperty& property = m_mutableStyle->propertyAt(i);
             CSSValue* value = property.value();
             if (!value->isPrimitiveValue())
                 continue;
@@ -1066,11 +1067,10 @@
 
 static void removePropertiesInStyle(CSSMutableStyleDeclaration* styleToRemovePropertiesFrom, CSSMutableStyleDeclaration* style)
 {
-    Vector<int> propertiesToRemove(style->propertyCount());
-    size_t i = 0;
-    CSSMutableStyleDeclaration::const_iterator end = style->end();
-    for (CSSMutableStyleDeclaration::const_iterator it = style->begin(); it != end; ++it, ++i)
-        propertiesToRemove[i] = it->id();
+    unsigned propertyCount = style->propertyCount();
+    Vector<int> propertiesToRemove(propertyCount);
+    for (unsigned i = 0; i < propertyCount; ++i)
+        propertiesToRemove[i] = style->propertyAt(i).id();
 
     styleToRemovePropertiesFrom->removePropertiesInSet(propertiesToRemove.data(), propertiesToRemove.size());
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to