[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.19-706-ge5415e9

zimmermann at webkit.org zimmermann at webkit.org
Thu Feb 4 21:31:17 UTC 2010


The following commit has been merged in the webkit-1.1 branch:
commit 3cdd8dc6df5e73fd7b1fa7eca997c042d13ff3f4
Author: zimmermann at webkit.org <zimmermann at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Jan 28 20:27:38 2010 +0000

    2010-01-28  Nikolas Zimmermann  <nzimmermann at rim.com>
    
            Reviewed by Dirk Schulze.
    
            Save additional memory in SVG*Element classes, by introducing SVGElementRareData
            https://bugs.webkit.org/show_bug.cgi?id=34268
    
            Introduce SVGElementRareData, to remove the need to store any members in SVGElement/SVGStyledElement.
            This saves some additional MB for the svg-node-count-vs-scroll.xhtml testcase.
    
            SVGElementRareData works just like NodeRareData. Unlike ElementRareData, we're not inheriting from
            NodeRareData in SVG, as we don't need all the rare data stored there, unlike Element.
    
            * GNUmakefile.am: Add SVGElementRareData.h to build.
            * WebCore.gypi: Ditto.
            * WebCore.pro: Ditto.
            * WebCore.vcproj/WebCore.vcproj: Ditto.
            * WebCore.xcodeproj/project.pbxproj: Ditto.
            * dom/Node.cpp: Use Nodes bitfield to keep track wheter a SVGElement has a SVGElementRareData object associated.
            (WebCore::Node::Node):
            * dom/Node.h: Add m_hasRareSVGData flag, merged with the existing bitfield, 10 bits remaining now.
            (WebCore::Node::hasRareSVGData):
            * svg/SVGAnimateMotionElement.cpp: SVGElement::instancesForElement() now returns a const-reference to the HashMap instead of copying.
            (WebCore::SVGAnimateMotionElement::applyResultsToTarget):
            * svg/SVGAnimateTransformElement.cpp: Ditto.
            (WebCore::SVGAnimateTransformElement::applyResultsToTarget):
            * svg/SVGAnimationElement.cpp: Ditto.
            (WebCore::SVGAnimationElement::setTargetAttributeAnimatedValue):
            * svg/SVGElement.cpp: Move the element instances HashSet and two cursor-related pointers into SVGElementRareData.
            (WebCore::SVGElement::SVGElement):
            (WebCore::SVGElement::~SVGElement):
            (WebCore::SVGElement::rareSVGData): Modelled just like Node::rareData().
            (WebCore::SVGElement::ensureRareSVGData): Dito.
            (WebCore::SVGElement::accessDocumentSVGExtensions):
            (WebCore::SVGElement::mapInstanceToElement): Route call through SVGElementRareData.
            (WebCore::SVGElement::removeInstanceMapping): Ditto.
            (WebCore::SVGElement::instancesForElement): Ditto.
            (WebCore::SVGElement::setCursorElement): Ditto.
            (WebCore::SVGElement::setCursorImageValue): Ditto.
            * svg/SVGElement.h:
            * svg/SVGElementInstance.cpp: Ditto.
            (WebCore::SVGElementInstance::invalidateAllInstancesOfElement):
            * svg/SVGElementRareData.h: Added. Based on NodeRareData - works exactly the same.
            (WebCore::SVGElementRareData::SVGElementRareData):
            (WebCore::SVGElementRareData::rareDataMap):
            (WebCore::SVGElementRareData::rareDataFromMap):
            (WebCore::SVGElementRareData::elementInstances):
            (WebCore::SVGElementRareData::instanceUpdatesBlocked):
            (WebCore::SVGElementRareData::setInstanceUpdatesBlocked):
            (WebCore::SVGElementRareData::cursorElement):
            (WebCore::SVGElementRareData::setCursorElement):
            (WebCore::SVGElementRareData::cursorImageValue):
            (WebCore::SVGElementRareData::setCursorImageValue):
            * svg/SVGStyledElement.cpp: Move m_instancesUpdatesBlocked into SVGElementRareData.
            (WebCore::SVGStyledElement::SVGStyledElement):
            (WebCore::SVGStyledElement::instanceUpdatesBlocked):
            (WebCore::SVGStyledElement::setInstanceUpdatesBlocked):
            * svg/SVGStyledElement.h:
            * svg/SVGUseElement.cpp: Adapt to element instances changes, now passed as const-reference.
            (WebCore::dumpInstanceTree):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@54009 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 24e15ab..549e675 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,64 @@
+2010-01-28  Nikolas Zimmermann  <nzimmermann at rim.com>
+
+        Reviewed by Dirk Schulze.
+
+        Save additional memory in SVG*Element classes, by introducing SVGElementRareData
+        https://bugs.webkit.org/show_bug.cgi?id=34268
+
+        Introduce SVGElementRareData, to remove the need to store any members in SVGElement/SVGStyledElement.
+        This saves some additional MB for the svg-node-count-vs-scroll.xhtml testcase.
+
+        SVGElementRareData works just like NodeRareData. Unlike ElementRareData, we're not inheriting from
+        NodeRareData in SVG, as we don't need all the rare data stored there, unlike Element.
+
+        * GNUmakefile.am: Add SVGElementRareData.h to build.
+        * WebCore.gypi: Ditto.
+        * WebCore.pro: Ditto.
+        * WebCore.vcproj/WebCore.vcproj: Ditto.
+        * WebCore.xcodeproj/project.pbxproj: Ditto.
+        * dom/Node.cpp: Use Nodes bitfield to keep track wheter a SVGElement has a SVGElementRareData object associated.
+        (WebCore::Node::Node):
+        * dom/Node.h: Add m_hasRareSVGData flag, merged with the existing bitfield, 10 bits remaining now.
+        (WebCore::Node::hasRareSVGData):
+        * svg/SVGAnimateMotionElement.cpp: SVGElement::instancesForElement() now returns a const-reference to the HashMap instead of copying.
+        (WebCore::SVGAnimateMotionElement::applyResultsToTarget):
+        * svg/SVGAnimateTransformElement.cpp: Ditto.
+        (WebCore::SVGAnimateTransformElement::applyResultsToTarget):
+        * svg/SVGAnimationElement.cpp: Ditto.
+        (WebCore::SVGAnimationElement::setTargetAttributeAnimatedValue):
+        * svg/SVGElement.cpp: Move the element instances HashSet and two cursor-related pointers into SVGElementRareData.
+        (WebCore::SVGElement::SVGElement):
+        (WebCore::SVGElement::~SVGElement):
+        (WebCore::SVGElement::rareSVGData): Modelled just like Node::rareData().
+        (WebCore::SVGElement::ensureRareSVGData): Dito.
+        (WebCore::SVGElement::accessDocumentSVGExtensions):
+        (WebCore::SVGElement::mapInstanceToElement): Route call through SVGElementRareData.
+        (WebCore::SVGElement::removeInstanceMapping): Ditto.
+        (WebCore::SVGElement::instancesForElement): Ditto.
+        (WebCore::SVGElement::setCursorElement): Ditto.
+        (WebCore::SVGElement::setCursorImageValue): Ditto.
+        * svg/SVGElement.h:
+        * svg/SVGElementInstance.cpp: Ditto.
+        (WebCore::SVGElementInstance::invalidateAllInstancesOfElement):
+        * svg/SVGElementRareData.h: Added. Based on NodeRareData - works exactly the same.
+        (WebCore::SVGElementRareData::SVGElementRareData):
+        (WebCore::SVGElementRareData::rareDataMap):
+        (WebCore::SVGElementRareData::rareDataFromMap):
+        (WebCore::SVGElementRareData::elementInstances):
+        (WebCore::SVGElementRareData::instanceUpdatesBlocked):
+        (WebCore::SVGElementRareData::setInstanceUpdatesBlocked):
+        (WebCore::SVGElementRareData::cursorElement):
+        (WebCore::SVGElementRareData::setCursorElement):
+        (WebCore::SVGElementRareData::cursorImageValue):
+        (WebCore::SVGElementRareData::setCursorImageValue):
+        * svg/SVGStyledElement.cpp: Move m_instancesUpdatesBlocked into SVGElementRareData.
+        (WebCore::SVGStyledElement::SVGStyledElement):
+        (WebCore::SVGStyledElement::instanceUpdatesBlocked):
+        (WebCore::SVGStyledElement::setInstanceUpdatesBlocked):
+        * svg/SVGStyledElement.h:
+        * svg/SVGUseElement.cpp: Adapt to element instances changes, now passed as const-reference.
+        (WebCore::dumpInstanceTree):
+
 2010-01-28  Aaron Boodman  <aa at chromium.org>
 
         Reviewed by Darin Adler.
diff --git a/WebCore/GNUmakefile.am b/WebCore/GNUmakefile.am
index 89fb66e..a830bcd 100644
--- a/WebCore/GNUmakefile.am
+++ b/WebCore/GNUmakefile.am
@@ -3049,6 +3049,7 @@ webcore_sources += \
 	WebCore/svg/SVGElementInstance.h \
 	WebCore/svg/SVGElementInstanceList.cpp \
 	WebCore/svg/SVGElementInstanceList.h \
+	WebCore/svg/SVGElementRareData.h \
 	WebCore/svg/SVGEllipseElement.cpp \
 	WebCore/svg/SVGEllipseElement.h \
 	WebCore/svg/SVGException.h \
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index 57611cd..08f735b 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -3345,6 +3345,7 @@
             'svg/SVGElementInstance.h',
             'svg/SVGElementInstanceList.cpp',
             'svg/SVGElementInstanceList.h',
+            'svg/SVGElementRareData.h',
             'svg/SVGEllipseElement.cpp',
             'svg/SVGEllipseElement.h',
             'svg/SVGException.h',
diff --git a/WebCore/WebCore.pro b/WebCore/WebCore.pro
index 959f783..e58a58b 100644
--- a/WebCore/WebCore.pro
+++ b/WebCore/WebCore.pro
@@ -1762,6 +1762,7 @@ HEADERS += \
     svg/SVGElement.h \
     svg/SVGElementInstance.h \
     svg/SVGElementInstanceList.h \
+    svg/SVGElementRareData.h \
     svg/SVGEllipseElement.h \
     svg/SVGExternalResourcesRequired.h \
     svg/SVGFEBlendElement.h \
diff --git a/WebCore/WebCore.vcproj/WebCore.vcproj b/WebCore/WebCore.vcproj/WebCore.vcproj
index 12cca99..e41a7fa 100644
--- a/WebCore/WebCore.vcproj/WebCore.vcproj
+++ b/WebCore/WebCore.vcproj/WebCore.vcproj
@@ -40837,6 +40837,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\svg\SVGElementRareData.h"
+				>
+			</File>
+			<File
 				RelativePath="..\svg\SVGEllipseElement.h"
 				>
 			</File>
diff --git a/WebCore/WebCore.xcodeproj/project.pbxproj b/WebCore/WebCore.xcodeproj/project.pbxproj
index 147809d..db276c5 100644
--- a/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -54,6 +54,7 @@
 		080FAE1B0EEEBDA800AACDE9 /* WMLTemplateElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 080FAE190EEEBDA800AACDE9 /* WMLTemplateElement.h */; };
 		0818AEE20EDB86BC00647B66 /* WMLEventHandlingElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0818AEE00EDB86BC00647B66 /* WMLEventHandlingElement.cpp */; };
 		0818AEE30EDB86BC00647B66 /* WMLEventHandlingElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 0818AEE10EDB86BC00647B66 /* WMLEventHandlingElement.h */; };
+		081AA8DA1111237E002AB06E /* SVGElementRareData.h in Headers */ = {isa = PBXBuildFile; fileRef = 081AA8D91111237E002AB06E /* SVGElementRareData.h */; };
 		081D81310EE0E74D00D73689 /* WMLTimerElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 081D812F0EE0E74D00D73689 /* WMLTimerElement.cpp */; };
 		081D81320EE0E74D00D73689 /* WMLTimerElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 081D81300EE0E74D00D73689 /* WMLTimerElement.h */; };
 		081EBF3A0FD34F4100DA7559 /* SVGFilterBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 081EBF380FD34F4100DA7559 /* SVGFilterBuilder.cpp */; };
@@ -5322,6 +5323,7 @@
 		080FAE190EEEBDA800AACDE9 /* WMLTemplateElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WMLTemplateElement.h; sourceTree = "<group>"; };
 		0818AEE00EDB86BC00647B66 /* WMLEventHandlingElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WMLEventHandlingElement.cpp; sourceTree = "<group>"; };
 		0818AEE10EDB86BC00647B66 /* WMLEventHandlingElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WMLEventHandlingElement.h; sourceTree = "<group>"; };
+		081AA8D91111237E002AB06E /* SVGElementRareData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGElementRareData.h; sourceTree = "<group>"; };
 		081D812F0EE0E74D00D73689 /* WMLTimerElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WMLTimerElement.cpp; sourceTree = "<group>"; };
 		081D81300EE0E74D00D73689 /* WMLTimerElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WMLTimerElement.h; sourceTree = "<group>"; };
 		081EBF380FD34F4100DA7559 /* SVGFilterBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGFilterBuilder.cpp; sourceTree = "<group>"; };
@@ -13856,6 +13858,7 @@
 				B22278260D00BF1F0071B782 /* SVGElementInstanceList.cpp */,
 				B22278270D00BF1F0071B782 /* SVGElementInstanceList.h */,
 				B22278280D00BF1F0071B782 /* SVGElementInstanceList.idl */,
+				081AA8D91111237E002AB06E /* SVGElementRareData.h */,
 				B22278290D00BF1F0071B782 /* SVGEllipseElement.cpp */,
 				B222782A0D00BF1F0071B782 /* SVGEllipseElement.h */,
 				B222782B0D00BF1F0071B782 /* SVGEllipseElement.idl */,
@@ -18462,6 +18465,7 @@
 				084D2834110A7FCB0038239A /* SVGAnimatedPropertyTraits.h in Headers */,
 				59E842661109E5A2000305AD /* JNIBridgeJSC.h in Headers */,
 				E1A1470811102B1500EEC0F3 /* ContainerNodeAlgorithms.h in Headers */,
+				081AA8DA1111237E002AB06E /* SVGElementRareData.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
diff --git a/WebCore/dom/Node.cpp b/WebCore/dom/Node.cpp
index 5ac745d..1baca9f 100644
--- a/WebCore/dom/Node.cpp
+++ b/WebCore/dom/Node.cpp
@@ -422,6 +422,7 @@ Node::Node(Document* document, ConstructionType type)
 #if ENABLE(SVG)
     , m_areSVGAttributesValid(true)
     , m_synchronizingSVGAttributes(false)
+    , m_hasRareSVGData(false)
 #endif
 {
     if (m_document)
diff --git a/WebCore/dom/Node.h b/WebCore/dom/Node.h
index 16a75dc..1eac305 100644
--- a/WebCore/dom/Node.h
+++ b/WebCore/dom/Node.h
@@ -571,7 +571,10 @@ protected:
     void setTabIndexExplicitly(short);
     
     bool hasRareData() const { return m_hasRareData; }
-    
+#if ENABLE(SVG)
+    bool hasRareSVGData() const { return m_hasRareSVGData; }
+#endif
+
     NodeRareData* rareData() const;
     NodeRareData* ensureRareData();
 
@@ -635,9 +638,10 @@ protected:
 #if ENABLE(SVG)
     mutable bool m_areSVGAttributesValid : 1; // Element
     mutable bool m_synchronizingSVGAttributes : 1; // SVGElement
+    bool m_hasRareSVGData : 1; // SVGElement
 #endif
 
-    // 11 bits remaining
+    // 10 bits remaining
 };
 
 // Used in Node::addSubresourceAttributeURLs() and in addSubresourceStyleURLs()
diff --git a/WebCore/svg/SVGAnimateMotionElement.cpp b/WebCore/svg/SVGAnimateMotionElement.cpp
index 44bf5fb..bd6de49 100644
--- a/WebCore/svg/SVGAnimateMotionElement.cpp
+++ b/WebCore/svg/SVGAnimateMotionElement.cpp
@@ -215,9 +215,9 @@ void SVGAnimateMotionElement::applyResultsToTarget()
         targetElement->renderer()->setNeedsLayout(true);
     
     // ...except in case where we have additional instances in <use> trees.
-    HashSet<SVGElementInstance*> instances = targetElement->instancesForElement();
-    HashSet<SVGElementInstance*>::iterator end = instances.end();
-    for (HashSet<SVGElementInstance*>::iterator it = instances.begin(); it != end; ++it) {
+    const HashSet<SVGElementInstance*>& instances = targetElement->instancesForElement();
+    const HashSet<SVGElementInstance*>::const_iterator end = instances.end();
+    for (HashSet<SVGElementInstance*>::const_iterator it = instances.begin(); it != end; ++it) {
         SVGElement* shadowTreeElement = (*it)->shadowTreeElement();
         ASSERT(shadowTreeElement);
         TransformationMatrix* transform = shadowTreeElement->supplementalTransform();
diff --git a/WebCore/svg/SVGAnimateTransformElement.cpp b/WebCore/svg/SVGAnimateTransformElement.cpp
index 362a22d..ac6eac9 100644
--- a/WebCore/svg/SVGAnimateTransformElement.cpp
+++ b/WebCore/svg/SVGAnimateTransformElement.cpp
@@ -163,10 +163,10 @@ void SVGAnimateTransformElement::applyResultsToTarget()
         targetElement->renderer()->setNeedsLayout(true);
     
     // ...except in case where we have additional instances in <use> trees.
-    HashSet<SVGElementInstance*> instances = targetElement->instancesForElement();
+    const HashSet<SVGElementInstance*>& instances = targetElement->instancesForElement();
     RefPtr<SVGTransformList> transformList = transformListFor(targetElement);
-    HashSet<SVGElementInstance*>::iterator end = instances.end();
-    for (HashSet<SVGElementInstance*>::iterator it = instances.begin(); it != end; ++it) {
+    const HashSet<SVGElementInstance*>::const_iterator end = instances.end();
+    for (HashSet<SVGElementInstance*>::const_iterator it = instances.begin(); it != end; ++it) {
         SVGElement* shadowTreeElement = (*it)->shadowTreeElement();
         ASSERT(shadowTreeElement);
         if (shadowTreeElement->isStyledTransformable())
diff --git a/WebCore/svg/SVGAnimationElement.cpp b/WebCore/svg/SVGAnimationElement.cpp
index 729fb7e..39abbfc 100644
--- a/WebCore/svg/SVGAnimationElement.cpp
+++ b/WebCore/svg/SVGAnimationElement.cpp
@@ -316,9 +316,9 @@ void SVGAnimationElement::setTargetAttributeAnimatedValue(const String& value)
         static_cast<SVGStyledElement*>(target)->setInstanceUpdatesBlocked(false);
     
     // If the target element is used in an <use> instance tree, update that as well.
-    HashSet<SVGElementInstance*> instances = target->instancesForElement();
-    HashSet<SVGElementInstance*>::iterator end = instances.end();
-    for (HashSet<SVGElementInstance*>::iterator it = instances.begin(); it != end; ++it) {
+    const HashSet<SVGElementInstance*>& instances = target->instancesForElement();
+    const HashSet<SVGElementInstance*>::const_iterator end = instances.end();
+    for (HashSet<SVGElementInstance*>::const_iterator it = instances.begin(); it != end; ++it) {
         SVGElement* shadowTreeElement = (*it)->shadowTreeElement();
         ASSERT(shadowTreeElement);
         if (isCSS)
diff --git a/WebCore/svg/SVGElement.cpp b/WebCore/svg/SVGElement.cpp
index c2cc36a..19c5f3b 100644
--- a/WebCore/svg/SVGElement.cpp
+++ b/WebCore/svg/SVGElement.cpp
@@ -39,6 +39,7 @@
 #include "RenderObject.h"
 #include "SVGCursorElement.h"
 #include "SVGElementInstance.h"
+#include "SVGElementRareData.h"
 #include "SVGNames.h"
 #include "SVGResource.h"
 #include "SVGSVGElement.h"
@@ -53,8 +54,6 @@ using namespace HTMLNames;
 
 SVGElement::SVGElement(const QualifiedName& tagName, Document* document)
     : StyledElement(tagName, document, CreateElementZeroRefCount)
-    , m_cursorElement(0)
-    , m_cursorImageValue(0)
 {
 }
 
@@ -65,10 +64,40 @@ PassRefPtr<SVGElement> SVGElement::create(const QualifiedName& tagName, Document
 
 SVGElement::~SVGElement()
 {
-    if (m_cursorElement)
-        m_cursorElement->removeClient(this);
-    if (m_cursorImageValue)
-        m_cursorImageValue->removeReferencedElement(this);
+    if (!hasRareSVGData())
+        ASSERT(!SVGElementRareData::rareDataMap().contains(this));
+    else {
+        SVGElementRareData::SVGElementRareDataMap& rareDataMap = SVGElementRareData::rareDataMap();
+        SVGElementRareData::SVGElementRareDataMap::iterator it = rareDataMap.find(this);
+        ASSERT(it != rareDataMap.end());
+
+        SVGElementRareData* rareData = it->second;
+        if (SVGCursorElement* cursorElement = rareData->cursorElement())
+            cursorElement->removeClient(this);
+        if (CSSCursorImageValue* cursorImageValue = rareData->cursorImageValue())
+            cursorImageValue->removeReferencedElement(this);
+
+        delete rareData;
+        rareDataMap.remove(it);
+    }
+}
+
+SVGElementRareData* SVGElement::rareSVGData() const
+{
+    ASSERT(hasRareSVGData());
+    return SVGElementRareData::rareDataFromMap(this);
+}
+
+SVGElementRareData* SVGElement::ensureRareSVGData()
+{
+    if (hasRareSVGData())
+        return rareSVGData();
+
+    ASSERT(!SVGElementRareData::rareDataMap().contains(this));
+    SVGElementRareData* data = new SVGElementRareData;
+    SVGElementRareData::rareDataMap().set(this, data);
+    m_hasRareSVGData = true;
+    return data;
 }
 
 bool SVGElement::isSupported(StringImpl* feature, StringImpl* version) const
@@ -116,7 +145,6 @@ SVGElement* SVGElement::viewportElement() const
 
 SVGDocumentExtensions* SVGElement::accessDocumentSVGExtensions() const
 {
-
     // This function is provided for use by SVGAnimatedProperty to avoid
     // global inclusion of Document.h in SVG code.
     return document() ? document()->accessSVGExtensions() : 0;
@@ -125,20 +153,41 @@ SVGDocumentExtensions* SVGElement::accessDocumentSVGExtensions() const
 void SVGElement::mapInstanceToElement(SVGElementInstance* instance)
 {
     ASSERT(instance);
-    ASSERT(!m_elementInstances.contains(instance));
-    m_elementInstances.add(instance);
+
+    HashSet<SVGElementInstance*>& instances = ensureRareSVGData()->elementInstances();
+    ASSERT(!instances.contains(instance));
+
+    instances.add(instance);
 }
  
 void SVGElement::removeInstanceMapping(SVGElementInstance* instance)
 {
     ASSERT(instance);
-    ASSERT(m_elementInstances.contains(instance));
-    m_elementInstances.remove(instance);
+    ASSERT(hasRareSVGData());
+
+    HashSet<SVGElementInstance*>& instances = rareSVGData()->elementInstances();
+    ASSERT(instances.contains(instance));
+
+    instances.remove(instance);
+}
+
+const HashSet<SVGElementInstance*>& SVGElement::instancesForElement() const
+{
+    if (!hasRareSVGData()) {
+        DEFINE_STATIC_LOCAL(HashSet<SVGElementInstance*>, emptyInstances, ());
+        return emptyInstances;
+    }
+    return rareSVGData()->elementInstances();
+}
+
+void SVGElement::setCursorElement(SVGCursorElement* cursorElement)
+{
+    ensureRareSVGData()->setCursorElement(cursorElement);
 }
 
-HashSet<SVGElementInstance*> SVGElement::instancesForElement() const
+void SVGElement::setCursorImageValue(CSSCursorImageValue* cursorImageValue)
 {
-    return m_elementInstances;
+    ensureRareSVGData()->setCursorImageValue(cursorImageValue);
 }
 
 void SVGElement::parseMappedAttribute(MappedAttribute* attr)
diff --git a/WebCore/svg/SVGElement.h b/WebCore/svg/SVGElement.h
index 89e533a..679c265 100644
--- a/WebCore/svg/SVGElement.h
+++ b/WebCore/svg/SVGElement.h
@@ -32,6 +32,7 @@ namespace WebCore {
     class Document;
     class SVGCursorElement;
     class SVGElementInstance;
+    class SVGElementRareData;
     class SVGSVGElement;
     class TransformationMatrix;
 
@@ -73,10 +74,10 @@ namespace WebCore {
 
         void setSynchronizedSVGAttributes(bool value) { m_areSVGAttributesValid = value; }
 
-        HashSet<SVGElementInstance*> instancesForElement() const;
+        const HashSet<SVGElementInstance*>& instancesForElement() const;
 
-        void setCursorElement(SVGCursorElement* cursorElement) { m_cursorElement = cursorElement; }
-        void setCursorImageValue(CSSCursorImageValue* cursorImageValue) { m_cursorImageValue = cursorImageValue; }
+        void setCursorElement(SVGCursorElement*);
+        void setCursorImageValue(CSSCursorImageValue*);
 
     protected:
         SVGElement(const QualifiedName&, Document*);
@@ -86,6 +87,9 @@ namespace WebCore {
         virtual void attributeChanged(Attribute*, bool preserveDecls = false);
         virtual void updateAnimatedSVGAttribute(const QualifiedName&) const;
 
+        SVGElementRareData* rareSVGData() const;
+        SVGElementRareData* ensureRareSVGData();
+
     private:
         friend class SVGElementInstance;
 
@@ -99,11 +103,6 @@ namespace WebCore {
         void removeInstanceMapping(SVGElementInstance*);
 
         virtual bool haveLoadedRequiredResources();
-
-        SVGCursorElement* m_cursorElement;
-        CSSCursorImageValue* m_cursorImageValue;
-
-        HashSet<SVGElementInstance*> m_elementInstances;
     };
 
 }
diff --git a/WebCore/svg/SVGElementInstance.cpp b/WebCore/svg/SVGElementInstance.cpp
index d348b0b..ca0a70c 100644
--- a/WebCore/svg/SVGElementInstance.cpp
+++ b/WebCore/svg/SVGElementInstance.cpp
@@ -95,15 +95,13 @@ void SVGElementInstance::invalidateAllInstancesOfElement(SVGElement* element)
     if (element->isStyled() && static_cast<SVGStyledElement*>(element)->instanceUpdatesBlocked())
         return;
 
-    HashSet<SVGElementInstance*> set = element->instancesForElement();
+    const HashSet<SVGElementInstance*>& set = element->instancesForElement();
     if (set.isEmpty())
         return;
 
     // Mark all use elements referencing 'element' for rebuilding
-    HashSet<SVGElementInstance*>::const_iterator it = set.begin();
     const HashSet<SVGElementInstance*>::const_iterator end = set.end();
-
-    for (; it != end; ++it) {
+    for (HashSet<SVGElementInstance*>::const_iterator it = set.begin(); it != end; ++it) {
         ASSERT((*it)->correspondingElement() == element);
         (*it)->correspondingUseElement()->invalidateShadowTree();
     }
diff --git a/WebCore/svg/SVGElementRareData.h b/WebCore/svg/SVGElementRareData.h
new file mode 100644
index 0000000..4e7f671
--- /dev/null
+++ b/WebCore/svg/SVGElementRareData.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef SVGElementRareData_h
+#define SVGElementRareData_h
+
+#include <wtf/HashSet.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/StdLibExtras.h>
+
+namespace WebCore {
+
+class CSSCursorImageValue;
+class SVGCursorElement;
+class SVGElement;
+class SVGElementInstance;
+
+class SVGElementRareData : public Noncopyable {
+public:
+    SVGElementRareData()
+        : m_cursorElement(0)
+        , m_cursorImageValue(0)
+        , m_instancesUpdatesBlocked(false)
+    {
+    }
+
+    typedef HashMap<const SVGElement*, SVGElementRareData*> SVGElementRareDataMap;
+
+    static SVGElementRareDataMap& rareDataMap()
+    {
+        DEFINE_STATIC_LOCAL(SVGElementRareDataMap, rareDataMap, ());
+        return rareDataMap;
+    }
+
+    static SVGElementRareData* rareDataFromMap(const SVGElement* element)
+    {
+        return rareDataMap().get(element);
+    }
+
+    HashSet<SVGElementInstance*>& elementInstances() { return m_elementInstances; }
+    const HashSet<SVGElementInstance*>& elementInstances() const { return m_elementInstances; }
+
+    bool instanceUpdatesBlocked() const { return m_instancesUpdatesBlocked; }
+    void setInstanceUpdatesBlocked(bool value) { m_instancesUpdatesBlocked = value; }
+
+    SVGCursorElement* cursorElement() const { return m_cursorElement; }
+    void setCursorElement(SVGCursorElement* cursorElement) { m_cursorElement = cursorElement; }
+
+    CSSCursorImageValue* cursorImageValue() const { return m_cursorImageValue; }
+    void setCursorImageValue(CSSCursorImageValue* cursorImageValue) { m_cursorImageValue = cursorImageValue; }
+
+private:
+    HashSet<SVGElementInstance*> m_elementInstances;
+    SVGCursorElement* m_cursorElement;
+    CSSCursorImageValue* m_cursorImageValue;
+    bool m_instancesUpdatesBlocked : 1;
+};
+
+}
+
+#endif
diff --git a/WebCore/svg/SVGStyledElement.cpp b/WebCore/svg/SVGStyledElement.cpp
index 155e6c6..4228a4c 100644
--- a/WebCore/svg/SVGStyledElement.cpp
+++ b/WebCore/svg/SVGStyledElement.cpp
@@ -34,6 +34,7 @@
 #include "RenderObject.h"
 #include "SVGElement.h"
 #include "SVGElementInstance.h"
+#include "SVGElementRareData.h"
 #include "SVGNames.h"
 #include "SVGRenderStyle.h"
 #include "SVGResourceClipper.h"
@@ -55,7 +56,6 @@ void mapAttributeToCSSProperty(HashMap<AtomicStringImpl*, int>* propertyNameToId
 
 SVGStyledElement::SVGStyledElement(const QualifiedName& tagName, Document* doc)
     : SVGElement(tagName, doc)
-    , m_instanceUpdatesBlocked(false)
 {
 }
 
@@ -305,7 +305,18 @@ void SVGStyledElement::detach()
     SVGResource::removeClient(this);
     SVGElement::detach();
 }
-    
+
+bool SVGStyledElement::instanceUpdatesBlocked() const
+{
+    return hasRareSVGData() && rareSVGData()->instanceUpdatesBlocked();
+}
+
+void SVGStyledElement::setInstanceUpdatesBlocked(bool value)
+{
+    if (hasRareSVGData())
+        rareSVGData()->setInstanceUpdatesBlocked(value);
+}
+
 }
 
 #endif // ENABLE(SVG)
diff --git a/WebCore/svg/SVGStyledElement.h b/WebCore/svg/SVGStyledElement.h
index bd57ee2..9f76c68 100644
--- a/WebCore/svg/SVGStyledElement.h
+++ b/WebCore/svg/SVGStyledElement.h
@@ -65,15 +65,14 @@ namespace WebCore {
 
         virtual void detach();
 
-        bool instanceUpdatesBlocked() const { return m_instanceUpdatesBlocked; }
-        void setInstanceUpdatesBlocked(bool value) { m_instanceUpdatesBlocked = value; }
+        bool instanceUpdatesBlocked() const;
+        void setInstanceUpdatesBlocked(bool);
 
     protected: 
         static int cssPropertyIdForSVGAttributeName(const QualifiedName&);
 
     private:
         DECLARE_ANIMATED_PROPERTY(SVGStyledElement, HTMLNames::classAttr, String, ClassName, className)
-        bool m_instanceUpdatesBlocked;
     };
 
 } // namespace WebCore
diff --git a/WebCore/svg/SVGUseElement.cpp b/WebCore/svg/SVGUseElement.cpp
index 5d14579..2ce1bd1 100644
--- a/WebCore/svg/SVGUseElement.cpp
+++ b/WebCore/svg/SVGUseElement.cpp
@@ -355,11 +355,11 @@ void dumpInstanceTree(unsigned int& depth, String& text, SVGElementInstance* tar
     for (unsigned int i = 0; i < depth; ++i)
         text += "  ";
 
-    HashSet<SVGElementInstance*> elementInstances = element->instancesForElement();
+    const HashSet<SVGElementInstance*>& elementInstances = element->instancesForElement();
     text += String::format("Corresponding element is associated with %i instance(s):\n", elementInstances.size());
 
-    HashSet<SVGElementInstance*>::iterator end = elementInstances.end();
-    for (HashSet<SVGElementInstance*>::iterator it = elementInstances.begin(); it != end; ++it) {
+    const HashSet<SVGElementInstance*>::const_iterator end = elementInstances.end();
+    for (HashSet<SVGElementInstance*>::const_iterator it = elementInstances.begin(); it != end; ++it) {
         for (unsigned int i = 0; i < depth; ++i)
             text += "  ";
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list