You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by jk...@apache.org on 2002/11/20 17:04:37 UTC

cvs commit: xml-xalan/java/src/org/apache/xml/dtm/ref DTMManagerDefault.java

jkesselm    2002/11/20 08:04:37

  Modified:    java/src/org/apache/xml/dtm/dom2dtm2 Tag: xslt20
                        DOM2DTM2Base.java DOM2DTM2Traversers.java
                        NodeDTMIDResolver.java
                        NodeDTMIDResolver_xerces.java
               java/src/org/apache/xml/dtm/ref Tag: xslt20
                        DTMManagerDefault.java
  Log:
  Significant performance improvement achieved in DOM2DTM2
  by only searching backward to the start of a logically-contiguous
  block of text when we know that the node might meet those
  conditions. When we know the type isn't Text, or when we've found
  it by scanning forward through the document, this overhead is
  suppressed. Difference on an intensive performance test is
  quite substantial!
  
  Performance is still not where I want it. Currently, the largest
  bottleneck seems to be the document-order testing, which we
  knew was going to be more expensive in this solution. It's
  probably possible to improve that algorithm, but we aren't
  likely to get close to the just-compare-node-numbers that the
  old DOM2DTM supported. It's hoped that DOM2DTM2's other
  advantages will make up for this.
  
  As before, DOM2DTM2 will only be used if the flag in
  DTMManagerDefault is set true; the code is checked in with
  it set false, since we aren't ready to make this our
  primary solution.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.4   +18 -15    xml-xalan/java/src/org/apache/xml/dtm/dom2dtm2/Attic/DOM2DTM2Base.java
  
  Index: DOM2DTM2Base.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/dom2dtm2/Attic/DOM2DTM2Base.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- DOM2DTM2Base.java	11 Nov 2002 19:51:16 -0000	1.1.2.3
  +++ DOM2DTM2Base.java	20 Nov 2002 16:04:36 -0000	1.1.2.4
  @@ -396,7 +396,7 @@
   	        {
   	        	if(p.getNodeType()==Node.ELEMENT_NODE)
   	    	    	shouldstrip=m_wsfilter.getShouldStripSpace(
  -	    	    		makeNodeHandle(m_resolver.findID(p)),
  +	    	    		makeNodeHandle(m_resolver.findID(p,false)), //never a text node
   	    	    		this);
           	}
           }
  @@ -463,7 +463,7 @@
   	        {
   	        	if(p.getNodeType()==Node.ELEMENT_NODE)
   	    	    	shouldstrip=m_wsfilter.getShouldStripSpace(
  -	    	    		makeNodeHandle(m_resolver.findID(p)),
  +	    	    		makeNodeHandle(m_resolver.findID(p,false)),  // never a text node
   	    	    		this);
           	}
           }
  @@ -794,7 +794,7 @@
     	if(n.getNodeType()==Node.ATTRIBUTE_NODE)
   	 	return NULL;
   	  
  -  	return m_resolver.findID(walkFirstChildSkipEntRef(n));
  +  	return m_resolver.findID(walkFirstChildSkipEntRef(n),false);  // should never be non-first text 
     }
   
     /**
  @@ -839,7 +839,7 @@
   	  			NAMESPACE_URI_XMLNS.equals(n.getNamespaceURI()) &&
     				("xmlns".equals(n.getPrefix()) || "xmlns".equals(n.getNodeName()))
     				))
  -		  	return m_resolver.findID(n);
  +		  	return m_resolver.findID(n,false);
   		}
   	 	return NULL;
     	}
  @@ -857,7 +857,7 @@
   				||ntype==Node.CDATA_SECTION_NODE));
   	}
   	  
  -  	return m_resolver.findID(n);
  +  	return m_resolver.findID(n,false); // should never be non-first text 
     }
   
     /**
  @@ -899,7 +899,7 @@
   	  			NAMESPACE_URI_XMLNS.equals(n.getNamespaceURI()) &&
     				("xmlns".equals(n.getPrefix()) || "xmlns".equals(n.getNodeName()))
     				))
  -		  	return m_resolver.findID(n);
  +		  	return m_resolver.findID(n,true); // might be text but not first-text
   		}
   	 	return NULL;
     	}
  @@ -931,7 +931,7 @@
   		}
   	}
   	  
  -  	return m_resolver.findID(n);
  +  	return m_resolver.findID(n,true);  // may be non-first text 
     }
   
     /**
  @@ -945,7 +945,7 @@
     {
     	Node n=m_resolver.findNode(identity);
     	n=walkParentSkipEntRef(n);
  -  	return m_resolver.findID(n);
  +  	return m_resolver.findID(n,false); // Parent will never be text node!
     }
   
     /**
  @@ -1315,7 +1315,8 @@
     	if(n.getNodeType()==Node.ATTRIBUTE_NODE)
   	 	return NULL;
   	  
  -  	return makeNodeHandle(m_resolver.findID(walkLastChildSkipEntRef(n)));
  +	// may be text but not first-text
  +  	return makeNodeHandle(m_resolver.findID(walkLastChildSkipEntRef(n),true));
     }
   
     /**
  @@ -1340,7 +1341,8 @@
     		return NULL;
   	  
     	return makeNodeHandle(m_resolver.findID(
  -  		((Element)n).getAttributeNodeNS(namespaceURI,name)
  +  		((Element)n).getAttributeNodeNS(namespaceURI,name),
  +  		false // never a text node
     		));
     }
   
  @@ -1364,7 +1366,7 @@
   		n=nnm.item(++i))
   		if(! NAMESPACE_URI_XMLNS.equals(
   			nnm.item(i).getNamespaceURI()) )
  -			return makeNodeHandle(m_resolver.findID(n));
  +			return makeNodeHandle(m_resolver.findID(n,false)); // never a text node
   
   	return NULL; 	// No non-NS attr found
     }
  @@ -1456,14 +1458,14 @@
   		if(nsnodes==null)
   			return NULL;
   		n=(Node)nsnodes.elementAt(0);
  -		return makeNodeHandle(m_resolver.findID( n ));
  +		return makeNodeHandle(m_resolver.findID( n,false )); // never a text node
       }
   	else
   	{
   		// Just do local scan?
   		// %REVIEW%
   		n=nextNSAttr(n);
  -		return makeNodeHandle(m_resolver.findID( n ));		
  +		return makeNodeHandle(m_resolver.findID( n,false )); // never a text node
   	}
     }
   
  @@ -1503,7 +1505,7 @@
   		for(i=0;i<s;++i)
   		{
   			if(m_resolver.isSameNode(start,(Node)nsnodes.elementAt(i)))
  -				return makeNodeHandle(m_resolver.findID((Node)nsnodes.elementAt(i+1)));
  +				return makeNodeHandle(m_resolver.findID((Node)nsnodes.elementAt(i+1),false)); // never a text node
   		}
   		return NULL; // Off end of list
   	  }
  @@ -2337,7 +2339,8 @@
   	return (doc==null) 
   		? NULL
   		: makeNodeHandle(m_resolver.findID(
  -			doc.getElementById( elementId)
  +			doc.getElementById( elementId),
  +			false // never a text node
   			));
     }
     
  
  
  
  1.1.2.2   +11 -9     xml-xalan/java/src/org/apache/xml/dtm/dom2dtm2/Attic/DOM2DTM2Traversers.java
  
  Index: DOM2DTM2Traversers.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/dom2dtm2/Attic/DOM2DTM2Traversers.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- DOM2DTM2Traversers.java	27 Sep 2002 22:07:03 -0000	1.1.2.1
  +++ DOM2DTM2Traversers.java	20 Nov 2002 16:04:36 -0000	1.1.2.2
  @@ -594,7 +594,7 @@
         int currentNodeIdent=makeNodeIdentity(current);
         Node n=m_resolver.findNode(currentNodeIdent);
         n=walkNextSkipEntRef(n,subtreeRootNode,true);
  -      return makeNodeHandle(m_resolver.findID(n));
  +      return makeNodeHandle(m_resolver.findID(n,false)); // never non-first Text node
       }
   
       /**
  @@ -629,7 +629,7 @@
         do
         {
   	      n=walkNextSkipEntRef(n,subtreeRootNode,true);
  -	      newid=m_resolver.findID(n);
  +	      newid=m_resolver.findID(n,false); // never non-first text node
         } while(n!=null && expandedTypeID != _exptype(newid));      			
         			
         return makeNodeHandle(newid);
  @@ -897,7 +897,7 @@
       	// since first() dealt with that.
       	Node n=getNode(current);
       	n=walkNextSkipEntRef(n,null,true);
  -    	return makeNodeHandle(m_resolver.findID(n));
  +    	return makeNodeHandle(m_resolver.findID(n,false)); // never non-first Text node
       }
   
       /**
  @@ -915,12 +915,14 @@
       	// We know it isn't an attr or a namespace,
       	// since first() dealt with that.
       	Node n=getNode(current);
  +    	int nid;
       	do
       	{
   	    	n=walkNextSkipEntRef(n,null,true);
  +	    	nid=m_resolver.findID(n,false);// never non-first text node 
       	}
  -    	while(n!=null && expandedTypeID!=_exptype(m_resolver.findID(n)));
  -    	return makeNodeHandle(m_resolver.findID(n));
  +    	while(n!=null && expandedTypeID!=_exptype(nid));
  +    	return makeNodeHandle(nid);// never non-first text node
       }
     }
   
  @@ -1206,7 +1208,7 @@
         {
   	      n=walkPreviousSkipEntRef(n,within);
         } while(n!=null && isAncestor(subtreeRootNode,n));
  -      return makeNodeHandle(m_resolver.findID(n));
  +      return makeNodeHandle(m_resolver.findID(n,true));  // may be non-first Text node
       }
   
       /**
  @@ -1233,7 +1235,7 @@
   	      n=walkPreviousSkipEntRef(n,within);
         }
         while(n!=null && isAncestor(subtreeRootNode,n) && !walkIsExpandedTypeID(n,expandedTypeID));
  -      return makeNodeHandle(m_resolver.findID(n));
  +      return makeNodeHandle(m_resolver.findID(n,true)); // may be non-first Text node
       }
     }
   
  @@ -1260,7 +1262,7 @@
         Node within=m_resolver.findNode(doc);     
         Node n=m_resolver.findNode(makeNodeIdentity(current));
         n=walkPreviousSkipEntRef(n,within);
  -      return makeNodeHandle(m_resolver.findID(n));
  +      return makeNodeHandle(m_resolver.findID(n,true));  // may be non-first Text node
       }
   
       /**
  @@ -1286,7 +1288,7 @@
   	      n=walkPreviousSkipEntRef(n,within);
         }
         while(n!=null && walkIsExpandedTypeID(n,expandedTypeID));
  -      return makeNodeHandle(m_resolver.findID(n));
  +      return makeNodeHandle(m_resolver.findID(n,true)); // may be non-first Text node
       }
     }
   
  
  
  
  1.1.2.2   +28 -2     xml-xalan/java/src/org/apache/xml/dtm/dom2dtm2/Attic/NodeDTMIDResolver.java
  
  Index: NodeDTMIDResolver.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/dom2dtm2/Attic/NodeDTMIDResolver.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- NodeDTMIDResolver.java	27 Sep 2002 22:07:03 -0000	1.1.2.1
  +++ NodeDTMIDResolver.java	20 Nov 2002 16:04:36 -0000	1.1.2.2
  @@ -26,8 +26,11 @@
   	 * */
   	
   	/** Given a DOM node, return its unique-within-Document ID number.
  -	 * This is implemented uniquely in each concrete resolver class.
   	 * 
  +	 * This version  is safe under all conditions -- equivalent to
  +	 * findID(n,true), which see.
  +	 * 
  +	 * This is implemented uniquely in each concrete resolver class.
   	 * Approaches may range from using the DOM Level 3 userData hooks
   	 * to leveraging a particular implementation's custom features to
   	 * (possibly extremely painful!) isSameNode table searches.
  @@ -37,7 +40,29 @@
   	 * and seek to the first of a logically-adjacent set of Text nodes.
   	 * */
   	public int findID(Node n);
  -	
  +
  +	/** Given a DOM node, return its unique-within-Document ID number.
  +	 * 
  +	 * This version is used within DOM2DTM2, as an optimization; if fixupTextNodes
  +	 * is false, the caller is asserting that the node will never be a Text
  +	 * node which "logically follows" another Text node, and thus that we don't
  +	 * have to spend cycles walking backward to test that case. If you hand us a text
  +	 * node which does not meet those constraints and do not set fixupTextNodes
  +	 * to true, erroneous results are the best you can expect; if in doubt,
  +	 * burn the cycles and do the fixup.
  +	 * 
  +	 * This is implemented uniquely in each concrete resolver class.
  +	 * Approaches may range from using the DOM Level 3 userData hooks
  +	 * to leveraging a particular implementation's custom features to
  +	 * (possibly extremely painful!) isSameNode table searches.
  +	 * 
  +	 * Note that some mapping from DOM to XPath should be performed
  +	 * -- specifically, findID should "skip" EntityReference nodes,
  +	 * and (if fixupTextNodes is true) seek to the first of a 
  +	 * logically-adjacent set of Text nodes.
  +	 * */
  +	public int findID(Node n,boolean fixupTextNodes);
  +
   	/** Given unique-within-Document ID number, return its Node
   	 * This is implemented uniquely in each concrete resolver class,
   	 * most commonly via some form of reverse table/vector.
  @@ -46,6 +71,7 @@
   	 * */
   	public Node findNode(int id);	
   	
  +
   	/** Given two node objects, report whether they are the same DOM node.
   	 * This is implemented uniquely in each concrete resolver class,
   	 * most portably via DOM3 isSameNode() but some DOMs require/permit
  
  
  
  1.1.2.5   +18 -49    xml-xalan/java/src/org/apache/xml/dtm/dom2dtm2/Attic/NodeDTMIDResolver_xerces.java
  
  Index: NodeDTMIDResolver_xerces.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/dom2dtm2/Attic/NodeDTMIDResolver_xerces.java,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- NodeDTMIDResolver_xerces.java	11 Nov 2002 19:51:16 -0000	1.1.2.4
  +++ NodeDTMIDResolver_xerces.java	20 Nov 2002 16:04:36 -0000	1.1.2.5
  @@ -80,7 +80,7 @@
   			resolver=new NodeDTMIDResolver_xerces();
   			// Make sure the Document node will be node 0, just for
   			// clarity/consistancy/simplicity of retrofit.
  -			resolver.findID(doc);
  +			resolver.findID(doc,false); // never a text node
   			
   			((NodeImpl)doc).setUserData(KEY_BOUND_RESOLVER,resolver,null);
   			return resolver;
  @@ -104,7 +104,7 @@
   	 * Xerces-specific classes, and do the node-to-ID binding via
   	 * userData. Reverse binding is done via a vector.
   	 * 
  -	 * %REVEIW%
  +	 * %REVIEW%
   	 * NOTE: Xerces nodes are claimed to be hashable, since that's what they
   	 * use for their internal implementation of userData. We could bypass
   	 * their system and use that. The code here generalizes to be
  @@ -113,8 +113,16 @@
   	 * */
   	public int findID(Node n)
   	{
  -		if(true) /*****************/
  -		{
  +		return findID(n,true);
  +	}
  +	
  +	/** PACKAGE-INTERNAL node-to-ID lookup, used within DOM2DTM2. If we're scanning
  +	 * forward (and thus know that any text nodes encountered will be the
  +	 * first in their logically-adjacent text block) we don't need to spend
  +	 * cycles calling the (expensive) findContainingXPathNode.
  +	 * */
  +	public int findID(Node n,boolean fixupTextNodes)	
  +	{
   	  	// %REVIEW% Should we have stored which doc we're applying to,
     		// and enforce membership? Probably good idea since we're
   	  	// relying on implementation characteristics.
  @@ -128,10 +136,8 @@
   			((DOM2DTMdefaultNamespaceDeclarationNode)n).getIDOfNode();
   		}
   
  -
   		int ntype=n.getNodeType();
   		Integer id;
  -		
   
   		NodeImpl n3=(NodeImpl)n; 
   		id=(Integer)n3.getUserData(KEY_ID);
  @@ -147,11 +153,15 @@
   		    // as the first node in their Logically
   		    // Consecutive Text block.
   		    //
  -		    // %REVEIW% Should this lookup be recursive, so IDs are
  +		    // %REVIEW% Should this lookup be recursive, so IDs are
   		    // set on all the intermediates as a side effect?
   		    //
   		    // Get the "containing" node; it may be same as n.
  -		    NodeImpl root=(NodeImpl)findContainingXPathNode(n);
  +		    NodeImpl root;
  +		    root=(fixupTextNodes)
  +		    	? (NodeImpl)findContainingXPathNode(n)
  +				: (NodeImpl)n;
  +				
   		    id=(Integer)root.getUserData(KEY_ID); 
   		    if(id==null)
   		    {
  @@ -176,48 +186,7 @@
   		
   		// If this throws NPE, something above is Broken
   		return id.intValue();		
  -			
  -		} /***********************/
  -		
  -	  	// %REVIEW% Should we have stored which doc we're applying to,
  -  		// and enforce membership? Probably good idea since we're
  -	  	// relying on implementation characteristics.
  -	  	
  -		if(n==null) return DTM.NULL;
   		
  -		Integer id;
  -		
  -		// If it's a Text node, we should find the first Text node
  -		// in sequence (backward depth-first walk through EntRefs).
  -		// If it's an EntRef, we should find the first non-EntRef
  -		// preceeding it.
  -		n=findContainingXPathNode(n);
  -		if(n==null) return org.apache.xml.dtm.DTM.NULL;
  -		
  -		if(n instanceof DOM2DTMdefaultNamespaceDeclarationNode)
  -		{
  -			// PROBLEM: Want the ID, not the Handle!
  -			return
  -				((DOM2DTMdefaultNamespaceDeclarationNode)n).getIDOfNode()
  -				;
  -			
  -		}
  -		else
  -		{
  -			NodeImpl n3=(NodeImpl)n; 
  -			id=(Integer)n3.getUserData(KEY_ID);
  -			if(id==null)
  -			{
  -				// Note sequence; first is added at 0.
  -				id=new Integer(m_map.size());
  -				n3.setUserData(KEY_ID,id,null);
  -				m_map.addElement(n); 
  -			}
  -		}
  -		
  -		
  -		// If this throws NPE, something is Broken
  -		return id.intValue();		
   	}
   
   	/** Given unique-within-Document ID number, return its Node
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.41.6.1.2.7 +29 -17    xml-xalan/java/src/org/apache/xml/dtm/ref/DTMManagerDefault.java
  
  Index: DTMManagerDefault.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/DTMManagerDefault.java,v
  retrieving revision 1.41.6.1.2.6
  retrieving revision 1.41.6.1.2.7
  diff -u -r1.41.6.1.2.6 -r1.41.6.1.2.7
  --- DTMManagerDefault.java	13 Nov 2002 05:27:34 -0000	1.41.6.1.2.6
  +++ DTMManagerDefault.java	20 Nov 2002 16:04:36 -0000	1.41.6.1.2.7
  @@ -78,8 +78,12 @@
   // EXPERIMENTAL 3/22/02
   import org.apache.xml.dtm.ref.xni2dtm.XNI2DTM;
   import org.apache.xml.dtm.ref.xni2dtm.XNISource;
  -// EXPERIMENTAL 9/18/02
  -// import org.apache.xml.dtm.dom2dtm2.DOM2DTM2;
  +
  +// EXPERIMENTAL 9/18/02 DO NOT COMMMENT THIS OUT; IT'S IN USE!
  +// IF YOU MUST DISABLE IT, SET THE STATIC BOOLEAN TO FALSE.
  +// IF YOU MUST COMPILE WITHOUT IT, TALK TO JOE ABOUT MAKING IT
  +// REFLECTION-BASED.
  +import org.apache.xml.dtm.dom2dtm2.DOM2DTM2;
   /**************************************************************/
   
   // W3C DOM
  @@ -126,9 +130,12 @@
     // Set true to attempt loading DOMs via our experimental
     // DOM2DTM2 wrapper. If false, or if that fails, we fall
     // back on standard DOM2DTM.
  +  // EXPERIMENTAL 9/18/02 DO NOT COMMMENT THIS OUT; IT'S IN USE!
  +  // IF YOU MUST DISABLE IT, SET THE STATIC BOOLEAN TO FALSE.
  +  // IF YOU MUST COMPILE WITHOUT IT, TALK TO JOE ABOUT MAKING IT
  +  // REFLECTION-BASED.
     private static final boolean ATTEMPT_DOM2DTM2=false;//true;
   	
  -	
     /** Set this to true if you want a dump of the DTM after creation. */
     private static final boolean DUMPTREE = false;
   
  @@ -296,23 +303,28 @@
         // Simplest case: Wrap a DTM around an existing DOM.
         if(ATTEMPT_DOM2DTM2)
         {
  -		DTM dtm;      	
  -//      	try
  -//      	{
  -//	      dtm = new DOM2DTM2(this, source, documentID,
  -//                                whiteSpaceFilter, xstringFactory, doIndexing);
  -//      	} catch(ClassCastException e)
  +	// EXPERIMENTAL 9/18/02 DO NOT COMMMENT THIS OUT; IT'S IN USE!
  +	// IF YOU MUST DISABLE IT, SET THE STATIC BOOLEAN TO FALSE.
  +	// IF YOU MUST COMPILE WITHOUT IT, TALK TO JOE ABOUT MAKING IT
  +	// REFLECTION-BASED.
  +	DTM dtm;      	
  +      	try
         	{
  -	      dtm = new DOM2DTM(this, (DOMSource) source, documentID,
  -                                whiteSpaceFilter, xstringFactory, doIndexing);
  -      	}
  -	    addDTM(dtm, dtmPos, 0);
  -        return dtm;
  +	  dtm = new DOM2DTM2(this, source, documentID,
  +			     whiteSpaceFilter, xstringFactory, doIndexing);
  +      	} catch(ClassCastException e)
  +	{
  +	  dtm = null;
  +	  
  +	}
  +	if(dtm!=null)
  +	{
  +	  addDTM(dtm, dtmPos, 0);
  +	  return dtm;
  +	}
         }
  -
  -
         DOM2DTM dtm = new DOM2DTM(this, (DOMSource) source, documentID,
  -                                whiteSpaceFilter, xstringFactory, doIndexing);
  +				whiteSpaceFilter, xstringFactory, doIndexing);
         addDTM(dtm, dtmPos, 0);
         return dtm;
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org