[webkit-changes] cvs commit: WebCore/layout-tests/fast/dom
gc-5-expected.txt gc-5.html
Maciej
mjs at opensource.apple.com
Wed Jul 13 21:48:45 PDT 2005
mjs 05/07/13 21:48:45
Modified: . ChangeLog
khtml/ecma kjs_binding.cpp kjs_binding.h kjs_window.h
xmlhttprequest.h
khtml/misc hashtable.h
Added: layout-tests/fast/dom gc-5-expected.txt gc-5.html
Log:
Reviewed by Kevin.
- convert some more things to use the new hashtable
* khtml/ecma/kjs_binding.cpp:
(KJS::domObjects):
(KJS::domNodesPerDocument):
(KJS::ScriptInterpreter::getDOMObject):
(KJS::ScriptInterpreter::putDOMObject):
(KJS::ScriptInterpreter::deleteDOMObject):
(KJS::ScriptInterpreter::forgetDOMObject):
(KJS::ScriptInterpreter::getDOMNodeForDocument):
(KJS::ScriptInterpreter::forgetDOMNodeForDocument):
(KJS::ScriptInterpreter::putDOMNodeForDocument):
(KJS::ScriptInterpreter::forgetAllDOMNodesForDocument):
(KJS::ScriptInterpreter::mark):
(KJS::ScriptInterpreter::updateDOMNodeDocument):
* khtml/ecma/kjs_binding.h:
* khtml/ecma/kjs_window.h: Include QPtrDict header
* khtml/ecma/xmlhttprequest.h: ditto
- fix a bug with remove of a nonexistent key - it used to trash
the table
* khtml/misc/hashtable.h:
(khtml::::remove):
Revision Changes Path
1.4420 +29 -0 WebCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/WebCore/ChangeLog,v
retrieving revision 1.4419
retrieving revision 1.4420
diff -u -r1.4419 -r1.4420
--- ChangeLog 14 Jul 2005 02:32:30 -0000 1.4419
+++ ChangeLog 14 Jul 2005 04:48:40 -0000 1.4420
@@ -1,3 +1,32 @@
+2005-07-12 Maciej Stachowiak <mjs at apple.com>
+
+ Reviewed by Kevin.
+
+ - convert some more things to use the new hashtable
+
+ * khtml/ecma/kjs_binding.cpp:
+ (KJS::domObjects):
+ (KJS::domNodesPerDocument):
+ (KJS::ScriptInterpreter::getDOMObject):
+ (KJS::ScriptInterpreter::putDOMObject):
+ (KJS::ScriptInterpreter::deleteDOMObject):
+ (KJS::ScriptInterpreter::forgetDOMObject):
+ (KJS::ScriptInterpreter::getDOMNodeForDocument):
+ (KJS::ScriptInterpreter::forgetDOMNodeForDocument):
+ (KJS::ScriptInterpreter::putDOMNodeForDocument):
+ (KJS::ScriptInterpreter::forgetAllDOMNodesForDocument):
+ (KJS::ScriptInterpreter::mark):
+ (KJS::ScriptInterpreter::updateDOMNodeDocument):
+ * khtml/ecma/kjs_binding.h:
+ * khtml/ecma/kjs_window.h: Include QPtrDict header
+ * khtml/ecma/xmlhttprequest.h: ditto
+
+ - fix a bug with remove of a nonexistent key - it used to trash
+ the table
+
+ * khtml/misc/hashtable.h:
+ (khtml::::remove):
+
2005-07-13 Justin Garcia <justin.garcia at apple.com>
Reviewed by mjs
1.33 +68 -49 WebCore/khtml/ecma/kjs_binding.cpp
Index: kjs_binding.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/ecma/kjs_binding.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- kjs_binding.cpp 31 May 2005 01:20:46 -0000 1.32
+++ kjs_binding.cpp 14 Jul 2005 04:48:44 -0000 1.33
@@ -29,6 +29,7 @@
#include "dom/dom_exception.h"
#include "dom/dom2_events.h"
#include "dom/dom2_range.h"
+#include "misc/hashmap.h"
#include "xml/dom_nodeimpl.h"
#include "xml/dom2_eventsimpl.h"
#include "dom/css_stylesheet.h"
@@ -37,8 +38,11 @@
using DOM::CSSException;
using DOM::DOMString;
+using DOM::DocumentImpl;
using DOM::NodeImpl;
using DOM::RangeException;
+using khtml::HashMap;
+using khtml::PointerHash;
namespace KJS {
@@ -76,24 +80,20 @@
return tryCall(exec, thisObj, args);
}
-static QPtrDict<DOMObject> * staticDomObjects = 0;
-QPtrDict< QPtrDict<DOMNode> > * staticDOMNodesPerDocument = 0;
+typedef HashMap<void *, DOMObject *> DOMObjectMap;
+typedef HashMap<NodeImpl *, DOMNode *, PointerHash<NodeImpl *> > NodeMap;
+typedef HashMap<DocumentImpl *, NodeMap *, PointerHash<DocumentImpl *> > NodePerDocMap;
-QPtrDict<DOMObject> & ScriptInterpreter::domObjects()
-{
- if (!staticDomObjects) {
- staticDomObjects = new QPtrDict<DOMObject>(1021);
- }
- return *staticDomObjects;
+static DOMObjectMap *domObjects()
+{
+ static DOMObjectMap* staticDomObjects = new DOMObjectMap();
+ return staticDomObjects;
}
-QPtrDict< QPtrDict<DOMNode> > & ScriptInterpreter::domNodesPerDocument()
+static NodePerDocMap *domNodesPerDocument()
{
- if (!staticDOMNodesPerDocument) {
- staticDOMNodesPerDocument = new QPtrDict<QPtrDict<DOMNode> >();
- staticDOMNodesPerDocument->setAutoDelete(true);
- }
- return *staticDOMNodesPerDocument;
+ static NodePerDocMap *staticDOMNodesPerDocument = new NodePerDocMap();
+ return staticDOMNodesPerDocument;
}
@@ -113,62 +113,81 @@
#endif
}
-void ScriptInterpreter::forgetDOMObject( void* objectHandle )
+DOMObject* ScriptInterpreter::getDOMObject(void* objectHandle)
+{
+ return domObjects()->get(objectHandle);
+}
+
+void ScriptInterpreter::putDOMObject(void* objectHandle, DOMObject* obj)
{
- deleteDOMObject( objectHandle );
+ domObjects()->insert(objectHandle, obj);
+}
+
+void ScriptInterpreter::deleteDOMObject(void* objectHandle)
+{
+ domObjects()->remove(objectHandle);
+}
+
+void ScriptInterpreter::forgetDOMObject(void* objectHandle)
+{
+ deleteDOMObject(objectHandle);
}
DOMNode *ScriptInterpreter::getDOMNodeForDocument(DOM::DocumentImpl *document, DOM::NodeImpl *node)
{
- QPtrDict<DOMNode> *documentDict = (QPtrDict<DOMNode> *)domNodesPerDocument()[document];
- if (documentDict)
- return (*documentDict)[node];
+ NodeMap *documentDict = domNodesPerDocument()->get(document);
+ if (documentDict)
+ return documentDict->get(node);
- return NULL;
+ return NULL;
}
void ScriptInterpreter::forgetDOMNodeForDocument(DOM::DocumentImpl *document, NodeImpl *node)
{
- QPtrDict<DOMNode> *documentDict = domNodesPerDocument()[document];
- if (documentDict)
- documentDict->remove(node);
+ NodeMap *documentDict = domNodesPerDocument()->get(document);
+ if (documentDict)
+ documentDict->remove(node);
}
void ScriptInterpreter::putDOMNodeForDocument(DOM::DocumentImpl *document, NodeImpl *nodeHandle, DOMNode *nodeWrapper)
{
- QPtrDict<DOMNode> *documentDict = domNodesPerDocument()[document];
- if (!documentDict) {
- documentDict = new QPtrDict<DOMNode>();
- domNodesPerDocument().insert(document, documentDict);
- }
-
- documentDict->insert(nodeHandle, nodeWrapper);
+ NodeMap *documentDict = domNodesPerDocument()->get(document);
+ if (!documentDict) {
+ documentDict = new NodeMap();
+ domNodesPerDocument()->insert(document, documentDict);
+ }
+ documentDict->insert(nodeHandle, nodeWrapper);
}
void ScriptInterpreter::forgetAllDOMNodesForDocument(DOM::DocumentImpl *document)
{
- domNodesPerDocument().remove(document);
+ NodePerDocMap::iterator it = domNodesPerDocument()->find(document);
+ if (it != domNodesPerDocument()->end()) {
+ delete it->second;
+ domNodesPerDocument()->remove(it);
+ }
}
void ScriptInterpreter::mark()
{
- QPtrDictIterator<QPtrDict<DOMNode> > dictIterator(domNodesPerDocument());
-
- QPtrDict<DOMNode> *nodeDict;
- while ((nodeDict = dictIterator.current())) {
- QPtrDictIterator<DOMNode> nodeIterator(*nodeDict);
-
- DOMNode *node;
- while ((node = nodeIterator.current())) {
- // don't mark wrappers for nodes that are no longer in the
- // document - they should not be saved if the node is not
- // otherwise reachable from JS.
- if (node->impl()->inDocument() && !node->marked())
- node->mark();
-
- ++nodeIterator;
- }
- ++dictIterator;
+ NodePerDocMap::iterator dictEnd = domNodesPerDocument()->end();
+ for (NodePerDocMap::iterator dictIt = domNodesPerDocument()->begin();
+ dictIt != dictEnd;
+ ++dictIt) {
+
+ NodeMap *nodeDict = dictIt->second;
+ NodeMap::iterator nodeEnd = nodeDict->end();
+ for (NodeMap::iterator nodeIt = nodeDict->begin();
+ nodeIt != nodeEnd;
+ ++nodeIt) {
+
+ DOMNode *node = nodeIt->second;
+ // don't mark wrappers for nodes that are no longer in the
+ // document - they should not be saved if the node is not
+ // otherwise reachable from JS.
+ if (node->impl()->inDocument() && !node->marked())
+ node->mark();
+ }
}
}
@@ -176,7 +195,7 @@
{
DOMNode *cachedObject = getDOMNodeForDocument(oldDoc, node);
if (cachedObject)
- putDOMNodeForDocument(newDoc, node, cachedObject);
+ putDOMNodeForDocument(newDoc, node, cachedObject);
}
bool ScriptInterpreter::wasRunByUserGesture() const
1.29 +5 -19 WebCore/khtml/ecma/kjs_binding.h
Index: kjs_binding.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/ecma/kjs_binding.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- kjs_binding.h 1 Jul 2005 18:56:38 -0000 1.28
+++ kjs_binding.h 14 Jul 2005 04:48:44 -0000 1.29
@@ -24,7 +24,6 @@
#include <kjs/interpreter.h>
#include <qvariant.h>
-#include <qptrdict.h>
#include <kjs/lookup.h>
#include <kjs/protect.h>
@@ -95,21 +94,13 @@
class ScriptInterpreter : public Interpreter
{
public:
- ScriptInterpreter( const Object &global, KHTMLPart* part );
+ ScriptInterpreter(const Object &global, KHTMLPart* part);
virtual ~ScriptInterpreter();
- static DOMObject* getDOMObject( void* objectHandle ) {
- return domObjects()[objectHandle];
- }
- static void putDOMObject( void* objectHandle, DOMObject* obj ) {
- domObjects().insert( objectHandle, obj );
- }
- static bool deleteDOMObject( void* objectHandle ) {
- return domObjects().remove( objectHandle );
- }
-
- static void forgetDOMObject( void* objectHandle );
-
+ static DOMObject* getDOMObject(void* objectHandle);
+ static void putDOMObject(void* objectHandle, DOMObject* obj);
+ static void deleteDOMObject(void* objectHandle);
+ static void forgetDOMObject(void* objectHandle);
static DOMNode *getDOMNodeForDocument(DOM::DocumentImpl *document, DOM::NodeImpl *node);
static void putDOMNodeForDocument(DOM::DocumentImpl *document, DOM::NodeImpl *nodeHandle, DOMNode *nodeWrapper);
@@ -117,8 +108,6 @@
static void forgetAllDOMNodesForDocument(DOM::DocumentImpl *document);
static void updateDOMNodeDocument(DOM::NodeImpl *nodeHandle, DOM::DocumentImpl *oldDoc, DOM::DocumentImpl *newDoc);
-
-
KHTMLPart* part() const { return m_part; }
virtual int rtti() { return 1; }
@@ -149,9 +138,6 @@
private:
KHTMLPart* m_part;
- static QPtrDict<DOMObject> &domObjects();
- static QPtrDict<QPtrDict<DOMNode> > &domNodesPerDocument();
-
DOM::EventImpl *m_evt;
bool m_inlineCode;
bool m_timerCallback;
1.45 +1 -0 WebCore/khtml/ecma/kjs_window.h
Index: kjs_window.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/ecma/kjs_window.h,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- kjs_window.h 3 Jul 2005 10:47:56 -0000 1.44
+++ kjs_window.h 14 Jul 2005 04:48:44 -0000 1.45
@@ -25,6 +25,7 @@
#include <qobject.h>
#include <qguardedptr.h>
#include <qmap.h>
+#include <qptrdict.h>
#include "kjs_binding.h"
1.14 +1 -0 WebCore/khtml/ecma/xmlhttprequest.h
Index: xmlhttprequest.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/ecma/xmlhttprequest.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- xmlhttprequest.h 28 May 2005 00:42:55 -0000 1.13
+++ xmlhttprequest.h 14 Jul 2005 04:48:44 -0000 1.14
@@ -24,6 +24,7 @@
#include <qguardedptr.h>
#include <qobject.h>
#include <kurl.h>
+#include <qptrdict.h>
#include "kjs_dom.h"
1.10 +5 -2 WebCore/khtml/misc/hashtable.h
Index: hashtable.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/misc/hashtable.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- hashtable.h 9 Jul 2005 20:19:16 -0000 1.9
+++ hashtable.h 14 Jul 2005 04:48:44 -0000 1.10
@@ -394,7 +394,7 @@
#if DUMP_HASHTABLE_STATS
++HashTableStats::numRemoves;
#endif
-
+
deleteBucket(*pos);
++m_deletedCount;
--m_keyCount;
@@ -411,12 +411,15 @@
if (!m_table)
return;
- remove(lookup(key).first);
+ remove(find(key));
}
template<typename Key, typename Value, Key ExtractKey(const Value &), typename HashFunctions, typename Traits>
inline void HashTable<Key, Value, ExtractKey, HashFunctions, Traits>::remove(iterator it)
{
+ if (it == end())
+ return;
+
remove(it.m_position);
}
1.1 WebCore/layout-tests/fast/dom/gc-5-expected.txt
Index: gc-5-expected.txt
===================================================================
This test verifies that DOM nodes are not retained just because a wrapper exists and is protected for a sibling. A wrapper must exist for the node itself or for an ancestor.
The output should be the following pieces of text on lines by themselves: "replacement content", "B".
replacement content
B
1.1 WebCore/layout-tests/fast/dom/gc-5.html
Index: gc-5.html
===================================================================
<head>
<script>
function doit()
{
var B = document.getElementById("span-B");
B.customProperty = "B";
B.nextSibling.customProperty = "D";
document.getElementById("div").innerHTML = "<span>replacement content</span>";
// create lots of objects to force a garbage collection
var i = 0;
while (i < 1000) {
i = i+1;
}
var output= document.getElementById("output");
output.innerHTML += B.customProperty + "<BR>";
if (B.nextSibling) {
output.innerHTML += B.nextSibling.customProperty + "<BR>";
}
}
if (window.layoutTestController) {
layoutTestController.dumpAsText();
}
</script>
</head>
<body onload="doit()">
<div style="border: 1px solid red">
<p>
This test verifies that DOM nodes are not retained just because a wrapper exists and is protected for a sibling. A wrapper must exist for the node itself or for an ancestor.
</p>
<p>
The output should be the following pieces of text on lines by themselves: "replacement content", "B".
</p>
</div>
<div id="div">
<span id="span-A"><span id="span-B"><span id="span-C">original span</span></span>
<span id="span-D"> xx </span>
</span>
</div>
<div id="output">
</div>
</body>
More information about the webkit-changes
mailing list