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/08/18 03:58:36 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/dom AttrImpl.java AttributeMap.java ChildAndParentNode.java DeferredDocumentImpl.java DeferredDocumentTypeImpl.java DeferredElementDefinitionImpl.java DeferredEntityReferenceImpl.java DocumentImpl.java NodeImpl.java ParentNode.java

lehors      00/08/17 18:58:36

  Modified:    java/src/org/apache/xerces/dom AttrImpl.java
                        AttributeMap.java ChildAndParentNode.java
                        DeferredDocumentImpl.java
                        DeferredDocumentTypeImpl.java
                        DeferredElementDefinitionImpl.java
                        DeferredEntityReferenceImpl.java DocumentImpl.java
                        NodeImpl.java ParentNode.java
  Log:
  added a flag on the document to store whether mutation events
  need to be fired. This is off by default and turned on when an event
  handler is registered. It is also turned off during synchronization
  in the Deferred case.
  Tests show a performance gain of up to 20% in the non deferred case!
  
  Revision  Changes    Path
  1.21      +3 -3      xml-xerces/java/src/org/apache/xerces/dom/AttrImpl.java
  
  Index: AttrImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/AttrImpl.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- AttrImpl.java	2000/07/07 00:36:07	1.20
  +++ AttrImpl.java	2000/08/18 01:58:34	1.21
  @@ -216,7 +216,7 @@
       		
           LCount lc=null;
           String oldvalue="";
  -        if(MUTATIONEVENTS)
  +        if(MUTATIONEVENTS && ownerDocument.mutationEvents)
           {
               // MUTATION PREPROCESSING AND PRE-EVENTS:
               // Only DOMAttrModified need be produced directly.
  @@ -230,7 +230,7 @@
               
           } // End mutation preprocessing
   
  -        if(MUTATIONEVENTS)
  +        if(MUTATIONEVENTS && ownerDocument.mutationEvents)
           {
               // Can no longer just discard the kids; they may have
               // event listeners waiting for them to disconnect.
  @@ -266,7 +266,7 @@
   		
       	changed(); // ***** Is this redundant?
   
  -        if(MUTATIONEVENTS)
  +        if(MUTATIONEVENTS && ownerDocument.mutationEvents)
           {
               // MUTATION POST-EVENTS:
               dispatchAggregateEvents(this,oldvalue);            
  
  
  
  1.5       +7 -4      xml-xerces/java/src/org/apache/xerces/dom/AttributeMap.java
  
  Index: AttributeMap.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/AttributeMap.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AttributeMap.java	2000/07/07 00:36:08	1.4
  +++ AttributeMap.java	2000/08/18 01:58:34	1.5
  @@ -144,7 +144,8 @@
               nodes.insertElementAt(arg, i);
           }
   
  -        if (NodeImpl.MUTATIONEVENTS) {
  +        if (NodeImpl.MUTATIONEVENTS &&
  +            ownerNode.ownerDocument().mutationEvents) {
               // MUTATION POST-EVENTS:
               ownerNode.dispatchAggregateEvents(
                   (AttrImpl)arg,
  @@ -214,7 +215,8 @@
   
       	// Only NamedNodeMaps containing attributes (those which are
       	// bound to an element) need report MutationEvents
  -        if (NodeImpl.MUTATIONEVENTS)
  +        if (NodeImpl.MUTATIONEVENTS
  +            && ownerNode.ownerDocument().mutationEvents)
           {
               // MUTATION POST-EVENTS:
               ownerNode.dispatchAggregateEvents(
  @@ -359,7 +361,8 @@
           LCount lc=null;
           String oldvalue="";
           AttrImpl enclosingAttribute=null;
  -        if (NodeImpl.MUTATIONEVENTS)
  +        if (NodeImpl.MUTATIONEVENTS
  +            && ownerNode.ownerDocument().mutationEvents)
           {
               // MUTATION PREPROCESSING AND PRE-EVENTS:
               lc=LCount.lookup(MutationEventImpl.DOM_ATTR_MODIFIED);
  @@ -409,7 +412,7 @@
           // We can't use the standard dispatchAggregate, since it assumes
           // that the Attr is still attached to an owner. This code is
           // similar but dispatches to the previous owner, "element".
  -        if(NodeImpl.MUTATIONEVENTS)
  +        if(NodeImpl.MUTATIONEVENTS && ownerNode.ownerDocument().mutationEvents)
           {
       	    // If we have to send DOMAttrModified (determined earlier),
               // do so.
  
  
  
  1.13      +15 -7     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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ChildAndParentNode.java	2000/07/19 00:58:33	1.12
  +++ ChildAndParentNode.java	2000/08/18 01:58:34	1.13
  @@ -1,4 +1,4 @@
  -/* $Id: ChildAndParentNode.java,v 1.12 2000/07/19 00:58:33 lehors Exp $ */
  +/* $Id: ChildAndParentNode.java,v 1.13 2000/08/18 01:58:34 lehors Exp $ */
   /*
    * The Apache Software License, Version 1.1
    *
  @@ -384,7 +384,8 @@
               ChildNode newInternal = (ChildNode)newChild;
   
               EnclosingAttr enclosingAttr=null;
  -            if(MUTATIONEVENTS && (mutationMask&MUTATION_AGGREGATE)!=0)
  +            if(MUTATIONEVENTS && ownerDocument.mutationEvents
  +               && (mutationMask&MUTATION_AGGREGATE)!=0)
               {
                   // MUTATION PREPROCESSING
                   // No direct pre-events, but if we're within the scope 
  @@ -462,7 +463,7 @@
                   }
               }
   
  -            if(MUTATIONEVENTS)
  +            if(MUTATIONEVENTS && ownerDocument.mutationEvents)
               {
                   // MUTATION POST-EVENTS:
                   // "Local" events (non-aggregated)
  @@ -573,7 +574,7 @@
           ChildNode oldInternal = (ChildNode) oldChild;
   
           EnclosingAttr enclosingAttr=null;
  -        if(MUTATIONEVENTS)
  +        if(MUTATIONEVENTS && ownerDocument.mutationEvents)
           {
               // MUTATION PREPROCESSING AND PRE-EVENTS:
               // If we're within the scope of an Attr and DOMAttrModified 
  @@ -678,7 +679,7 @@
   
           changed();
   
  -        if(MUTATIONEVENTS)
  +        if(MUTATIONEVENTS && ownerDocument.mutationEvents)
           {
               // MUTATION POST-EVENTS:
               // Subroutine: Transmit DOMAttrModified and DOMSubtreeModified,
  @@ -721,7 +722,7 @@
           // aggregations should be issued only once per user request.
   
           EnclosingAttr enclosingAttr=null;
  -        if(MUTATIONEVENTS)
  +        if(MUTATIONEVENTS && ownerDocument.mutationEvents)
           {
               // MUTATION PREPROCESSING AND PRE-EVENTS:
               // If we're within the scope of an Attr and DOMAttrModified 
  @@ -737,7 +738,7 @@
           internalInsertBefore(newChild, oldChild,MUTATION_LOCAL);
           internalRemoveChild(oldChild,MUTATION_LOCAL);
   
  -        if(MUTATIONEVENTS)
  +        if(MUTATIONEVENTS && ownerDocument.mutationEvents)
           {
               dispatchAggregateEvents(enclosingAttr);
           }
  @@ -882,6 +883,10 @@
        */
       protected final void synchronizeChildren(int nodeIndex) {
   
  +        // we don't want to generate any event for this so turn them off
  +        boolean orig = ownerDocument.mutationEvents;
  +        ownerDocument.mutationEvents = false;
  +
           // no need to sync in the future
           needsSyncChildren(false);
   
  @@ -911,6 +916,9 @@
               first.isFirstChild(true);
               lastChild(last);
           }
  +
  +        // set mutation events flag back to its original value
  +        ownerDocument.mutationEvents = orig;
   
       } // synchronizeChildren()
   
  
  
  
  1.20      +7 -0      xml-xerces/java/src/org/apache/xerces/dom/DeferredDocumentImpl.java
  
  Index: DeferredDocumentImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DeferredDocumentImpl.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- DeferredDocumentImpl.java	2000/07/07 00:36:09	1.19
  +++ DeferredDocumentImpl.java	2000/08/18 01:58:34	1.20
  @@ -1376,6 +1376,10 @@
               }
           }
   
  +        // we don't want to generate any event for this so turn them off
  +        boolean orig = mutationEvents;
  +        mutationEvents = false;
  +
           // no need to sync in the future
           needsSyncChildren(false);
   
  @@ -1415,6 +1419,9 @@
               first.isFirstChild(true);
               lastChild(last);
           }
  +
  +        // set mutation events flag back to its original value
  +        mutationEvents = orig;
   
       } // synchronizeChildren()
   
  
  
  
  1.9       +7 -0      xml-xerces/java/src/org/apache/xerces/dom/DeferredDocumentTypeImpl.java
  
  Index: DeferredDocumentTypeImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DeferredDocumentTypeImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DeferredDocumentTypeImpl.java	2000/07/07 00:36:10	1.8
  +++ DeferredDocumentTypeImpl.java	2000/08/18 01:58:34	1.9
  @@ -152,6 +152,10 @@
       /** Synchronizes the entities, notations, and elements. */
       protected void synchronizeChildren() {
   
  +        // we don't want to generate any event for this so turn them off
  +        boolean orig = ownerDocument().mutationEvents;
  +        ownerDocument().mutationEvents = false;
  +
           // no need to synchronize again
           needsSyncChildren(false);
   
  @@ -206,6 +210,9 @@
                   }
                }
           }
  +
  +        // set mutation events flag back to its original value
  +        ownerDocument().mutationEvents = orig;
   
       } // synchronizeChildren()
   
  
  
  
  1.6       +7 -0      xml-xerces/java/src/org/apache/xerces/dom/DeferredElementDefinitionImpl.java
  
  Index: DeferredElementDefinitionImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DeferredElementDefinitionImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DeferredElementDefinitionImpl.java	2000/07/07 00:36:10	1.5
  +++ DeferredElementDefinitionImpl.java	2000/08/18 01:58:34	1.6
  @@ -132,6 +132,10 @@
       /** Synchronizes the default attribute values. */
       protected void synchronizeChildren() {
   
  +        // we don't want to generate any event for this so turn them off
  +        boolean orig = ownerDocument.mutationEvents;
  +        ownerDocument.mutationEvents = false;
  +
           // attributes are now synced
           needsSyncChildren(false);
   
  @@ -148,6 +152,9 @@
               Node attr = ownerDocument.getNodeObject(nodeIndex);
               attributes.setNamedItem(attr);
           }
  +
  +        // set mutation events flag back to its original value
  +        ownerDocument.mutationEvents = orig;
   
       } // synchronizeChildren()
   
  
  
  
  1.8       +7 -0      xml-xerces/java/src/org/apache/xerces/dom/DeferredEntityReferenceImpl.java
  
  Index: DeferredEntityReferenceImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DeferredEntityReferenceImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DeferredEntityReferenceImpl.java	2000/08/17 01:02:01	1.7
  +++ DeferredEntityReferenceImpl.java	2000/08/18 01:58:34	1.8
  @@ -183,6 +183,11 @@
           DocumentType doctype = ownerDocument.getDoctype();
           boolean found = false;
           if (doctype != null) {
  +
  +            // we don't want to generate any event for this so turn them off
  +            boolean orig = ownerDocument.mutationEvents;
  +            ownerDocument.mutationEvents = false;
  +
               NamedNodeMap entities = doctype.getEntities();
               if (entities != null) {
                   Entity entity = (Entity)entities.getNamedItem(getNodeName());
  @@ -205,6 +210,8 @@
                       }
                   }
               }
  +            // set mutation events flag back to its original value
  +            ownerDocument().mutationEvents = orig;
           }
   
           // if not found, create entity at this reference
  
  
  
  1.39      +20 -1     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.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- DocumentImpl.java	2000/08/18 01:55:26	1.38
  +++ DocumentImpl.java	2000/08/18 01:58:34	1.39
  @@ -178,6 +178,9 @@
       /** Bypass error checking. */
       protected boolean errorChecking = true;
   
  +    /** Bypass mutation events firing. */
  +    protected boolean mutationEvents = false;
  +
       //
       // Static initialization
       //
  @@ -303,6 +306,7 @@
           // experimental
           newdoc.allowGrammarAccess = allowGrammarAccess;
           newdoc.errorChecking = errorChecking;
  +        newdoc.mutationEvents = mutationEvents;
   
           // return new document
       	return newdoc;
  @@ -359,7 +363,7 @@
        */
       public Node removeChild(Node oldChild)
           throws DOMException {
  -	    super.removeChild(oldChild);
  +        super.removeChild(oldChild);
   	
       	// If remove succeeded, un-cache the kid appropriately
           int type = oldChild.getNodeType();
  @@ -624,6 +628,21 @@
        */
       public boolean getErrorChecking() {
           return errorChecking;
  +    }
  +
  +    /** 
  +     * Sets whether the DOM implementation generates mutation events
  +     * upon operations.
  +     */
  +    public void setMutationEvents(boolean set) {
  +        mutationEvents = set;
  +    }
  +
  +    /**
  +     * Returns true if the DOM implementation generates mutation events.
  +     */
  +    public boolean getMutationEvents() {
  +        return mutationEvents;
       }
   
       // non-DOM factory methods
  
  
  
  1.30      +7 -3      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.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- NodeImpl.java	2000/07/20 18:31:31	1.29
  +++ NodeImpl.java	2000/08/18 01:58:34	1.30
  @@ -739,6 +739,10 @@
   	        ++lc.captures;
   	    else
   	        ++lc.bubbles;
  +
  +            // turn mutation events on
  +            ownerDocument().mutationEvents = true;
  +
   	} // addEventListener(String,EventListener,boolean) :void
   	
   	/** Introduced in DOM Level 2. <p>
  @@ -1024,7 +1028,7 @@
        */
       void dispatchEventToSubtree(ChildNode n,Event e)
       {
  -      if(MUTATIONEVENTS)
  +      if(MUTATIONEVENTS && ownerDocument().mutationEvents)
         {
   	    if(nodeListeners==null || n==null)
               return;
  @@ -1062,7 +1066,7 @@
   	 */
   	EnclosingAttr getEnclosingAttr()
   	{
  -      if(MUTATIONEVENTS)
  +      if(MUTATIONEVENTS && ownerDocument().mutationEvents)
         {
           NodeImpl eventAncestor=this;
           while(true)
  @@ -1124,7 +1128,7 @@
   	 */
   	void dispatchAggregateEvents(AttrImpl enclosingAttr,String oldvalue)
   	{
  -      if(MUTATIONEVENTS)
  +      if(MUTATIONEVENTS && ownerDocument().mutationEvents)
         {
   	    if(nodeListeners==null)
               return;
  
  
  
  1.13      +15 -7     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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ParentNode.java	2000/07/19 00:58:33	1.12
  +++ ParentNode.java	2000/08/18 01:58:34	1.13
  @@ -1,4 +1,4 @@
  -/* $Id: ParentNode.java,v 1.12 2000/07/19 00:58:33 lehors Exp $ */
  +/* $Id: ParentNode.java,v 1.13 2000/08/18 01:58:34 lehors Exp $ */
   /*
    * The Apache Software License, Version 1.1
    *
  @@ -394,7 +394,8 @@
               ChildNode newInternal = (ChildNode)newChild;
   
               EnclosingAttr enclosingAttr=null;
  -            if(MUTATIONEVENTS && (mutationMask&MUTATION_AGGREGATE)!=0)
  +            if(MUTATIONEVENTS && ownerDocument.mutationEvents
  +               && (mutationMask&MUTATION_AGGREGATE)!=0)
               {
                   // MUTATION PREPROCESSING
                   // No direct pre-events, but if we're within the scope 
  @@ -472,7 +473,7 @@
                   }
               }
   
  -            if(MUTATIONEVENTS)
  +            if(MUTATIONEVENTS && ownerDocument.mutationEvents)
               {
                   // MUTATION POST-EVENTS:
                   // "Local" events (non-aggregated)
  @@ -583,7 +584,7 @@
           ChildNode oldInternal = (ChildNode) oldChild;
   
           EnclosingAttr enclosingAttr=null;
  -        if(MUTATIONEVENTS)
  +        if(MUTATIONEVENTS && ownerDocument.mutationEvents)
           {
               // MUTATION PREPROCESSING AND PRE-EVENTS:
               // If we're within the scope of an Attr and DOMAttrModified 
  @@ -688,7 +689,7 @@
   
           changed();
   
  -        if(MUTATIONEVENTS)
  +        if(MUTATIONEVENTS && ownerDocument.mutationEvents)
           {
               // MUTATION POST-EVENTS:
               // Subroutine: Transmit DOMAttrModified and DOMSubtreeModified,
  @@ -731,7 +732,7 @@
           // aggregations should be issued only once per user request.
   
           EnclosingAttr enclosingAttr=null;
  -        if(MUTATIONEVENTS)
  +        if(MUTATIONEVENTS && ownerDocument.mutationEvents)
           {
               // MUTATION PREPROCESSING AND PRE-EVENTS:
               // If we're within the scope of an Attr and DOMAttrModified 
  @@ -747,7 +748,7 @@
           internalInsertBefore(newChild, oldChild,MUTATION_LOCAL);
           internalRemoveChild(oldChild,MUTATION_LOCAL);
   
  -        if(MUTATIONEVENTS)
  +        if(MUTATIONEVENTS && ownerDocument.mutationEvents)
           {
               dispatchAggregateEvents(enclosingAttr);
           }
  @@ -892,6 +893,10 @@
        */
       protected final void synchronizeChildren(int nodeIndex) {
   
  +        // we don't want to generate any event for this so turn them off
  +        boolean orig = ownerDocument.mutationEvents;
  +        ownerDocument.mutationEvents = false;
  +
           // no need to sync in the future
           needsSyncChildren(false);
   
  @@ -921,6 +926,9 @@
               first.isFirstChild(true);
               lastChild(last);
           }
  +
  +        // set mutation events flag back to its original value
  +        ownerDocument.mutationEvents = orig;
   
       } // synchronizeChildren()