Changeset 166407 in webkit


Ignore:
Timestamp:
Mar 28, 2014 8:36:40 AM (10 years ago)
Author:
Antti Koivisto
Message:

Remove NodeListRootType flag
https://bugs.webkit.org/show_bug.cgi?id=130896

Reviewed by Anders Carlsson.

This can be handled statically (except for the RadioNodeList case) removing
a branch from NodeList traversal.

  • dom/ClassNodeList.h:
  • dom/Document.cpp:

(WebCore::Document::registerNodeListForInvalidation):
(WebCore::Document::unregisterNodeListForInvalidation):
(WebCore::Document::registerNodeList): Deleted.
(WebCore::Document::unregisterNodeList): Deleted.

Mark document invalidation registered lists with a bit.
Renamed for clarity.

  • dom/Document.h:
  • dom/LiveNodeList.cpp:

(WebCore::LiveNodeList::LiveNodeList):
(WebCore::LiveNodeList::rootNode):

Base class version that invokes virtual isRootedAtDocument. It is needed to support
LiveNodeList::namedItem.

  • dom/LiveNodeList.h:

(WebCore::LiveNodeList::isRegisteredForInvalidationAtDocument):
(WebCore::LiveNodeList::setRegisteredForInvalidationAtDocument):
(WebCore::LiveNodeList::document):
(WebCore::CachedLiveNodeList<NodeListType>::CachedLiveNodeList):
(WebCore::CachedLiveNodeList<NodeListType>::~CachedLiveNodeList):
(WebCore::CachedLiveNodeList<NodeListType>::rootNode):

Call isRootedAtDocument on the final leaf type. Except for RadioNodeList this
resolves statically.

(WebCore::CachedLiveNodeList<NodeListType>::willValidateIndexCache):
(WebCore::CachedLiveNodeList<NodeListType>::invalidateCache):
(WebCore::LiveNodeList::isRootedAtDocument): Deleted.
(WebCore::LiveNodeList::rootType): Deleted.
(WebCore::LiveNodeList::rootNode): Deleted.

  • dom/NameNodeList.h:
  • dom/NodeRareData.h:

(WebCore::NodeListsNodeData::adoptDocument):

  • dom/TagNodeList.h:
  • html/HTMLCollection.cpp:

(WebCore::rootTypeFromCollectionType):

  • html/HTMLCollection.h:

(WebCore::HTMLCollection::isRootedAtDocument):
(WebCore::HTMLCollection::rootType):

HTMLCollections still needs the flag.

  • html/LabelsNodeList.cpp:

(WebCore::LabelsNodeList::LabelsNodeList):

  • html/LabelsNodeList.h:
  • html/RadioNodeList.cpp:

(WebCore::RadioNodeList::RadioNodeList):

  • html/RadioNodeList.h:
Location:
trunk/Source/WebCore
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r166406 r166407  
     12014-03-28  Antti Koivisto  <antti@apple.com>
     2
     3        Remove NodeListRootType flag
     4        https://bugs.webkit.org/show_bug.cgi?id=130896
     5
     6        Reviewed by Anders Carlsson.
     7
     8        This can be handled statically (except for the RadioNodeList case) removing
     9        a branch from NodeList traversal.
     10
     11        * dom/ClassNodeList.h:
     12        * dom/Document.cpp:
     13        (WebCore::Document::registerNodeListForInvalidation):
     14        (WebCore::Document::unregisterNodeListForInvalidation):
     15        (WebCore::Document::registerNodeList): Deleted.
     16        (WebCore::Document::unregisterNodeList): Deleted.
     17       
     18            Mark document invalidation registered lists with a bit.
     19            Renamed for clarity.
     20
     21        * dom/Document.h:
     22        * dom/LiveNodeList.cpp:
     23        (WebCore::LiveNodeList::LiveNodeList):
     24        (WebCore::LiveNodeList::rootNode):
     25       
     26            Base class version that invokes virtual isRootedAtDocument. It is needed to support
     27            LiveNodeList::namedItem.
     28
     29        * dom/LiveNodeList.h:
     30        (WebCore::LiveNodeList::isRegisteredForInvalidationAtDocument):
     31        (WebCore::LiveNodeList::setRegisteredForInvalidationAtDocument):
     32        (WebCore::LiveNodeList::document):
     33        (WebCore::CachedLiveNodeList<NodeListType>::CachedLiveNodeList):
     34        (WebCore::CachedLiveNodeList<NodeListType>::~CachedLiveNodeList):
     35        (WebCore::CachedLiveNodeList<NodeListType>::rootNode):
     36       
     37            Call isRootedAtDocument on the final leaf type. Except for RadioNodeList this
     38            resolves statically.
     39
     40        (WebCore::CachedLiveNodeList<NodeListType>::willValidateIndexCache):
     41        (WebCore::CachedLiveNodeList<NodeListType>::invalidateCache):
     42        (WebCore::LiveNodeList::isRootedAtDocument): Deleted.
     43        (WebCore::LiveNodeList::rootType): Deleted.
     44        (WebCore::LiveNodeList::rootNode): Deleted.
     45        * dom/NameNodeList.h:
     46        * dom/NodeRareData.h:
     47        (WebCore::NodeListsNodeData::adoptDocument):
     48        * dom/TagNodeList.h:
     49        * html/HTMLCollection.cpp:
     50        (WebCore::rootTypeFromCollectionType):
     51        * html/HTMLCollection.h:
     52        (WebCore::HTMLCollection::isRootedAtDocument):
     53        (WebCore::HTMLCollection::rootType):
     54       
     55            HTMLCollections still needs the flag.
     56
     57        * html/LabelsNodeList.cpp:
     58        (WebCore::LabelsNodeList::LabelsNodeList):
     59        * html/LabelsNodeList.h:
     60        * html/RadioNodeList.cpp:
     61        (WebCore::RadioNodeList::RadioNodeList):
     62        * html/RadioNodeList.h:
     63
    1642014-03-28  Mario Sanchez Prada  <mario.prada@samsung.com>
    265
  • trunk/Source/WebCore/dom/ClassNodeList.cpp

    r166377 r166407  
    11/*
    2  * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
     2 * Copyright (C) 2007-2008, 2014 Apple Inc. All rights reserved.
    33 * Copyright (C) 2007 David Smith (catfish.man@gmail.com)
    44 *
  • trunk/Source/WebCore/dom/ClassNodeList.h

    r166369 r166407  
    11/*
    2  * Copyright (C) 2007 Apple Inc. All rights reserved.
     2 * Copyright (C) 2007, 2014 Apple Inc. All rights reserved.
    33 * Copyright (C) 2007 David Smith (catfish.man@gmail.com)
    44 *
     
    4848
    4949    virtual bool nodeMatches(Element*) const override;
     50    virtual bool isRootedAtDocument() const override { return false; }
    5051
    5152private:
  • trunk/Source/WebCore/dom/Document.cpp

    r166277 r166407  
    34533453}
    34543454
    3455 void Document::registerNodeList(LiveNodeList& list)
     3455void Document::registerNodeListForInvalidation(LiveNodeList& list)
    34563456{
    34573457    m_nodeListAndCollectionCounts[list.invalidationType()]++;
    3458     if (list.isRootedAtDocument())
    3459         m_listsInvalidatedAtDocument.add(&list);
    3460 }
    3461 
    3462 void Document::unregisterNodeList(LiveNodeList& list)
     3458    if (!list.isRootedAtDocument())
     3459        return;
     3460    ASSERT(!list.isRegisteredForInvalidationAtDocument());
     3461    list.setRegisteredForInvalidationAtDocument(true);
     3462    m_listsInvalidatedAtDocument.add(&list);
     3463}
     3464
     3465void Document::unregisterNodeListForInvalidation(LiveNodeList& list)
    34633466{
    34643467    m_nodeListAndCollectionCounts[list.invalidationType()]--;
    3465     if (list.isRootedAtDocument()) {
    3466         if (!m_listsInvalidatedAtDocument.size()) {
    3467             ASSERT(m_inInvalidateNodeListAndCollectionCaches);
    3468             return;
    3469         }
    3470         ASSERT(m_listsInvalidatedAtDocument.contains(&list));
    3471         m_listsInvalidatedAtDocument.remove(&list);
    3472     }
     3468    if (!list.isRegisteredForInvalidationAtDocument())
     3469        return;
     3470    if (!m_listsInvalidatedAtDocument.size()) {
     3471        ASSERT(m_inInvalidateNodeListAndCollectionCaches);
     3472        return;
     3473    }
     3474    ASSERT(m_listsInvalidatedAtDocument.contains(&list));
     3475    m_listsInvalidatedAtDocument.remove(&list);
     3476    list.setRegisteredForInvalidationAtDocument(false);
    34733477}
    34743478
  • trunk/Source/WebCore/dom/Document.h

    r165423 r166407  
    762762    void optimizedStyleSheetUpdateTimerFired(Timer<Document>&);
    763763
    764     void registerNodeList(LiveNodeList&);
    765     void unregisterNodeList(LiveNodeList&);
     764    void registerNodeListForInvalidation(LiveNodeList&);
     765    void unregisterNodeListForInvalidation(LiveNodeList&);
    766766    void registerCollection(HTMLCollection&);
    767767    void unregisterCollection(HTMLCollection&);
  • trunk/Source/WebCore/dom/LiveNodeList.cpp

    r166377 r166407  
    33 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    44 *           (C) 2001 Dirk Mueller (mueller@kde.org)
    5  * Copyright (C) 2004, 2006, 2007, 2008, 2010, 2013 Apple Inc. All rights reserved.
     5 * Copyright (C) 2004, 2006-2008, 2010, 2013-2014 Apple Inc. All rights reserved.
    66 *
    77 * This library is free software; you can redistribute it and/or
     
    3232namespace WebCore {
    3333
    34 LiveNodeList::LiveNodeList(ContainerNode& ownerNode, NodeListInvalidationType invalidationType, NodeListRootType rootType)
     34LiveNodeList::LiveNodeList(ContainerNode& ownerNode, NodeListInvalidationType invalidationType)
    3535    : m_ownerNode(ownerNode)
    36     , m_rootType(rootType)
    3736    , m_invalidationType(invalidationType)
     37    , m_isRegisteredForInvalidationAtDocument(false)
    3838{
    39     ASSERT(m_rootType == static_cast<unsigned>(rootType));
    4039    ASSERT(m_invalidationType == static_cast<unsigned>(invalidationType));
    4140}
     
    4544}
    4645
     46ContainerNode& LiveNodeList::rootNode() const
     47{
     48    if (isRootedAtDocument() && ownerNode().inDocument())
     49        return ownerNode().document();
     50
     51    return ownerNode();
     52}
    4753
    4854Node* LiveNodeList::namedItem(const AtomicString& elementId) const
  • trunk/Source/WebCore/dom/LiveNodeList.h

    r166377 r166407  
    33 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    44 *           (C) 2001 Dirk Mueller (mueller@kde.org)
    5  * Copyright (C) 2004, 2006, 2007, 2013 Apple Inc. All rights reserved.
     5 * Copyright (C) 2004, 2006-2007, 2013-2014 Apple Inc. All rights reserved.
    66 *
    77 * This library is free software; you can redistribute it and/or
     
    3838class Element;
    3939
    40 enum NodeListRootType {
    41     NodeListIsRootedAtNode,
    42     NodeListIsRootedAtDocument
    43 };
    44 
    4540static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType, const QualifiedName&);
    4641
    4742class LiveNodeList : public NodeList {
    4843public:
    49     LiveNodeList(ContainerNode& ownerNode, NodeListInvalidationType, NodeListRootType);
     44    LiveNodeList(ContainerNode& ownerNode, NodeListInvalidationType);
     45    virtual ~LiveNodeList();
     46
    5047    virtual Node* namedItem(const AtomicString&) const override final;
     48
    5149    virtual bool nodeMatches(Element*) const = 0;
    52 
    53     virtual ~LiveNodeList();
    54 
    55     ALWAYS_INLINE bool isRootedAtDocument() const { return m_rootType == NodeListIsRootedAtDocument; }
     50    virtual bool isRootedAtDocument() const = 0;
     51
    5652    ALWAYS_INLINE NodeListInvalidationType invalidationType() const { return static_cast<NodeListInvalidationType>(m_invalidationType); }
    5753    ContainerNode& ownerNode() const { return const_cast<ContainerNode&>(m_ownerNode.get()); }
     
    6359    virtual void invalidateCache(Document&) const = 0;
    6460
     61    bool isRegisteredForInvalidationAtDocument() const { return m_isRegisteredForInvalidationAtDocument; }
     62    void setRegisteredForInvalidationAtDocument(bool f) { m_isRegisteredForInvalidationAtDocument = f; }
     63
    6564protected:
    6665    Document& document() const { return m_ownerNode->document(); }
     66
     67private:
     68    virtual bool isLiveNodeList() const override final { return true; }
     69
    6770    ContainerNode& rootNode() const;
    6871
    69     ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeListRootType>(m_rootType); }
    70 
    71 private:
    72     virtual bool isLiveNodeList() const override { return true; }
    73 
    7472    Element* iterateForPreviousElement(Element* current) const;
    7573
    7674    Ref<ContainerNode> m_ownerNode;
    7775
    78     const unsigned m_rootType : 1;
    79     const unsigned m_invalidationType : 4;
     76    const unsigned m_invalidationType;
     77    bool m_isRegisteredForInvalidationAtDocument;
    8078};
    8179
     
    10098
    10199protected:
    102     CachedLiveNodeList(ContainerNode& rootNode, NodeListInvalidationType, NodeListRootType = NodeListIsRootedAtNode);
     100    CachedLiveNodeList(ContainerNode& rootNode, NodeListInvalidationType);
    103101
    104102private:
     103    ContainerNode& rootNode() const;
     104
    105105    mutable CollectionIndexCache<NodeListType, Element> m_indexCache;
    106106};
     
    130130}
    131131
    132 inline ContainerNode& LiveNodeList::rootNode() const
    133 {
    134     if (isRootedAtDocument() && ownerNode().inDocument())
     132template <class NodeListType>
     133CachedLiveNodeList<NodeListType>::CachedLiveNodeList(ContainerNode& ownerNode, NodeListInvalidationType invalidationType)
     134    : LiveNodeList(ownerNode, invalidationType)
     135{
     136}
     137
     138template <class NodeListType>
     139CachedLiveNodeList<NodeListType>::~CachedLiveNodeList()
     140{
     141    if (m_indexCache.hasValidCache())
     142        document().unregisterNodeListForInvalidation(*this);
     143}
     144
     145template <class NodeListType>
     146inline ContainerNode& CachedLiveNodeList<NodeListType>::rootNode() const
     147{
     148    if (static_cast<const NodeListType&>(*this).isRootedAtDocument() && ownerNode().inDocument())
    135149        return ownerNode().document();
    136150
    137151    return ownerNode();
    138 }
    139 
    140 template <class NodeListType>
    141 CachedLiveNodeList<NodeListType>::CachedLiveNodeList(ContainerNode& ownerNode, NodeListInvalidationType invalidationType, NodeListRootType rootType)
    142     : LiveNodeList(ownerNode, invalidationType, rootType)
    143 {
    144 }
    145 
    146 template <class NodeListType>
    147 CachedLiveNodeList<NodeListType>::~CachedLiveNodeList()
    148 {
    149     if (m_indexCache.hasValidCache())
    150         document().unregisterNodeList(*this);
    151152}
    152153
     
    217218void CachedLiveNodeList<NodeListType>::willValidateIndexCache() const
    218219{
    219     document().registerNodeList(const_cast<NodeListType&>(static_cast<const NodeListType&>(*this)));
     220    document().registerNodeListForInvalidation(const_cast<NodeListType&>(static_cast<const NodeListType&>(*this)));
    220221}
    221222
     
    225226    if (!m_indexCache.hasValidCache())
    226227        return;
    227     document.unregisterNodeList(const_cast<NodeListType&>(static_cast<const NodeListType&>(*this)));
     228    document.unregisterNodeListForInvalidation(const_cast<NodeListType&>(static_cast<const NodeListType&>(*this)));
    228229    m_indexCache.invalidate();
    229230}
  • trunk/Source/WebCore/dom/NameNodeList.cpp

    r166377 r166407  
    33 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    44 *           (C) 2001 Dirk Mueller (mueller@kde.org)
    5  * Copyright (C) 2004, 2007 Apple Inc. All rights reserved.
     5 * Copyright (C) 2004, 2007, 2014 Apple Inc. All rights reserved.
    66 *
    77 * This library is free software; you can redistribute it and/or
  • trunk/Source/WebCore/dom/NameNodeList.h

    r166377 r166407  
    33 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    44 *           (C) 2001 Dirk Mueller (mueller@kde.org)
    5  * Copyright (C) 2004, 2007m 2008 Apple Inc. All rights reserved.
     5 * Copyright (C) 2004, 2007-2008, 2014 Apple Inc. All rights reserved.
    66 *
    77 * This library is free software; you can redistribute it and/or
     
    4242
    4343    virtual bool nodeMatches(Element*) const override;
     44    virtual bool isRootedAtDocument() const override { return false; }
    4445
    4546private:
  • trunk/Source/WebCore/dom/TagNodeList.cpp

    r166377 r166407  
    33 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    44 *           (C) 2001 Dirk Mueller (mueller@kde.org)
    5  * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
     5 * Copyright (C) 2004-2007, 2014 Apple Inc. All rights reserved.
    66 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
    77 *
  • trunk/Source/WebCore/dom/TagNodeList.h

    r166377 r166407  
    33 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    44 *           (C) 2001 Dirk Mueller (mueller@kde.org)
    5  * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
     5 * Copyright (C) 2004-2008, 2014 Apple Inc. All rights reserved.
    66 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
    77 *
     
    4848
    4949    virtual bool nodeMatches(Element*) const override;
     50    virtual bool isRootedAtDocument() const override { return false; }
    5051
    5152protected:
     
    7576
    7677    virtual bool nodeMatches(Element*) const override;
     78    virtual bool isRootedAtDocument() const override { return false; }
    7779
    7880private:
  • trunk/Source/WebCore/html/HTMLCollection.cpp

    r165699 r166407  
    6666}
    6767
    68 static NodeListRootType rootTypeFromCollectionType(CollectionType type)
     68static HTMLCollection::RootType rootTypeFromCollectionType(CollectionType type)
    6969{
    7070    switch (type) {
     
    8080    case DocumentNamedItems:
    8181    case FormControls:
    82         return NodeListIsRootedAtDocument;
     82        return HTMLCollection::IsRootedAtDocument;
    8383    case NodeChildren:
    8484    case TableTBodies:
     
    9090    case DataListOptions:
    9191    case MapAreas:
    92         return NodeListIsRootedAtNode;
     92        return HTMLCollection::IsRootedAtNode;
    9393    }
    9494    ASSERT_NOT_REACHED();
    95     return NodeListIsRootedAtNode;
     95    return HTMLCollection::IsRootedAtNode;
    9696}
    9797
  • trunk/Source/WebCore/html/HTMLCollection.h

    r165103 r166407  
    101101    size_t memoryCost() const { return m_indexCache.memoryCost() + (m_namedElementCache ? m_namedElementCache->memoryCost() : 0); }
    102102
    103     bool isRootedAtDocument() const { return m_rootType == NodeListIsRootedAtDocument; }
     103    enum RootType {
     104        IsRootedAtNode,
     105        IsRootedAtDocument
     106    };
     107    bool isRootedAtDocument() const { return m_rootType == IsRootedAtDocument; }
    104108    NodeListInvalidationType invalidationType() const { return static_cast<NodeListInvalidationType>(m_invalidationType); }
    105109    CollectionType type() const { return static_cast<CollectionType>(m_collectionType); }
     
    134138    bool usesCustomForwardOnlyTraversal() const { return m_usesCustomForwardOnlyTraversal; }
    135139
    136     NodeListRootType rootType() const { return static_cast<NodeListRootType>(m_rootType); }
     140    RootType rootType() const { return static_cast<RootType>(m_rootType); }
    137141
    138142    CollectionNamedElementCache& createNameItemCache() const
  • trunk/Source/WebCore/html/LabelsNodeList.cpp

    r166377 r166407  
    33 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    44 *           (C) 2001 Dirk Mueller (mueller@kde.org)
    5  * Copyright (C) 2004, 2007, 2008 Apple Inc. All rights reserved.
     5 * Copyright (C) 2004, 2007, 2008, 2014 Apple Inc. All rights reserved.
    66 * Copyright (C) 2010 Nokia Inc. All rights reserved.
    77 *
     
    3535
    3636LabelsNodeList::LabelsNodeList(LabelableElement& forNode)
    37     : CachedLiveNodeList(forNode, InvalidateOnForAttrChange, NodeListIsRootedAtDocument)
     37    : CachedLiveNodeList(forNode, InvalidateOnForAttrChange)
    3838{
    3939}
  • trunk/Source/WebCore/html/LabelsNodeList.h

    r166377 r166407  
    33 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    44 *           (C) 2001 Dirk Mueller (mueller@kde.org)
    5  * Copyright (C) 2004, 2007 Apple Inc. All rights reserved.
     5 * Copyright (C) 2004, 2007, 2014 Apple Inc. All rights reserved.
    66 * Copyright (C) 2010 Nokia Inc. All rights reserved.
    77 *
     
    4040
    4141    virtual bool nodeMatches(Element*) const override;
     42    virtual bool isRootedAtDocument() const override { return true; }
    4243
    4344private:
  • trunk/Source/WebCore/html/RadioNodeList.cpp

    r166377 r166407  
    11/*
    22 * Copyright (c) 2012 Motorola Mobility, Inc. All rights reserved.
     3 * Copyright (C) 2014 Apple Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3940
    4041RadioNodeList::RadioNodeList(ContainerNode& rootNode, const AtomicString& name)
    41     : CachedLiveNodeList(rootNode, InvalidateForFormControls, isHTMLFormElement(rootNode) ? NodeListIsRootedAtDocument : NodeListIsRootedAtNode)
     42    : CachedLiveNodeList(rootNode, InvalidateForFormControls)
    4243    , m_name(name)
     44    , m_isRootedAtDocument(isHTMLFormElement(ownerNode()))
    4345{
    4446}
  • trunk/Source/WebCore/html/RadioNodeList.h

    r166377 r166407  
    11/*
    22 * Copyright (c) 2012 Motorola Mobility, Inc. All rights reserved.
     3 * Copyright (C) 2014 Apple Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    4647
    4748    virtual bool nodeMatches(Element*) const override;
     49    virtual bool isRootedAtDocument() const override { return m_isRootedAtDocument; }
    4850
    4951private:
     
    5254
    5355    AtomicString m_name;
     56    bool m_isRootedAtDocument;
    5457};
    5558
Note: See TracChangeset for help on using the changeset viewer.