Changeset 28868
- Timestamp:
- 12/19/07 12:11:09 (12 months ago)
- Location:
- trunk/WebCore
- Files:
-
- 14 modified
-
ChangeLog (modified) (1 diff)
-
dom/ChildNodeList.cpp (modified) (1 diff)
-
dom/ClassNodeList.cpp (modified) (1 diff)
-
dom/ClassNodeList.h (modified) (2 diffs)
-
dom/Document.cpp (modified) (1 diff)
-
dom/Document.h (modified) (1 diff)
-
dom/Element.cpp (modified) (1 diff)
-
dom/Element.h (modified) (1 diff)
-
dom/NameNodeList.cpp (modified) (2 diffs)
-
dom/NameNodeList.h (modified) (2 diffs)
-
dom/Node.cpp (modified) (9 diffs)
-
dom/Node.h (modified) (5 diffs)
-
dom/NodeList.cpp (modified) (1 diff)
-
dom/NodeList.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r28867 r28868 1 2007-12-19 Sam Weinig <sam@webkit.org> 2 3 Reviewed by Maciej. 4 5 http://bugs.webkit.org/show_bug.cgi?id=16511 6 Speed up ClassNodeList and NamedNodeList by using the caching mechanism employed by ChildNodeList. 7 - This give a ~2.15x speedup on the native test @ http://ejohn.org/apps/classname/ 8 9 * dom/ChildNodeList.cpp: Use the caching NodeList constructor to turn on caching. 10 (WebCore::ChildNodeList::ChildNodeList): 11 * dom/ClassNodeList.cpp: 12 (WebCore::ClassNodeList::ClassNodeList): 13 * dom/ClassNodeList.h: 14 15 Move getElementsByName and getElementsByClassName to Node so they 16 can use easily employ the caching already used by ChildNodeLists. In the case of 17 getElementsByClassName, this reduces code duplication in Element as well 18 * dom/Document.cpp: 19 * dom/Document.h: 20 21 Move getElementsByClassName to Node. 22 * dom/Element.cpp: 23 * dom/Element.h: 24 25 * dom/NameNodeList.cpp: Use the caching NodeList constructor to turn on caching. 26 (WebCore::NameNodeList::NameNodeList): 27 (WebCore::NameNodeList::item): 28 * dom/NameNodeList.h: 29 30 Add maps of caches for ClassNodeLists and NameNodeList to NodeListsNodeData. 31 * dom/Node.cpp: 32 (WebCore::TagNodeList::TagNodeList): 33 (WebCore::Node::Node): 34 (WebCore::Node::~Node): 35 (WebCore::Node::childNodes): 36 (WebCore::Node::registerNodeList): 37 (WebCore::Node::getElementsByName): 38 (WebCore::Node::getElementsByClassName): 39 * dom/Node.h: Make m_nodeLists an OwnPtr. Moved getElementsByName and getElementsByClassName here 40 41 Allow subclasses to choose whether they want to receive the notifications using a new bit. 42 * dom/NodeList.cpp: 43 (WebCore::NodeList::NodeList): 44 * dom/NodeList.h: 45 (WebCore::NodeList::needsNotifications): 46 1 47 2007-12-19 Dave Hyatt <hyatt@apple.com> 2 48 -
trunk/WebCore/dom/ChildNodeList.cpp
r25754 r28868 32 32 33 33 ChildNodeList::ChildNodeList(Node* n, NodeList::Caches* info) 34 : NodeList(n, info )34 : NodeList(n, info, false) 35 35 { 36 36 } -
trunk/WebCore/dom/ClassNodeList.cpp
r28722 r28868 37 37 namespace WebCore { 38 38 39 ClassNodeList::ClassNodeList(PassRefPtr<Node> rootNode, const AtomicString& className)40 : NodeList(rootNode )39 ClassNodeList::ClassNodeList(PassRefPtr<Node> rootNode, const String& classNames, NodeList::Caches* caches) 40 : NodeList(rootNode, caches, true) 41 41 { 42 m_classNames.parseClassAttribute(className , m_rootNode->document()->inCompatMode());42 m_classNames.parseClassAttribute(classNames, m_rootNode->document()->inCompatMode()); 43 43 } 44 44 -
trunk/WebCore/dom/ClassNodeList.h
r28722 r28868 31 31 #define ClassNodeList_h 32 32 33 #include "AtomicString.h"34 33 #include "ClassNames.h" 35 34 #include "NodeList.h" … … 37 36 namespace WebCore { 38 37 38 class String; 39 39 40 class ClassNodeList : public NodeList { 40 41 public: 41 ClassNodeList(PassRefPtr<Node> rootNode, const AtomicString& className);42 ClassNodeList(PassRefPtr<Node> rootNode, const String& classNames, NodeList::Caches*); 42 43 43 44 virtual unsigned length() const; -
trunk/WebCore/dom/Document.cpp
r28867 r28868 3497 3497 } 3498 3498 3499 PassRefPtr<NameNodeList> Document::getElementsByName(const String& elementName)3500 {3501 return new NameNodeList(this, elementName);3502 }3503 3504 PassRefPtr<NodeList> Document::getElementsByClassName(const String& className)3505 {3506 return new ClassNodeList(this, className);3507 }3508 3509 3499 void Document::finishedParsing() 3510 3500 { -
trunk/WebCore/dom/Document.h
r28722 r28868 212 212 213 213 PassRefPtr<Node> adoptNode(PassRefPtr<Node> source, ExceptionCode&); 214 215 PassRefPtr<NameNodeList> getElementsByName(const String& elementName);216 PassRefPtr<NodeList> getElementsByClassName(const String& className);217 214 218 215 PassRefPtr<HTMLCollection> images(); -
trunk/WebCore/dom/Element.cpp
r28722 r28868 1124 1124 } 1125 1125 1126 PassRefPtr<NodeList> Element::getElementsByClassName(const String& className)1127 {1128 return new ClassNodeList(this, className);1129 }1130 1131 1126 void Element::cancelFocusAppearanceUpdate() 1132 1127 { -
trunk/WebCore/dom/Element.h
r28722 r28868 163 163 virtual void updateFocusAppearance(bool restorePreviousSelection); 164 164 void blur(); 165 166 PassRefPtr<NodeList> getElementsByClassName(const String&);167 165 168 166 #ifndef NDEBUG -
trunk/WebCore/dom/NameNodeList.cpp
r28722 r28868 31 31 using namespace HTMLNames; 32 32 33 NameNodeList::NameNodeList(Node* root, const String& name )34 : NodeList(root )33 NameNodeList::NameNodeList(Node* root, const String& name, NodeList::Caches* caches) 34 : NodeList(root, caches, true) 35 35 , m_nodeName(name) 36 36 { … … 42 42 } 43 43 44 Node* NameNodeList::item (unsigned index) const44 Node* NameNodeList::item(unsigned index) const 45 45 { 46 46 return recursiveItem(index); -
trunk/WebCore/dom/NameNodeList.h
r28722 r28868 34 34 class NameNodeList : public NodeList { 35 35 public: 36 NameNodeList(Node* root, const String& name );36 NameNodeList(Node* root, const String& name, NodeList::Caches*); 37 37 38 38 // DOM methods overridden from parent classes … … 42 42 43 43 // Other methods (not part of DOM) 44 44 45 virtual void rootNodeAttributeChanged() { NodeList::rootNodeChildrenChanged(); } 45 46 -
trunk/WebCore/dom/Node.cpp
r28110 r28868 27 27 #include "CString.h" 28 28 #include "ChildNodeList.h" 29 #include "ClassNodeList.h" 29 30 #include "DOMImplementation.h" 30 31 #include "Document.h" … … 33 34 #include "Frame.h" 34 35 #include "HTMLNames.h" 36 #include "HTMLNames.h" 35 37 #include "KURL.h" 36 38 #include "Logging.h" 39 #include "NameNodeList.h" 37 40 #include "NamedAttrMap.h" 38 41 #include "RenderObject.h" … … 51 54 NodeListSet m_listsToNotify; 52 55 NodeList::Caches m_childNodeListCaches; 56 HashMap<String, NodeList::Caches> m_classNodeListCaches; 57 HashMap<String, NodeList::Caches> m_nameNodeListCaches; 53 58 }; 54 59 … … 69 74 70 75 inline TagNodeList::TagNodeList(PassRefPtr<Node> rootNode, const AtomicString& namespaceURI, const AtomicString& localName) 71 : NodeList(rootNode), m_namespaceURI(namespaceURI), m_localName(localName) 76 : NodeList(rootNode, true) 77 , m_namespaceURI(namespaceURI) 78 , m_localName(localName) 72 79 { 73 80 ASSERT(m_namespaceURI.isNull() || !m_namespaceURI.isEmpty()); … … 139 146 m_next(0), 140 147 m_renderer(0), 141 m_nodeLists(0),142 148 m_tabIndex(0), 143 149 m_hasId(false), … … 192 198 if (renderer()) 193 199 detach(); 194 delete m_nodeLists; 200 195 201 if (m_previous) 196 202 m_previous->setNextSibling(0); … … 218 224 { 219 225 if (!m_nodeLists) 220 m_nodeLists = new NodeListsNodeData;226 m_nodeLists.set(new NodeListsNodeData); 221 227 222 228 return new ChildNodeList(this, &m_nodeLists->m_childNodeListCaches); … … 439 445 { 440 446 if (!m_nodeLists) 441 m_nodeLists = new NodeListsNodeData;447 m_nodeLists.set(new NodeListsNodeData); 442 448 else if (!m_document->hasNodeLists()) 443 449 // We haven't been receiving notifications while there were no registered lists, so the cache is invalid now. … … 1206 1212 name = localName.lower(); 1207 1213 return new TagNodeList(this, namespaceURI.isEmpty() ? nullAtom : AtomicString(namespaceURI), name); 1214 } 1215 1216 PassRefPtr<NodeList> Node::getElementsByName(const String& elementName) 1217 { 1218 if (!m_nodeLists) 1219 m_nodeLists.set(new NodeListsNodeData); 1220 1221 return new NameNodeList(this, elementName, &m_nodeLists->m_nameNodeListCaches.add(elementName, NodeList::Caches()).first->second); 1222 } 1223 1224 PassRefPtr<NodeList> Node::getElementsByClassName(const String& classNames) 1225 { 1226 if (!m_nodeLists) 1227 m_nodeLists.set(new NodeListsNodeData); 1228 1229 return new ClassNodeList(this, classNames, &m_nodeLists->m_classNodeListCaches.add(classNames, NodeList::Caches()).first->second); 1208 1230 } 1209 1231 -
trunk/WebCore/dom/Node.h
r28110 r28868 25 25 #define Node_h 26 26 27 #include "DeprecatedString.h" 27 28 #include "DocPtr.h" 28 #include "DeprecatedString.h"29 29 #include "PlatformString.h" 30 30 #include "TreeShared.h" 31 31 #include <wtf/Assertions.h> 32 32 #include <wtf/HashSet.h> 33 #include <wtf/OwnPtr.h> 33 34 #include <wtf/PassRefPtr.h> 34 35 … … 45 46 class NamedAttrMap; 46 47 class NodeList; 47 struct NodeListsNodeData;48 48 class PlatformKeyboardEvent; 49 49 class PlatformMouseEvent; … … 55 55 class RenderStyle; 56 56 class TextStream; 57 struct NodeListsNodeData; 57 58 58 59 typedef int ExceptionCode; … … 452 453 PassRefPtr<NodeList> getElementsByTagNameNS(const String& namespaceURI, const String& localName); 453 454 455 PassRefPtr<NodeList> getElementsByName(const String& elementName); 456 PassRefPtr<NodeList> getElementsByClassName(const String& classNames); 457 454 458 private: // members 455 459 DocPtr<Document> m_document; … … 462 466 virtual void didMoveToNewOwnerDocument() { } 463 467 464 NodeListsNodeData*m_nodeLists;468 OwnPtr<NodeListsNodeData> m_nodeLists; 465 469 466 470 short m_tabIndex; -
trunk/WebCore/dom/NodeList.cpp
r25754 r28868 31 31 namespace WebCore { 32 32 33 NodeList::NodeList(PassRefPtr<Node> rootNode )33 NodeList::NodeList(PassRefPtr<Node> rootNode, bool needsNotifications) 34 34 : m_rootNode(rootNode) 35 35 , m_caches(new Caches) 36 36 , m_ownsCaches(true) 37 , m_needsNotifications(needsNotifications) 37 38 { 38 39 m_rootNode->registerNodeList(this); 39 40 } 40 41 41 NodeList::NodeList(PassRefPtr<Node> rootNode, NodeList::Caches* info )42 NodeList::NodeList(PassRefPtr<Node> rootNode, NodeList::Caches* info, bool needsNotifications) 42 43 : m_rootNode(rootNode) 43 44 , m_caches(info) 44 45 , m_ownsCaches(false) 46 , m_needsNotifications(needsNotifications) 45 47 { 46 48 m_rootNode->registerNodeList(this); -
trunk/WebCore/dom/NodeList.h
r27983 r28868 50 50 }; 51 51 52 NodeList(PassRefPtr<Node> rootNode );53 NodeList(PassRefPtr<Node> rootNode, Caches* );52 NodeList(PassRefPtr<Node> rootNode, bool needsNotifications); 53 NodeList(PassRefPtr<Node> rootNode, Caches*, bool needsNotifications); 54 54 virtual ~NodeList(); 55 55 56 bool needsNotifications() const { return m_ ownsCaches; }56 bool needsNotifications() const { return m_needsNotifications; } 57 57 58 58 // DOM methods & attributes for NodeList … … 74 74 mutable Caches* m_caches; 75 75 bool m_ownsCaches; 76 bool m_needsNotifications; 76 77 77 78 private: