From kde-commits Mon Oct 22 16:35:01 2007 From: Germain Garand Date: Mon, 22 Oct 2007 16:35:01 +0000 To: kde-commits Subject: KDE/kdelibs/khtml/xml Message-Id: <1193070901.438432.26315.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=119307094815075 SVN commit 728184 by ggarand: Cache the document element: now that we have comments in dom, it can be slow to walk the tree each and every time. Adapted from similar change in WC r15247 by Timothy Hatcher M +25 -4 dom_docimpl.cpp M +3 -0 dom_docimpl.h --- trunk/KDE/kdelibs/khtml/xml/dom_docimpl.cpp #728183:728184 @@ -376,6 +376,7 @@ m_docLoading = false; m_inSyncLoad = false; m_loadingXMLDoc = 0; + m_documentElement = 0; m_cssTarget = 0; m_dynamicDomRestyler = new khtml::DynamicDomRestyler(); } @@ -420,6 +421,11 @@ m_activeNode->deref(); m_activeNode = 0; } + + if (m_documentElement) { + m_documentElement->deref(); + m_documentElement = 0; + } removeChildren(); @@ -468,6 +474,8 @@ m_hoverNode->deref(); if (m_activeNode) m_activeNode->deref(); + if (m_documentElement) + m_documentElement->deref(); m_renderArena.reset(); @@ -485,12 +493,25 @@ return m_implementation; } +void DocumentImpl::childrenChanged() +{ + // invalidate the document element we have cached in case it was replaced + if (m_documentElement) + m_documentElement->deref(); + m_documentElement = 0; +} + ElementImpl *DocumentImpl::documentElement() const { - NodeImpl *n = firstChild(); - while (n && n->nodeType() != Node::ELEMENT_NODE) - n = n->nextSibling(); - return static_cast(n); + if (!m_documentElement) { + NodeImpl* n = firstChild(); + while (n && n->nodeType() != Node::ELEMENT_NODE) + n = n->nextSibling(); + m_documentElement = static_cast(n); + if (m_documentElement) + m_documentElement->ref(); + } + return m_documentElement; } ElementImpl *DocumentImpl::createElement( const DOMString &name, int* pExceptioncode ) --- trunk/KDE/kdelibs/khtml/xml/dom_docimpl.h #728183:728184 @@ -190,6 +190,7 @@ DOMImplementationImpl *implementation() const; ElementImpl *documentElement() const; + virtual void childrenChanged(); virtual ElementImpl *createElement ( const DOMString &tagName, int* pExceptioncode = 0 ); virtual AttrImpl *createAttribute( const DOMString &tagName, int* pExceptioncode = 0 ); DocumentFragmentImpl *createDocumentFragment (); @@ -650,6 +651,8 @@ DOMString m_title; DOMString m_preferredStylesheetSet; khtml::CachedCSSStyleSheet *m_loadingXMLDoc; + + mutable ElementImpl* m_documentElement; //int m_decoderMibEnum;