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...@locus.apache.org on 2000/07/07 22:33:08 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/dom ChildAndParentNode.java ChildNode.java DocumentImpl.java NodeImpl.java ParentNode.java

lehors      00/07/07 13:33:08

  Modified:    java/src/org/apache/xerces/dom ChildAndParentNode.java
                        ChildNode.java DocumentImpl.java NodeImpl.java
                        ParentNode.java
  Log:
  Yet another change to make the DOM smaller:
  We used to have a change count on every (parent) node, 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.9       +1 -42     xml-xerces/java/src/org/apache/xerces/dom/ChildAndParentNode.java
  
  Index: ChildAndParentNode.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/ChildAndParentNode.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ChildAndParentNode.java	2000/07/07 00:36:08	1.8
  +++ ChildAndParentNode.java	2000/07/07 20:33:07	1.9
  @@ -1,4 +1,4 @@
  -/* $Id: ChildAndParentNode.java,v 1.8 2000/07/07 00:36:08 lehors Exp $ */
  +/* $Id: ChildAndParentNode.java,v 1.9 2000/07/07 20:33:07 lehors Exp $ */
   /*
    * The Apache Software License, Version 1.1
    *
  @@ -83,31 +83,6 @@
       /** First child. */
       protected ChildNode firstChild = null;
   
  -    /**
  -     * Number of alterations made to this subtree since its creation.
  -     * Serves as a "dirty bit" so 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 and its
  -     * parents 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.
  -     */
  -    protected int changes = 0;
  -
       // transients
   
       /** Cached node list length. */
  @@ -849,22 +824,6 @@
       //
       // Protected methods
       //
  -
  -    /** Denotes that this node has changed. */
  -    protected void changed() {
  -    	++changes;
  -        // invalidate cache for children NodeList
  -        nodeListIndex = -1;
  -        nodeListLength = -1;
  -        NodeImpl parentNode = parentNode();
  -    	if (parentNode != null) {
  -            parentNode.changed();
  -        }
  -    }
  -
  -    protected int changes() {
  -        return changes;
  -    }
   
       /**
        * Override this method in subclass to hook in efficient
  
  
  
  1.3       +0 -13     xml-xerces/java/src/org/apache/xerces/dom/ChildNode.java
  
  Index: ChildNode.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/ChildNode.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ChildNode.java	2000/07/07 00:36:08	1.2
  +++ ChildNode.java	2000/07/07 20:33:07	1.3
  @@ -185,17 +185,4 @@
           return isFirstChild() ? null : previousSibling;
       }
   
  -    //
  -    // Protected methods
  -    //
  -
  -    /** Denotes that this node has changed. */
  -    protected void changed() {
  -        // ++changes; we just let the parent know
  -        NodeImpl parentNode = parentNode();
  -    	if (parentNode != null) {
  -            parentNode.changed();
  -        }
  -    }
  -
   } // class ChildNode
  
  
  
  1.33      +50 -0     xml-xerces/java/src/org/apache/xerces/dom/DocumentImpl.java
  
  Index: DocumentImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DocumentImpl.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- DocumentImpl.java	2000/07/07 00:36:11	1.32
  +++ DocumentImpl.java	2000/07/07 20:33:07	1.33
  @@ -134,6 +134,42 @@
       /** Table for quick check of child insertion. */
       protected Hashtable userData;
   
  +    /**
  +     * 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.
  +     */
  +    protected int changes = 0;
  +
       // experimental
   
       /** Allow grammar access. */
  @@ -1468,6 +1504,20 @@
               return child.getNodeType() == Node.ELEMENT_NODE;
           }
       	return 0 != (kidOK[parent.getNodeType()] & 1 << child.getNodeType());
  +    }
  +
  +    /**
  +     * Denotes that this node has changed.
  +     */
  +    protected void changed() {
  +        changes++;
  +    }
  +
  +    /**
  +     * Returns the number of changes to this node.
  +     */
  +    protected int changes() {
  +        return changes;
       }
   
   } // class DocumentImpl
  
  
  
  1.27      +10 -5     xml-xerces/java/src/org/apache/xerces/dom/NodeImpl.java
  
  Index: NodeImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/NodeImpl.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- NodeImpl.java	2000/07/07 00:36:13	1.26
  +++ NodeImpl.java	2000/07/07 20:33:07	1.27
  @@ -1244,16 +1244,21 @@
       /**
        * Denotes that this node has changed.
        */
  -    protected void changed() {} // overridden in subclasses
  +    protected void 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.
  +        ownerDocument().changed();
  +    }
   
       /**
        * Returns the number of changes to this node.
        */
       protected int changes() {
  -        // overridden in subclasses
  -        throw new RuntimeException(
  -                    "changes() called on a NodeImpl or one of its subclasses" +
  -                    "which doesn't really implement it");
  +        // 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 ownerDocument().changes();
       }
   
       /**
  
  
  
  1.9       +1 -42     xml-xerces/java/src/org/apache/xerces/dom/ParentNode.java
  
  Index: ParentNode.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/ParentNode.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ParentNode.java	2000/07/07 00:36:14	1.8
  +++ ParentNode.java	2000/07/07 20:33:07	1.9
  @@ -1,4 +1,4 @@
  -/* $Id: ParentNode.java,v 1.8 2000/07/07 00:36:14 lehors Exp $ */
  +/* $Id: ParentNode.java,v 1.9 2000/07/07 20:33:07 lehors Exp $ */
   /*
    * The Apache Software License, Version 1.1
    *
  @@ -93,31 +93,6 @@
       /** First child. */
       protected ChildNode firstChild = null;
   
  -    /**
  -     * Number of alterations made to this subtree since its creation.
  -     * Serves as a "dirty bit" so 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 and its
  -     * parents 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.
  -     */
  -    protected int changes = 0;
  -
       // transients
   
       /** Cached node list length. */
  @@ -859,22 +834,6 @@
       //
       // Protected methods
       //
  -
  -    /** Denotes that this node has changed. */
  -    protected void changed() {
  -    	++changes;
  -        // invalidate cache for children NodeList
  -        nodeListIndex = -1;
  -        nodeListLength = -1;
  -        NodeImpl parentNode = parentNode();
  -    	if (parentNode != null) {
  -            parentNode.changed();
  -        }
  -    }
  -
  -    protected int changes() {
  -        return changes;
  -    }
   
       /**
        * Override this method in subclass to hook in efficient