Changeset 122531 in webkit


Ignore:
Timestamp:
Jul 12, 2012 5:20:46 PM (12 years ago)
Author:
rniwa@webkit.org
Message:

Move m_type and m_hasNameCache from HTMLCollectionCacheBase to DynamicNodeListCacheBase for better bit packing
https://bugs.webkit.org/show_bug.cgi?id=91164

Reviewed by Anders Carlsson.

Moved m_type and m_hasNameCache from HTMLCollection and renamed them to m_collectionType and m_isNameCacheValid.

Also renamed shouldIncludeChildren to shouldOnlyIncludeDirectChildren and negated the return value since
all HTMLCollection include children in the collection and the function was meant to tell us whether the collection
should include descendents that are not direct children of base().

In addition, renamed nextNodeOrSibling to nextNode since "or sibling" doesn't seem to add any semantic clarity.

  • dom/DynamicNodeList.h:

(WebCore::DynamicNodeListCacheBase::DynamicNodeListCacheBase):
(DynamicNodeListCacheBase):
(WebCore::DynamicNodeListCacheBase::type):
(WebCore::DynamicNodeListCacheBase::hasNameCache):
(WebCore::DynamicNodeListCacheBase::setHasNameCache):
(WebCore::DynamicNodeListCacheBase::clearCache):

  • html/HTMLCollection.cpp:

(WebCore::shouldOnlyIncludeDirectChildren):
(WebCore::HTMLCollection::HTMLCollection):
(WebCore::HTMLCollection::isAcceptableElement):
(WebCore::nextNode):
(WebCore::HTMLCollection::itemAfter):

  • html/HTMLCollection.h:

(WebCore::HTMLCollectionCacheBase::HTMLCollectionCacheBase):
(HTMLCollectionCacheBase):
(WebCore::HTMLCollectionCacheBase::clearCache):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r122530 r122531  
     12012-07-12  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Move m_type and m_hasNameCache from HTMLCollectionCacheBase to DynamicNodeListCacheBase for better bit packing
     4        https://bugs.webkit.org/show_bug.cgi?id=91164
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Moved m_type and m_hasNameCache from HTMLCollection and renamed them to m_collectionType and m_isNameCacheValid.
     9
     10        Also renamed shouldIncludeChildren to shouldOnlyIncludeDirectChildren and negated the return value since
     11        all HTMLCollection include children in the collection and the function was meant to tell us whether the collection
     12        should include descendents that are not direct children of base().
     13
     14        In addition, renamed nextNodeOrSibling to nextNode since "or sibling" doesn't seem to add any semantic clarity.
     15
     16        * dom/DynamicNodeList.h:
     17        (WebCore::DynamicNodeListCacheBase::DynamicNodeListCacheBase):
     18        (DynamicNodeListCacheBase):
     19        (WebCore::DynamicNodeListCacheBase::type):
     20        (WebCore::DynamicNodeListCacheBase::hasNameCache):
     21        (WebCore::DynamicNodeListCacheBase::setHasNameCache):
     22        (WebCore::DynamicNodeListCacheBase::clearCache):
     23        * html/HTMLCollection.cpp:
     24        (WebCore::shouldOnlyIncludeDirectChildren):
     25        (WebCore::HTMLCollection::HTMLCollection):
     26        (WebCore::HTMLCollection::isAcceptableElement):
     27        (WebCore::nextNode):
     28        (WebCore::HTMLCollection::itemAfter):
     29        * html/HTMLCollection.h:
     30        (WebCore::HTMLCollectionCacheBase::HTMLCollectionCacheBase):
     31        (HTMLCollectionCacheBase):
     32        (WebCore::HTMLCollectionCacheBase::clearCache):
     33
    1342012-07-12  Shinya Kawanaka  <shinyak@chromium.org>
    235
  • trunk/Source/WebCore/dom/DynamicNodeList.h

    r122518 r122531  
    2525#define DynamicNodeList_h
    2626
     27#include "CollectionType.h"
    2728#include "Document.h"
    2829#include "NodeList.h"
     
    4041        : m_rootedAtDocument(rootType == NodeListIsRootedAtDocument)
    4142        , m_invalidationType(invalidationType)
     43        , m_collectionType(InvalidCollectionType)
    4244    {
    4345        ASSERT(m_invalidationType == static_cast<unsigned>(invalidationType));
     46        clearCache();
     47    }
     48
     49    DynamicNodeListCacheBase(CollectionType collectionType)
     50        : m_collectionType(collectionType)
     51    {
     52        ASSERT(m_collectionType == static_cast<unsigned>(collectionType));
    4453        clearCache();
    4554    }
     
    5059    ALWAYS_INLINE NodeListRootType rootType() { return m_rootedAtDocument ? NodeListIsRootedAtDocument : NodeListIsRootedAtNode; }
    5160    ALWAYS_INLINE NodeListInvalidationType invalidationType() const { return static_cast<NodeListInvalidationType>(m_invalidationType); }
     61    ALWAYS_INLINE CollectionType type() const { return static_cast<CollectionType>(m_collectionType); }
    5262
    5363protected:
     
    7181    }
    7282
     83    bool hasNameCache() const { return m_isNameCacheValid; }
     84    void setHasNameCache() const { m_isNameCacheValid = true; }
     85
    7386    void clearCache() const
    7487    {
     
    7689        m_isLengthCacheValid = false;
    7790        m_isItemCacheValid = false;
     91        m_isNameCacheValid = false;
    7892    }
    7993
     
    88102    const unsigned m_rootedAtDocument : 1;
    89103    const unsigned m_invalidationType : 3;
     104
     105    // From HTMLCollection
     106    mutable unsigned m_isNameCacheValid : 1;
     107    const unsigned m_collectionType : 5;
    90108};
    91109
  • trunk/Source/WebCore/html/CollectionType.h

    r122115 r122531  
    6161#endif
    6262
    63     FormControls
     63    FormControls,
     64    InvalidCollectionType
    6465};
    6566
  • trunk/Source/WebCore/html/HTMLCollection.cpp

    r122518 r122531  
    4141using namespace HTMLNames;
    4242
    43 static bool shouldIncludeChildren(CollectionType type)
     43static bool shouldOnlyIncludeDirectChildren(CollectionType type)
    4444{
    4545    switch (type) {
     
    6464#endif
    6565    case FormControls:
    66         return true;
     66        return false;
    6767    case NodeChildren:
    6868    case TRCells:
    6969    case TSectionRows:
    7070    case TableTBodies:
    71         return false;
     71        return true;
     72    case InvalidCollectionType:
     73        break;
    7274    }
    7375    ASSERT_NOT_REACHED();
     
    7678
    7779HTMLCollection::HTMLCollection(Node* base, CollectionType type)
    78     : HTMLCollectionCacheBase(type, shouldIncludeChildren(type))
     80    : HTMLCollectionCacheBase(type)
    7981    , m_base(base)
    8082{
     
    171173    case TableRows:
    172174    case WindowNamedItems:
     175    case InvalidCollectionType:
    173176        ASSERT_NOT_REACHED();
    174177    }
     
    176179}
    177180
    178 static Node* nextNodeOrSibling(Node* base, Node* node, bool includeChildren)
    179 {
    180     return includeChildren ? node->traverseNextNode(base) : node->traverseNextSibling(base);
     181static ALWAYS_INLINE Node* nextNode(Node* base, Node* previous, bool onlyIncludeDirectChildren)
     182{
     183    return onlyIncludeDirectChildren ? previous->traverseNextSibling(base) : previous->traverseNextNode(base);
    181184}
    182185
     
    184187{
    185188    ASSERT_UNUSED(offsetInArray, !offsetInArray);
    186     Node* current;
    187     if (!previous)
    188         current = m_base->firstChild();
    189     else
    190         current = nextNodeOrSibling(base(), previous, includeChildren());
    191 
    192     for (; current; current = nextNodeOrSibling(base(), current, includeChildren())) {
    193         if (!current->isElementNode())
    194             continue;
    195         Element* element = static_cast<Element*>(current);
    196         if (isAcceptableElement(element))
    197             return element;
     189    bool onlyIncludeDirectChildren = shouldOnlyIncludeDirectChildren(type());
     190    Node* rootNode = base();
     191    Node* current = previous ? nextNode(rootNode, previous, onlyIncludeDirectChildren) : m_base->firstChild();
     192
     193    for (; current; current = nextNode(rootNode, current, onlyIncludeDirectChildren)) {
     194        if (current->isElementNode() && isAcceptableElement(toElement(current)))
     195            return toElement(current);
    198196    }
    199197
  • trunk/Source/WebCore/html/HTMLCollection.h

    r122518 r122531  
    4040class HTMLCollectionCacheBase : public DynamicNodeListCacheBase {
    4141public:
    42     HTMLCollectionCacheBase(CollectionType type, bool includeChildren)
    43         : DynamicNodeListCacheBase(NodeListIsRootedAtNode, DoNotInvalidateOnAttributeChanges) // These two flags are never used
     42    HTMLCollectionCacheBase(CollectionType type)
     43        : DynamicNodeListCacheBase(type)
    4444        , m_cachedElementsArrayOffset(0)
    4545        , m_cacheTreeVersion(0)
    46         , m_hasNameCache(false)
    47         , m_type(type)
    48         , m_includeChildren(includeChildren)
    4946    {
    50         ASSERT(static_cast<CollectionType>(m_type) == type);
    5147    }
    52 
    53     CollectionType type() const { return static_cast<CollectionType>(m_type); }
    5448
    5549protected:
     
    6155        m_cachedElementsArrayOffset = 0;
    6256        m_cacheTreeVersion = currentDomTreeVersion;
    63         m_hasNameCache = false;
    6457    }
    6558
     
    7164    unsigned cachedElementsArrayOffset() const { return m_cachedElementsArrayOffset; }
    7265
    73     bool includeChildren() const { return m_includeChildren; }
    7466    uint64_t cacheTreeVersion() const { return m_cacheTreeVersion; }
    7567
     
    7971    void appendIdCache(const AtomicString& name, Element* element) const { append(m_idCache, name, element); }
    8072    void appendNameCache(const AtomicString& name, Element* element) const { append(m_nameCache, name, element); }
    81 
    82     bool hasNameCache() const { return m_hasNameCache; }
    83     void setHasNameCache() const { m_hasNameCache = true; }
    8473
    8574    static void append(NodeCacheMap&, const AtomicString&, Element*);
     
    9584    mutable unsigned m_cachedElementsArrayOffset;
    9685    mutable uint64_t m_cacheTreeVersion;
    97 
    98     // FIXME: Move these bit flags to DynamicNodeListCacheBase to pack them better.
    99     mutable unsigned m_hasNameCache : 1;
    100     const unsigned m_type : 5; // CollectionType
    101     const unsigned m_includeChildren : 1;
    10286};
    10387
Note: See TracChangeset for help on using the changeset viewer.