Title: [166586] trunk/Source/WebCore
- Revision
- 166586
- Author
- zandober...@gmail.com
- Date
- 2014-04-01 08:22:36 -0700 (Tue, 01 Apr 2014)
Log Message
Avoid unnecessary HashSet copies when calling collectInstancesForSVGElement
https://bugs.webkit.org/show_bug.cgi?id=131020
Reviewed by Andreas Kling.
Remove collectInstancesForSVGElement() to avoid HashSet copies when assigning a const
HashSet reference to a non-const HashSet reference. Instead, range-based for-loops are
deployed to iterate directly over the const reference to HashSet that's returned by
SVGElement::instancesForElement(). SVGElement::containingShadowRoot() return value
is checked to see if the iteration should be performed in the first place, preserving
the behavior of collectInstancesForSVGElement().
* svg/SVGElement.cpp:
(WebCore::SVGElement::addEventListener):
(WebCore::SVGElement::removeEventListener):
(WebCore::collectInstancesForSVGElement): Deleted.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (166585 => 166586)
--- trunk/Source/WebCore/ChangeLog 2014-04-01 15:20:40 UTC (rev 166585)
+++ trunk/Source/WebCore/ChangeLog 2014-04-01 15:22:36 UTC (rev 166586)
@@ -1,5 +1,24 @@
2014-04-01 Zan Dobersek <zdober...@igalia.com>
+ Avoid unnecessary HashSet copies when calling collectInstancesForSVGElement
+ https://bugs.webkit.org/show_bug.cgi?id=131020
+
+ Reviewed by Andreas Kling.
+
+ Remove collectInstancesForSVGElement() to avoid HashSet copies when assigning a const
+ HashSet reference to a non-const HashSet reference. Instead, range-based for-loops are
+ deployed to iterate directly over the const reference to HashSet that's returned by
+ SVGElement::instancesForElement(). SVGElement::containingShadowRoot() return value
+ is checked to see if the iteration should be performed in the first place, preserving
+ the behavior of collectInstancesForSVGElement().
+
+ * svg/SVGElement.cpp:
+ (WebCore::SVGElement::addEventListener):
+ (WebCore::SVGElement::removeEventListener):
+ (WebCore::collectInstancesForSVGElement): Deleted.
+
+2014-04-01 Zan Dobersek <zdober...@igalia.com>
+
Move the attributes HashMap out of the parseAttributes function
https://bugs.webkit.org/show_bug.cgi?id=131019
Modified: trunk/Source/WebCore/svg/SVGElement.cpp (166585 => 166586)
--- trunk/Source/WebCore/svg/SVGElement.cpp 2014-04-01 15:20:40 UTC (rev 166585)
+++ trunk/Source/WebCore/svg/SVGElement.cpp 2014-04-01 15:22:36 UTC (rev 166586)
@@ -535,17 +535,6 @@
return true;
}
-static inline void collectInstancesForSVGElement(SVGElement* element, HashSet<SVGElementInstance*>& instances)
-{
- ASSERT(element);
- if (element->containingShadowRoot())
- return;
-
- ASSERT(!element->instanceUpdatesBlocked());
-
- instances = element->instancesForElement();
-}
-
bool SVGElement::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> prpListener, bool useCapture)
{
RefPtr<EventListener> listener = prpListener;
@@ -554,15 +543,16 @@
if (!Node::addEventListener(eventType, listener, useCapture))
return false;
+ if (containingShadowRoot())
+ return true;
+
// Add event listener to all shadow tree DOM element instances
- HashSet<SVGElementInstance*> instances;
- collectInstancesForSVGElement(this, instances);
- const HashSet<SVGElementInstance*>::const_iterator end = instances.end();
- for (HashSet<SVGElementInstance*>::const_iterator it = instances.begin(); it != end; ++it) {
- ASSERT((*it)->shadowTreeElement());
- ASSERT((*it)->correspondingElement() == this);
+ ASSERT(!element->instanceUpdatesBlocked());
+ for (auto& instance : instancesForElement()) {
+ ASSERT(instance->shadowTreeElement());
+ ASSERT(instance->correspondingElement() == this);
- bool result = (*it)->shadowTreeElement()->Node::addEventListener(eventType, listener, useCapture);
+ bool result = instance->shadowTreeElement()->Node::addEventListener(eventType, listener, useCapture);
ASSERT_UNUSED(result, result);
}
@@ -571,9 +561,7 @@
bool SVGElement::removeEventListener(const AtomicString& eventType, EventListener* listener, bool useCapture)
{
- HashSet<SVGElementInstance*> instances;
- collectInstancesForSVGElement(this, instances);
- if (instances.isEmpty())
+ if (containingShadowRoot())
return Node::removeEventListener(eventType, listener, useCapture);
// EventTarget::removeEventListener creates a PassRefPtr around the given EventListener
@@ -588,11 +576,11 @@
return false;
// Remove event listener from all shadow tree DOM element instances
- const HashSet<SVGElementInstance*>::const_iterator end = instances.end();
- for (HashSet<SVGElementInstance*>::const_iterator it = instances.begin(); it != end; ++it) {
- ASSERT((*it)->correspondingElement() == this);
+ ASSERT(!element->instanceUpdatesBlocked());
+ for (auto& instance : instancesForElement()) {
+ ASSERT(instance->correspondingElement() == this);
- SVGElement* shadowTreeElement = (*it)->shadowTreeElement();
+ SVGElement* shadowTreeElement = instance->shadowTreeElement();
ASSERT(shadowTreeElement);
if (shadowTreeElement->Node::removeEventListener(eventType, listener, useCapture))
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes