Changeset 166586 in webkit


Ignore:
Timestamp:
Apr 1, 2014 8:22:36 AM (10 years ago)
Author:
zandobersek@gmail.com
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.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r166585 r166586  
     12014-04-01  Zan Dobersek  <zdobersek@igalia.com>
     2
     3        Avoid unnecessary HashSet copies when calling collectInstancesForSVGElement
     4        https://bugs.webkit.org/show_bug.cgi?id=131020
     5
     6        Reviewed by Andreas Kling.
     7
     8        Remove collectInstancesForSVGElement() to avoid HashSet copies when assigning a const
     9        HashSet reference to a non-const HashSet reference. Instead, range-based for-loops are
     10        deployed to iterate directly over the const reference to HashSet that's returned by
     11        SVGElement::instancesForElement(). SVGElement::containingShadowRoot() return value
     12        is checked to see if the iteration should be performed in the first place, preserving
     13        the behavior of collectInstancesForSVGElement().
     14
     15        * svg/SVGElement.cpp:
     16        (WebCore::SVGElement::addEventListener):
     17        (WebCore::SVGElement::removeEventListener):
     18        (WebCore::collectInstancesForSVGElement): Deleted.
     19
    1202014-04-01  Zan Dobersek  <zdobersek@igalia.com>
    221
  • trunk/Source/WebCore/svg/SVGElement.cpp

    r165607 r166586  
    536536}
    537537
    538 static inline void collectInstancesForSVGElement(SVGElement* element, HashSet<SVGElementInstance*>& instances)
    539 {
    540     ASSERT(element);
    541     if (element->containingShadowRoot())
    542         return;
    543 
    544     ASSERT(!element->instanceUpdatesBlocked());
    545 
    546     instances = element->instancesForElement();
    547 }
    548 
    549538bool SVGElement::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> prpListener, bool useCapture)
    550539{
     
    555544        return false;
    556545
     546    if (containingShadowRoot())
     547        return true;
     548
    557549    // Add event listener to all shadow tree DOM element instances
    558     HashSet<SVGElementInstance*> instances;
    559     collectInstancesForSVGElement(this, instances);   
    560     const HashSet<SVGElementInstance*>::const_iterator end = instances.end();
    561     for (HashSet<SVGElementInstance*>::const_iterator it = instances.begin(); it != end; ++it) {
    562         ASSERT((*it)->shadowTreeElement());
    563         ASSERT((*it)->correspondingElement() == this);
    564 
    565         bool result = (*it)->shadowTreeElement()->Node::addEventListener(eventType, listener, useCapture);
     550    ASSERT(!element->instanceUpdatesBlocked());
     551    for (auto& instance : instancesForElement()) {
     552        ASSERT(instance->shadowTreeElement());
     553        ASSERT(instance->correspondingElement() == this);
     554
     555        bool result = instance->shadowTreeElement()->Node::addEventListener(eventType, listener, useCapture);
    566556        ASSERT_UNUSED(result, result);
    567557    }
     
    572562bool SVGElement::removeEventListener(const AtomicString& eventType, EventListener* listener, bool useCapture)
    573563{
    574     HashSet<SVGElementInstance*> instances;
    575     collectInstancesForSVGElement(this, instances);
    576     if (instances.isEmpty())
     564    if (containingShadowRoot())
    577565        return Node::removeEventListener(eventType, listener, useCapture);
    578566
     
    589577
    590578    // Remove event listener from all shadow tree DOM element instances
    591     const HashSet<SVGElementInstance*>::const_iterator end = instances.end();
    592     for (HashSet<SVGElementInstance*>::const_iterator it = instances.begin(); it != end; ++it) {
    593         ASSERT((*it)->correspondingElement() == this);
    594 
    595         SVGElement* shadowTreeElement = (*it)->shadowTreeElement();
     579    ASSERT(!element->instanceUpdatesBlocked());
     580    for (auto& instance : instancesForElement()) {
     581        ASSERT(instance->correspondingElement() == this);
     582
     583        SVGElement* shadowTreeElement = instance->shadowTreeElement();
    596584        ASSERT(shadowTreeElement);
    597585
Note: See TracChangeset for help on using the changeset viewer.