Changeset 122531 in webkit
- Timestamp:
- Jul 12, 2012 5:20:46 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r122530 r122531 1 2012-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 1 34 2012-07-12 Shinya Kawanaka <shinyak@chromium.org> 2 35 -
trunk/Source/WebCore/dom/DynamicNodeList.h
r122518 r122531 25 25 #define DynamicNodeList_h 26 26 27 #include "CollectionType.h" 27 28 #include "Document.h" 28 29 #include "NodeList.h" … … 40 41 : m_rootedAtDocument(rootType == NodeListIsRootedAtDocument) 41 42 , m_invalidationType(invalidationType) 43 , m_collectionType(InvalidCollectionType) 42 44 { 43 45 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)); 44 53 clearCache(); 45 54 } … … 50 59 ALWAYS_INLINE NodeListRootType rootType() { return m_rootedAtDocument ? NodeListIsRootedAtDocument : NodeListIsRootedAtNode; } 51 60 ALWAYS_INLINE NodeListInvalidationType invalidationType() const { return static_cast<NodeListInvalidationType>(m_invalidationType); } 61 ALWAYS_INLINE CollectionType type() const { return static_cast<CollectionType>(m_collectionType); } 52 62 53 63 protected: … … 71 81 } 72 82 83 bool hasNameCache() const { return m_isNameCacheValid; } 84 void setHasNameCache() const { m_isNameCacheValid = true; } 85 73 86 void clearCache() const 74 87 { … … 76 89 m_isLengthCacheValid = false; 77 90 m_isItemCacheValid = false; 91 m_isNameCacheValid = false; 78 92 } 79 93 … … 88 102 const unsigned m_rootedAtDocument : 1; 89 103 const unsigned m_invalidationType : 3; 104 105 // From HTMLCollection 106 mutable unsigned m_isNameCacheValid : 1; 107 const unsigned m_collectionType : 5; 90 108 }; 91 109 -
trunk/Source/WebCore/html/CollectionType.h
r122115 r122531 61 61 #endif 62 62 63 FormControls 63 FormControls, 64 InvalidCollectionType 64 65 }; 65 66 -
trunk/Source/WebCore/html/HTMLCollection.cpp
r122518 r122531 41 41 using namespace HTMLNames; 42 42 43 static bool should IncludeChildren(CollectionType type)43 static bool shouldOnlyIncludeDirectChildren(CollectionType type) 44 44 { 45 45 switch (type) { … … 64 64 #endif 65 65 case FormControls: 66 return true;66 return false; 67 67 case NodeChildren: 68 68 case TRCells: 69 69 case TSectionRows: 70 70 case TableTBodies: 71 return false; 71 return true; 72 case InvalidCollectionType: 73 break; 72 74 } 73 75 ASSERT_NOT_REACHED(); … … 76 78 77 79 HTMLCollection::HTMLCollection(Node* base, CollectionType type) 78 : HTMLCollectionCacheBase(type , shouldIncludeChildren(type))80 : HTMLCollectionCacheBase(type) 79 81 , m_base(base) 80 82 { … … 171 173 case TableRows: 172 174 case WindowNamedItems: 175 case InvalidCollectionType: 173 176 ASSERT_NOT_REACHED(); 174 177 } … … 176 179 } 177 180 178 static Node* nextNodeOrSibling(Node* base, Node* node, bool includeChildren)179 { 180 return includeChildren ? node->traverseNextNode(base) : node->traverseNextSibling(base);181 static ALWAYS_INLINE Node* nextNode(Node* base, Node* previous, bool onlyIncludeDirectChildren) 182 { 183 return onlyIncludeDirectChildren ? previous->traverseNextSibling(base) : previous->traverseNextNode(base); 181 184 } 182 185 … … 184 187 { 185 188 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); 198 196 } 199 197 -
trunk/Source/WebCore/html/HTMLCollection.h
r122518 r122531 40 40 class HTMLCollectionCacheBase : public DynamicNodeListCacheBase { 41 41 public: 42 HTMLCollectionCacheBase(CollectionType type , bool includeChildren)43 : DynamicNodeListCacheBase( NodeListIsRootedAtNode, DoNotInvalidateOnAttributeChanges) // These two flags are never used42 HTMLCollectionCacheBase(CollectionType type) 43 : DynamicNodeListCacheBase(type) 44 44 , m_cachedElementsArrayOffset(0) 45 45 , m_cacheTreeVersion(0) 46 , m_hasNameCache(false)47 , m_type(type)48 , m_includeChildren(includeChildren)49 46 { 50 ASSERT(static_cast<CollectionType>(m_type) == type);51 47 } 52 53 CollectionType type() const { return static_cast<CollectionType>(m_type); }54 48 55 49 protected: … … 61 55 m_cachedElementsArrayOffset = 0; 62 56 m_cacheTreeVersion = currentDomTreeVersion; 63 m_hasNameCache = false;64 57 } 65 58 … … 71 64 unsigned cachedElementsArrayOffset() const { return m_cachedElementsArrayOffset; } 72 65 73 bool includeChildren() const { return m_includeChildren; }74 66 uint64_t cacheTreeVersion() const { return m_cacheTreeVersion; } 75 67 … … 79 71 void appendIdCache(const AtomicString& name, Element* element) const { append(m_idCache, name, element); } 80 72 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; }84 73 85 74 static void append(NodeCacheMap&, const AtomicString&, Element*); … … 95 84 mutable unsigned m_cachedElementsArrayOffset; 96 85 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; // CollectionType101 const unsigned m_includeChildren : 1;102 86 }; 103 87
Note: See TracChangeset
for help on using the changeset viewer.