Source/WebCore/ChangeLog

 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 NOBODY (OOPS!).
 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 Dana Jansens <danakj@chromium.org>
235
336 [chromium] Remove the RenderPass pointer from RenderPassDrawQuad
122529

Source/WebCore/dom/DynamicNodeList.h

2424#ifndef DynamicNodeList_h
2525#define DynamicNodeList_h
2626
 27#include "CollectionType.h"
2728#include "Document.h"
2829#include "NodeList.h"
2930#include <wtf/Forward.h>

@@public:
3940 DynamicNodeListCacheBase(NodeListRootType rootType, NodeListInvalidationType invalidationType)
4041 : m_rootedAtDocument(rootType == NodeListIsRootedAtDocument)
4142 , m_invalidationType(invalidationType)
 43 , m_collectionType(InvalidCollectionType)
4244 {
4345 ASSERT(m_invalidationType == static_cast<unsigned>(invalidationType));
4446 clearCache();
4547 }
4648
 49 DynamicNodeListCacheBase(CollectionType collectionType)
 50 : m_collectionType(collectionType)
 51 {
 52 ASSERT(m_collectionType == static_cast<unsigned>(collectionType));
 53 clearCache();
 54 }
 55
4756public:
4857 ALWAYS_INLINE bool isRootedAtDocument() const { return m_rootedAtDocument; }
4958 ALWAYS_INLINE bool shouldInvalidateOnAttributeChange() const { return m_invalidationType != DoNotInvalidateOnAttributeChanges; }
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:
5464 ALWAYS_INLINE bool isItemCacheValid() const { return m_isItemCacheValid; }

@@protected:
7080 m_isItemCacheValid = true;
7181 }
7282
 83 bool hasNameCache() const { return m_isNameCacheValid; }
 84 void setHasNameCache() const { m_isNameCacheValid = true; }
 85
7386 void clearCache() const
7487 {
7588 m_cachedItem = 0;
7689 m_isLengthCacheValid = false;
7790 m_isItemCacheValid = false;
 91 m_isNameCacheValid = false;
7892 }
7993
8094private:

@@private:
87101 // From DynamicNodeList
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
92110class DynamicNodeList : public NodeList, public DynamicNodeListCacheBase {
122519

Source/WebCore/html/HTMLCollection.cpp

@@namespace WebCore {
4040
4141using namespace HTMLNames;
4242
43 static bool shouldIncludeChildren(CollectionType type)
 43static bool shouldOnlyIncludeDirectChildren(CollectionType type)
4444{
4545 switch (type) {
4646 case DocAll:

@@static bool shouldIncludeChildren(Collec
6363 case ItemProperties:
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();
7476 return false;
7577}
7678
7779HTMLCollection::HTMLCollection(Node* base, CollectionType type)
78  : HTMLCollectionCacheBase(type, shouldIncludeChildren(type))
 80 : HTMLCollectionCacheBase(type)
7981 , m_base(base)
8082{
8183 ASSERT(m_base);

@@inline bool HTMLCollection::isAcceptable
170172 case DocumentNamedItems:
171173 case TableRows:
172174 case WindowNamedItems:
 175 case InvalidCollectionType:
173176 ASSERT_NOT_REACHED();
174177 }
175178 return false;
176179}
177180
178 static Node* nextNodeOrSibling(Node* base, Node* node, bool includeChildren)
 181static ALWAYS_INLINE Node* nextNode(Node* base, Node* previous, bool onlyIncludeDirectChildren)
179182{
180  return includeChildren ? node->traverseNextNode(base) : node->traverseNextSibling(base);
 183 return onlyIncludeDirectChildren ? previous->traverseNextSibling(base) : previous->traverseNextNode(base);
181184}
182185
183186Element* HTMLCollection::itemAfter(unsigned& offsetInArray, Element* previous) const
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
200198 return 0;
122519

Source/WebCore/html/HTMLCollection.h

@@class NodeList;
3939
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 }
5248
53  CollectionType type() const { return static_cast<CollectionType>(m_type); }
54 
5549protected:
5650 void clearCache(uint64_t currentDomTreeVersion) const
5751 {

@@protected:
6054 m_nameCache.clear();
6155 m_cachedElementsArrayOffset = 0;
6256 m_cacheTreeVersion = currentDomTreeVersion;
63  m_hasNameCache = false;
6457 }
6558
6659 void setItemCache(Node* item, unsigned offset, unsigned elementsArrayOffset) const

@@protected:
7063 }
7164 unsigned cachedElementsArrayOffset() const { return m_cachedElementsArrayOffset; }
7265
73  bool includeChildren() const { return m_includeChildren; }
7466 uint64_t cacheTreeVersion() const { return m_cacheTreeVersion; }
7567
7668 typedef HashMap<AtomicStringImpl*, OwnPtr<Vector<Element*> > > NodeCacheMap;

@@protected:
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); }
8173
82  bool hasNameCache() const { return m_hasNameCache; }
83  void setHasNameCache() const { m_hasNameCache = true; }
84 
8574 static void append(NodeCacheMap&, const AtomicString&, Element*);
8675
8776private:

@@private:
9483 mutable NodeCacheMap m_nameCache;
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
10488class HTMLCollection : public RefCounted<HTMLCollection>, public HTMLCollectionCacheBase {
122519