You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by le...@apache.org on 2001/01/17 18:46:03 UTC
cvs commit: xml-xerces/c/src/dom CommonParentNode.cpp CommonParentNode.hpp DocumentImpl.cpp DocumentImpl.hpp NodeImpl.cpp
lehors 01/01/17 09:46:03
Modified: c/src/dom CommonParentNode.cpp CommonParentNode.hpp
DocumentImpl.cpp DocumentImpl.hpp NodeImpl.cpp
Log:
We used to have a change counter on a node basis, so that we knew what
subtree changed. But since only DeepNodeList really use this today,
the gain appears to be really small compared to the cost of having
an int on every (parent) node plus having to walk up the tree all the
way to the root to mark the branch as changed everytime a node is
changed.
So we now have a single counter global to the document. It means that
some objects may flush their cache more often than necessary, but this
makes nodes smaller and only the document needs to be marked as changed.
Revision Changes Path
1.6 +1 -20 xml-xerces/c/src/dom/CommonParentNode.cpp
Index: CommonParentNode.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/dom/CommonParentNode.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CommonParentNode.cpp 2000/08/17 23:02:17 1.5
+++ CommonParentNode.cpp 2001/01/17 17:46:01 1.6
@@ -55,7 +55,7 @@
*/
/*
- * $Id: CommonParentNode.cpp,v 1.5 2000/08/17 23:02:17 lehors Exp $
+ * $Id: CommonParentNode.cpp,v 1.6 2001/01/17 17:46:01 lehors Exp $
*/
@@ -65,8 +65,6 @@
{
this->ownerDocument = ownerDoc;
this->firstChild = null;
-
- fChanges = 0;
};
// This only makes a shallow copy, cloneChildren must also be called for a
@@ -78,8 +76,6 @@
// Need to break the association w/ original kids
this->firstChild = null;
-
- fChanges = 0;
};
@@ -108,21 +104,6 @@
child->setOwnerDocument(doc);
}
}
-
-
-void THIS_CLASS::changed()
-{
- ++fChanges;
- NodeImpl *parentNode = getParentNode();
- if (parentNode != null) {
- parentNode->changed();
- }
-};
-
-int THIS_CLASS::changes()
-{
- return fChanges;
-};
NodeListImpl *THIS_CLASS::getChildNodes() {
1.3 +1 -6 xml-xerces/c/src/dom/CommonParentNode.hpp
Index: CommonParentNode.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/dom/CommonParentNode.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CommonParentNode.hpp 2000/08/17 22:47:08 1.2
+++ CommonParentNode.hpp 2001/01/17 17:46:01 1.3
@@ -64,7 +64,7 @@
//
/*
- * $Id: CommonParentNode.hpp,v 1.2 2000/08/17 22:47:08 lehors Exp $
+ * $Id: CommonParentNode.hpp,v 1.3 2001/01/17 17:46:01 lehors Exp $
*/
/**
@@ -85,17 +85,12 @@
ChildNode *firstChild;
- int fChanges;
-
public:
THIS_CLASS(DocumentImpl *ownerDocument);
THIS_CLASS(const THIS_CLASS &other);
virtual DocumentImpl * getOwnerDocument();
virtual void setOwnerDocument(DocumentImpl *doc);
-
- virtual int changes();
- virtual void changed();
virtual NodeListImpl *getChildNodes();
virtual NodeImpl * getFirstChild();
1.32 +18 -2 xml-xerces/c/src/dom/DocumentImpl.cpp
Index: DocumentImpl.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/dom/DocumentImpl.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- DocumentImpl.cpp 2000/08/17 22:47:09 1.31
+++ DocumentImpl.cpp 2001/01/17 17:46:01 1.32
@@ -55,7 +55,7 @@
*/
/*
- * $Id: DocumentImpl.cpp,v 1.31 2000/08/17 22:47:09 lehors Exp $
+ * $Id: DocumentImpl.cpp,v 1.32 2001/01/17 17:46:01 lehors Exp $
*/
//
@@ -103,7 +103,7 @@
fNodeIDMap = 0;
userData = 0;
ranges = 0;
-
+ fChanges = 0;
};
@@ -125,6 +125,7 @@
fNodeIDMap = 0;
userData = 0;
ranges = 0;
+ fChanges = 0;
}
void DocumentImpl::setDocumentType(DocumentTypeImpl *doctype)
@@ -816,3 +817,18 @@
else
hasUserData(false);
};
+
+/**
+ * Denotes that this node has changed.
+ */
+void DocumentImpl::changed() {
+ fChanges++;
+}
+
+/**
+ * Returns the number of changes to this node.
+ */
+int DocumentImpl::changes() {
+ return fChanges;
+}
+
1.21 +40 -1 xml-xerces/c/src/dom/DocumentImpl.hpp
Index: DocumentImpl.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/dom/DocumentImpl.hpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- DocumentImpl.hpp 2000/07/28 01:33:31 1.20
+++ DocumentImpl.hpp 2001/01/17 17:46:01 1.21
@@ -58,7 +58,7 @@
*/
/*
- * $Id: DocumentImpl.hpp,v 1.20 2000/07/28 01:33:31 aruna1 Exp $
+ * $Id: DocumentImpl.hpp,v 1.21 2001/01/17 17:46:01 lehors Exp $
*/
//
@@ -124,6 +124,42 @@
RefHashTableOf<void> *userData;
RangeImpls *ranges;
+ /**
+ * Number of alterations made to this document since its creation.
+ * Serves as a "dirty bit" so that live objects such as NodeList can
+ * recognize when an alteration has been made and discard its cached
+ * state information.
+ * <p>
+ * Any method that alters the tree structure MUST cause or be
+ * accompanied by a call to changed(), to inform it that any outstanding
+ * NodeLists may have to be updated.
+ * <p>
+ * (Required because NodeList is simultaneously "live" and integer-
+ * indexed -- a bad decision in the DOM's design.)
+ * <p>
+ * Note that changes which do not affect the tree's structure -- changing
+ * the node's name, for example -- do _not_ have to call changed().
+ * <p>
+ * Alternative implementation would be to use a cryptographic
+ * Digest value rather than a count. This would have the advantage that
+ * "harmless" changes (those producing equal() trees) would not force
+ * NodeList to resynchronize. Disadvantage is that it's slightly more prone
+ * to "false negatives", though that's the difference between "wildly
+ * unlikely" and "absurdly unlikely". IF we start maintaining digests,
+ * we should consider taking advantage of them.
+ *
+ * Note: This used to be done a node basis, so that we knew what
+ * subtree changed. But since only DeepNodeList really use this today,
+ * the gain appears to be really small compared to the cost of having
+ * an int on every (parent) node plus having to walk up the tree all the
+ * way to the root to mark the branch as changed everytime a node is
+ * changed.
+ * So we now have a single counter global to the document. It means that
+ * some objects may flush their cache more often than necessary, but this
+ * makes nodes smaller and only the document needs to be marked as changed.
+ */
+ int fChanges;
+
friend class NodeIteratorImpl;
friend class TreeWalkerImpl;
friend class RangeImpl;
@@ -194,6 +230,9 @@
static bool isKidOK(NodeImpl *parent, NodeImpl *child);
inline NodeIDMap * getNodeIDMap() {return fNodeIDMap;};
+
+ virtual void changed();
+ virtual int changes();
};
#endif
1.32 +10 -6 xml-xerces/c/src/dom/NodeImpl.cpp
Index: NodeImpl.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/dom/NodeImpl.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- NodeImpl.cpp 2001/01/17 17:25:53 1.31
+++ NodeImpl.cpp 2001/01/17 17:46:02 1.32
@@ -55,7 +55,7 @@
*/
/*
- * $Id: NodeImpl.cpp,v 1.31 2001/01/17 17:25:53 lehors Exp $
+ * $Id: NodeImpl.cpp,v 1.32 2001/01/17 17:46:02 lehors Exp $
*/
// This class doesn't support having any children, and implements the behavior
@@ -144,15 +144,19 @@
bool NodeImpl::isTextImpl() {return false;};
-void NodeImpl::changed() {} // overridden in subclasses
+void NodeImpl::changed() {
+ // we do not actually store this information on every node, we only
+ // have a global indicator on the Document. Doing otherwise cost us too
+ // much for little gain.
+ getDocument()->changed();
+}
int NodeImpl::changes()
{
- // overridden in subclasses
-// throw new RuntimeException(
-// "changes() called on a NodeImpl or one of its subclasses" +
-// "which doesn't really implement it");
- return 0;
+ // we do not actually store this information on every node, we only
+ // have a global indicator on the Document. Doing otherwise cost us too
+ // much for little gain.
+ return getDocument()->changes();
};