Changeset 103855 in webkit


Ignore:
Timestamp:
Dec 30, 2011, 6:43:33 PM (13 years ago)
Author:
[email protected]
Message:

Cache and reuse the HTMLSelectElement.options collection.
<http://webkit.org/b/75399>

Reviewed by Anders Carlsson.

Source/WebCore:

Let HTMLSelectElement::options() cache the returned collection and tie it to the
lifetime of the form. This shrinks HTMLSelectElement by sizeof(CollectionCache)
minus one pointer.

Test: fast/dom/select-options-collection-idempotence.html

fast/gc-9.html

  • html/HTMLSelectElement.h:
  • html/HTMLSelectElement.cpp:

(WebCore::HTMLSelectElement::options):

Cache the HTMLOptionsCollection returned by options() on the HTMLSelectElement.
Remove the per-select CollectionCache and let the collection manage that.

  • html/HTMLOptionsCollection.h:
  • html/HTMLOptionsCollection.cpp:

(WebCore::HTMLOptionsCollection::create):
(WebCore::HTMLOptionsCollection::HTMLOptionsCollection):

Tell the base class constructor to not retain the back-pointer to the element.

  • html/HTMLSelectElement.cpp:

(WebCore::HTMLSelectElement::setRecalcListItems):

  • html/HTMLOptionsCollection.cpp:

(WebCore::HTMLOptionsCollection::invalidateCache):

Added so HTMLSelectElement can invalidate the collection without triggering
unnecessary instantiation of a CollectionCache.

LayoutTests:

  • Update gc-9.html to document the new lifetime characteristics of HTMLSelectElement.options.
  • Add a test to verify that HTMLSelectElement.options returns the same object when called repeatedly.
  • fast/dom/gc-9-expected.txt:
  • fast/dom/gc-9.html:
  • fast/dom/select-options-collection-idempotence-expected.txt: Added.
  • fast/dom/select-options-collection-idempotence.html: Added.
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r103853 r103855  
     12011-12-30  Andreas Kling  <[email protected]>
     2
     3        Cache and reuse the HTMLSelectElement.options collection.
     4        <http://webkit.org/b/75399>
     5
     6        Reviewed by Anders Carlsson.
     7
     8        - Update gc-9.html to document the new lifetime characteristics of HTMLSelectElement.options.
     9        - Add a test to verify that HTMLSelectElement.options returns the same object when called repeatedly.
     10
     11        * fast/dom/gc-9-expected.txt:
     12        * fast/dom/gc-9.html:
     13        * fast/dom/select-options-collection-idempotence-expected.txt: Added.
     14        * fast/dom/select-options-collection-idempotence.html: Added.
     15
    1162011-12-30  Robert Hogan  <[email protected]>
    217
  • trunk/LayoutTests/fast/dom/gc-9-expected.txt

    r103848 r103855  
    1414PASS: document.getElementsByTagName('canvas')[0].getContext('2d').createLinearGradient(0, 0, 0, 0).myCustomProperty should be undefined and is.
    1515PASS: document.getElementsByTagName('canvas')[0].getContext('2d').createPattern(new Image(), 'no-repeat').myCustomProperty should be undefined and is.
    16 PASS: document.getElementsByTagName('select')[0].options.myCustomProperty should be undefined and is.
     16PASS: document.getElementsByTagName('select')[0].options.myCustomProperty should be 1 and is.
    1717PASS: document.body.childNodes.myCustomProperty should be undefined and is.
    1818PASS: document.all.myCustomProperty should be 1 and is.
     
    5050PASS: document.getElementsByTagName('canvas')[0].getContext('2d').createLinearGradient(0, 0, 0, 0).myCustomProperty should be undefined and is.
    5151PASS: document.getElementsByTagName('canvas')[0].getContext('2d').createPattern(new Image(), 'no-repeat').myCustomProperty should be undefined and is.
    52 PASS: document.getElementsByTagName('select')[0].options.myCustomProperty should be undefined and is.
     52PASS: document.getElementsByTagName('select')[0].options.myCustomProperty should be 1 and is.
    5353PASS: document.body.childNodes.myCustomProperty should be undefined and is.
    5454PASS: document.all.myCustomProperty should be 1 and is.
  • trunk/LayoutTests/fast/dom/gc-9.html

    r103848 r103855  
    123123    [ "document.getElementsByTagName('canvas')[0].getContext('2d').createLinearGradient(0, 0, 0, 0)" ], // CanvasGradient
    124124    [ "document.getElementsByTagName('canvas')[0].getContext('2d').createPattern(new Image(), 'no-repeat')" ], // CanvasPattern
    125     [ "document.getElementsByTagName('select')[0].options" ],
     125    [ "document.getElementsByTagName('select')[0].options", "allow custom" ],
    126126    [ "document.body.childNodes" ],
    127127
  • trunk/Source/WebCore/ChangeLog

    r103854 r103855  
     12011-12-30  Andreas Kling  <[email protected]>
     2
     3        Cache and reuse the HTMLSelectElement.options collection.
     4        <http://webkit.org/b/75399>
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Let HTMLSelectElement::options() cache the returned collection and tie it to the
     9        lifetime of the form. This shrinks HTMLSelectElement by sizeof(CollectionCache)
     10        minus one pointer.
     11
     12        Test: fast/dom/select-options-collection-idempotence.html
     13              fast/gc-9.html
     14
     15        * html/HTMLSelectElement.h:
     16        * html/HTMLSelectElement.cpp:
     17        (WebCore::HTMLSelectElement::options):
     18
     19            Cache the HTMLOptionsCollection returned by options() on the HTMLSelectElement.
     20            Remove the per-select CollectionCache and let the collection manage that.
     21
     22        * html/HTMLOptionsCollection.h:
     23        * html/HTMLOptionsCollection.cpp:
     24        (WebCore::HTMLOptionsCollection::create):
     25        (WebCore::HTMLOptionsCollection::HTMLOptionsCollection):
     26
     27            Tell the base class constructor to not retain the back-pointer to the element.
     28
     29        * html/HTMLSelectElement.cpp:
     30        (WebCore::HTMLSelectElement::setRecalcListItems):
     31        * html/HTMLOptionsCollection.cpp:
     32        (WebCore::HTMLOptionsCollection::invalidateCache):
     33
     34            Added so HTMLSelectElement can invalidate the collection without triggering
     35            unnecessary instantiation of a CollectionCache.
     36
    1372011-12-30  Kentaro Hara  <[email protected]>
    238
  • trunk/Source/WebCore/html/HTMLOptionsCollection.cpp

    r97533 r103855  
    2828namespace WebCore {
    2929
    30 HTMLOptionsCollection::HTMLOptionsCollection(PassRefPtr<HTMLSelectElement> select)
    31     : HTMLCollection(select.get(), SelectOptions, select->collectionInfo())
     30HTMLOptionsCollection::HTMLOptionsCollection(HTMLSelectElement* select)
     31    : HTMLCollection(select, SelectOptions, 0, /* retainBaseNode */ false)
    3232{
    3333}
    3434
    35 PassRefPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(PassRefPtr<HTMLSelectElement> select)
     35PassRefPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(HTMLSelectElement* select)
    3636{
    3737    return adoptRef(new HTMLOptionsCollection(select));
     
    8888}
    8989
     90void HTMLOptionsCollection::invalidateCache()
     91{
     92    if (info())
     93        info()->reset();
     94}
     95
    9096} //namespace
  • trunk/Source/WebCore/html/HTMLOptionsCollection.h

    r34432 r103855  
    3636class HTMLOptionsCollection : public HTMLCollection {
    3737public:
    38     static PassRefPtr<HTMLOptionsCollection> create(PassRefPtr<HTMLSelectElement>);
     38    static PassRefPtr<HTMLOptionsCollection> create(HTMLSelectElement*);
    3939
    4040    void add(PassRefPtr<HTMLOptionElement>, ExceptionCode&);
     
    4747    void setLength(unsigned, ExceptionCode&);
    4848
     49    void invalidateCache();
     50
    4951private:
    50     HTMLOptionsCollection(PassRefPtr<HTMLSelectElement>);
     52    HTMLOptionsCollection(HTMLSelectElement*);
    5153};
    5254
  • trunk/Source/WebCore/html/HTMLSelectElement.cpp

    r103497 r103855  
    328328PassRefPtr<HTMLOptionsCollection> HTMLSelectElement::options()
    329329{
    330     return HTMLOptionsCollection::create(this);
     330    if (!m_optionsCollection)
     331        m_optionsCollection = HTMLOptionsCollection::create(this);
     332    return m_optionsCollection;
    331333}
    332334
     
    681683    setOptionsChangedOnRenderer();
    682684    setNeedsStyleRecalc();
    683     if (!inDocument())
    684         m_collectionInfo.reset();
     685    if (!inDocument() && m_optionsCollection)
     686        m_optionsCollection->invalidateCache();
    685687}
    686688
  • trunk/Source/WebCore/html/HTMLSelectElement.h

    r102419 r103855  
    2727#define HTMLSelectElement_h
    2828
    29 #include "CollectionCache.h"
    3029#include "Event.h"
    3130#include "HTMLFormControlElement.h"
     31#include "HTMLOptionsCollection.h"
    3232#include <wtf/Vector.h>
    3333
     
    8484    Node* namedItem(const AtomicString& name);
    8585    Node* item(unsigned index);
    86 
    87     CollectionCache* collectionInfo() { m_collectionInfo.checkConsistency(); return &m_collectionInfo; }
    8886
    8987    void scrollToSelection();
     
    177175    virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
    178176
    179     CollectionCache m_collectionInfo;
     177    RefPtr<HTMLOptionsCollection> m_optionsCollection;
     178
    180179    // m_listItems contains HTMLOptionElement, HTMLOptGroupElement, and HTMLHRElement objects.
    181180    mutable Vector<HTMLElement*> m_listItems;
Note: See TracChangeset for help on using the changeset viewer.