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 2001/05/18 23:01:29 UTC

cvs commit: xml-xalan/java/src/org/apache/xml/utils FastStringBuffer.java

jkesselm    01/05/18 14:01:28

  Modified:    java/src/org/apache/xml/dtm Tag: DTM_EXP
                        DTMManagerDefault.java
               java/src/org/apache/xml/dtm/dom2dtm Tag: DTM_EXP
                        DOM2DTM.java
               java/src/org/apache/xml/utils Tag: DTM_EXP
                        FastStringBuffer.java
  Log:
  DMManagerDefault@getDTMHandleFromNode now tries to find
  an existing DOM2DTM which contains that node, rather than
  immediately generating a new one. The cost of searching for it
  is fairly high, though I've tried to avoid exhaustive search through
  every DOM2DTM.
  
  Caveat: If found, there is no guarantee that this is the _best_
  DTMHandle for that node. Due to the possiblility that DOM2DTM
  represents only a subtree, DTMManager may have multiple DTMs
  which expose that node. We could search for the one that gives
  it the deepest "level"... but given how expensive each search
  currently is, I don't know if we want to go there.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.17  +28 -3     xml-xalan/java/src/org/apache/xml/dtm/Attic/DTMManagerDefault.java
  
  Index: DTMManagerDefault.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/Attic/DTMManagerDefault.java,v
  retrieving revision 1.1.2.16
  retrieving revision 1.1.2.17
  diff -u -r1.1.2.16 -r1.1.2.17
  --- DTMManagerDefault.java	2001/05/18 07:16:38	1.1.2.16
  +++ DTMManagerDefault.java	2001/05/18 21:01:21	1.1.2.17
  @@ -362,7 +362,8 @@
   
     /**
      * Given a W3C DOM node, try and return a DTM handle.
  -   * Note: calling this may be non-optimal.
  +   * Note: calling this may be non-optimal, and there is no guarantee that
  +   * the node will be found in any particular DTM.
      *
      * @param node Non-null reference to a DOM node.
      *
  @@ -375,9 +376,33 @@
         return ((org.apache.xml.dtm.DTMNodeProxy) node).getDTMNodeNumber();
       else
       {
  -
  +      // Find the DOM2DTMs wrapped around this Document (if any)
  +      // and check whether they contain the Node in question.
  +      //
  +      // NOTE that since a DOM2DTM may represent a subtree rather
  +      // than a full document, we have to be prepared to check more
  +      // than one -- and there is no guarantee that we will find 
  +      // one that contains ancestors or siblings of the node we're
  +      // seeking.
  +      //
  +      // %REVIEW% We could search for the one which contains this
  +      // node at the deepest level, and thus covers the widest
  +      // subtree, but that's going to entail additional work
  +      // checking more DTMs... and getHandleFromNode is not a
  +      // cheap operation in most implementations.
  +      for(int i=m_dtms.size()-1;i>=0;--i)
  +	{
  +	  DTM thisDTM=(DTM)m_dtms.elementAt(i);
  +	  if(thisDTM instanceof DOM2DTM)
  +	    {
  +	      int handle=((DOM2DTM)thisDTM).getHandleOfNode(node);
  +	      if(handle!=DTM.NULL) return handle;
  +	    }
  +	}
  +      
  +      // Fallback: Not found in one we know how to search.
  +      // Current solution: Generate a new DOM2DTM with this node as root.
         // %REVIEW% Maybe the best I can do??
  -      // Or should I first search all the DTMs??
         DTM dtm = getDTM(new javax.xml.transform.dom.DOMSource(node), false,
                          null, true);
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.16  +59 -7     xml-xalan/java/src/org/apache/xml/dtm/dom2dtm/Attic/DOM2DTM.java
  
  Index: DOM2DTM.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/dom2dtm/Attic/DOM2DTM.java,v
  retrieving revision 1.1.2.15
  retrieving revision 1.1.2.16
  diff -u -r1.1.2.15 -r1.1.2.16
  --- DOM2DTM.java	2001/05/18 07:16:46	1.1.2.15
  +++ DOM2DTM.java	2001/05/18 21:01:25	1.1.2.16
  @@ -494,24 +494,76 @@
     /**
      * Get the handle from a Node.
      * <p>%OPT% This will be pretty slow.</p>
  +   * 
  +   * %REVIEW% This relies on being able to test node-identity via
  +   * object-identity. DTM2DOM proxying is a great example of a case where
  +   * that doesn't work. DOM Level 3 will provide the isSameNode() method
  +   * to fix that, but until then this is going to be flaky.
      *
      * @param node A node, which may be null.
      *
      * @return The node handle or <code>DTM.NULL</code>.
      */
  -  protected int getHandleFromNode(Node node)
  +  private int getHandleFromNode(Node node)
     {
  -
       if (null != node)
       {
         int len = m_nodes.size();
  -
         for (int i = 0; i < len; i++)
  -      {
  -        if (m_nodes.elementAt(i) == node)
  -          return i | m_dtmIdent;
  -      }
  +	{
  +	  if (m_nodes.elementAt(i) == node)
  +	    return i | m_dtmIdent;
  +	}
       }
  +
  +    return DTM.NULL;
  +  }
  +
  +  /** Get the handle from a Node. This is a more robust version of
  +   * getHandleFromNode, intended to be usable by the public.
  +   *
  +   * <p>%OPT% This will be pretty slow.</p>
  +   * 
  +   * %REVIEW% This relies on being able to test node-identity via
  +   * object-identity. DTM2DOM proxying is a great example of a case where
  +   * that doesn't work. DOM Level 3 will provide the isSameNode() method
  +   * to fix that, but until then this is going to be flaky.
  +   *
  +   * @param node A node, which may be null.
  +   *
  +   * @return The node handle or <code>DTM.NULL</code>.  */
  +  public int getHandleOfNode(Node node)
  +  {
  +    if (null != node)
  +    {
  +      // Is Node actually within the same document? If not, don't search!
  +      // This would be easier if m_root was always the Document node, but
  +      // we decided to allow wrapping a DTM around a subtree.
  +      if((m_root==node) ||
  +	 (m_root.getNodeType()==DOCUMENT_NODE &&
  +	  m_root==node.getOwnerDocument()) ||
  +	 (m_root.getNodeType()!=DOCUMENT_NODE &&
  +	  m_root.getOwnerDocument()==node.getOwnerDocument())
  +	 )
  +	{
  +	  // If node _is_ in m_root's tree, find its handle
  +	  //
  +	  // %OPT% This check may be improved significantly when DOM
  +	  // Level 3 nodeKey and relative-order tests become
  +	  // available!
  +	  for(Node cursor=node;
  +	      cursor!=null;
  +	      cursor=
  +		(cursor.getNodeType()!=ATTRIBUTE_NODE)
  +		? cursor.getParentNode()
  +		: ((org.w3c.dom.Attr)cursor).getOwnerElement())
  +	    {
  +	      if(cursor==m_root)
  +		// We know this node; find its handle.
  +		return getHandleFromNode(node); 
  +	    } // for ancestors of node
  +	} // if node and m_root in same Document
  +    } // if node!=null
   
       return DTM.NULL;
     }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.10.2.2  +5 -2      xml-xalan/java/src/org/apache/xml/utils/FastStringBuffer.java
  
  Index: FastStringBuffer.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/utils/FastStringBuffer.java,v
  retrieving revision 1.10.2.1
  retrieving revision 1.10.2.2
  diff -u -r1.10.2.1 -r1.10.2.2
  --- FastStringBuffer.java	2001/05/18 07:16:53	1.10.2.1
  +++ FastStringBuffer.java	2001/05/18 21:01:27	1.10.2.2
  @@ -82,6 +82,8 @@
    */
   public class FastStringBuffer
   {
  +  // If nonzero, forces the inial chunk size.
  +  /**/static final int DEBUG_FORCE_INIT_BITS=0;
   
     /**
      * Field m_chunkBits sets our chunking strategy, by saying how many
  @@ -186,6 +188,7 @@
     public FastStringBuffer(int initChunkBits, int maxChunkBits,
                             int rebundleBits)
     {
  +    if(DEBUG_FORCE_INIT_BITS!=0) initChunkBits=DEBUG_FORCE_INIT_BITS;
   
       m_array = new char[16][];
   
  @@ -300,7 +303,7 @@
      * The only safe use for our setLength() is to truncate the FastStringBuffer
      * to a shorter string.
      * <p>
  -   * TODO: Current setLength code is probably not the best solution.
  +   * TODO: %REVEIW% Current setLength code is probably not the best solution.
      * It releases memory that in theory we shouldn retain and
      * reuse. Holding onto that would require recursive truncation of
      * the inner FSB, and extending the append operations to recurse
  @@ -333,7 +336,7 @@
      * NEEDSDOC @param l
      * NEEDSDOC @param rootFSB
      */
  -  final void setLength(int l, FastStringBuffer rootFSB)
  +  private final void setLength(int l, FastStringBuffer rootFSB)
     {
   
       m_lastChunk = l >>> m_chunkBits;
  
  
  

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