dbertoni    00/07/25 07:49:36

  Modified:    c/src/XSLT ElemTemplateElement.cpp ElemTemplateElement.hpp
  Log:
  Restructured code so that node lists are not copied unnecessarily.
  
  Revision  Changes    Path
  1.26      +208 -66   xml-xalan/c/src/XSLT/ElemTemplateElement.cpp
  
  Index: ElemTemplateElement.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemTemplateElement.cpp,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- ElemTemplateElement.cpp   2000/07/06 20:19:25     1.25
  +++ ElemTemplateElement.cpp   2000/07/25 14:49:32     1.26
  @@ -96,8 +96,7 @@
   #include "ElemForEach.hpp"
   #include "ElemSort.hpp"
   #include "ElemTemplate.hpp"
  -#include "NodeSortKey.hpp"
  -#include "NodeSorter.hpp"
  +//#include "NodeSortKey.hpp"
   #include "Stylesheet.hpp"
   #include "StylesheetExecutionContext.hpp"
   #include "StylesheetRoot.hpp"
  @@ -579,7 +578,7 @@
                        const QName&                                    mode,
                        const XPath*                                    
selectPattern,
                        int                                                     
        xslToken,
  -                     int selectStackFrameIndex) const
  +                     int                                                     
        selectStackFrameIndex) const
   {
        typedef StylesheetExecutionContext::SetAndRestoreCurrentStackFrameIndex 
        SetAndRestoreCurrentStackFrameIndex;
   
  @@ -630,9 +629,6 @@
                        keys.push_back(key);
                }
        }
  -     // @@ JMD: Now in method processSortKeys in java ...
  -
  -     MutableNodeRefList      sourceNodes = 
executionContext.createMutableNodeRefList();
   
   /*
        @@@ JMD: This is newer java code that is not implemented in C++; so, the
  @@ -645,36 +641,43 @@
   
        if (0 != selectPattern)
        {
  -             SetAndRestoreCurrentStackFrameIndex             
theSetAndRestore(
  -                             executionContext,
  -                             selectStackFrameIndex);
  +             XObject*        theXObject = 0;
   
  -/*
  -     @@@ JMD: This is newer java code that is not implemented in C++; the
  -     callback mechanism may affect the correct positioning of the stack 
frame and
  -     may be why the parameters aren't working right
  -
  -      // Optimization note: is there a way we can keep from creating 
  -      // a new callback context every time?
  -      TemplateElementContext callbackContext 
  -        = (null != callback) 
  -                      ? new TemplateElementContext(stylesheetTree, 
xslInstruction,
  -                                      template, sourceNodeContext, mode, 
xslToken, tcontext,
  -                                      savedCurrentStackFrameIndex) : null;
  -*/
  +             {
  +                     SetAndRestoreCurrentStackFrameIndex             
theSetAndRestore(
  +                                     executionContext,
  +                                     selectStackFrameIndex);
   
  -             const XObjectGuard      result(
  -                             executionContext.getXObjectFactory(),
  -                             selectPattern->execute(
  -                                     sourceNodeContext,
  -                                     xslInstruction,
  -                                     executionContext));
  +     /*
  +             @@@ JMD: This is newer java code that is not implemented in 
C++; the
  +             callback mechanism may affect the correct positioning of the 
stack frame and
  +             may be why the parameters aren't working right
  +
  +               // Optimization note: is there a way we can keep from 
creating 
  +               // a new callback context every time?
  +               TemplateElementContext callbackContext 
  +                     = (null != callback) 
  +                              ? new TemplateElementContext(stylesheetTree, 
xslInstruction,
  +                                              template, sourceNodeContext, 
mode, xslToken, tcontext,
  +                                              savedCurrentStackFrameIndex) : 
null;
  +     */
  +
  +                     theXObject = 
  +                                     selectPattern->execute(
  +                                             sourceNodeContext,
  +                                             xslInstruction,
  +                                             executionContext);
  +             }
   
                // @@ JMD: Should this be an assert ??
  -             if (0 != result.get())
  +             if (0 != theXObject)
                {
  -                     sourceNodes = result->mutableNodeset();
  +                     const XObjectGuard      result(
  +                                     executionContext.getXObjectFactory(),
  +                                     theXObject);
   
  +                     const NodeRefListBase* const    sourceNodes = 
&result->mutableNodeset();
  +
                        if(0 != executionContext.getTraceListeners())
                        {
                                executionContext.fireSelectEvent(
  @@ -685,63 +688,202 @@
                                                        *selectPattern,
                                                        result.get()));
                        }
  +
  +                     const unsigned int      nNodes = 
sourceNodes->getLength();
  +
  +                     if (nNodes > 0)
  +                     {
  +                             doTransformSelectedChildren(
  +                                             executionContext,
  +                                             stylesheetTree,
  +                                             xslInstruction,
  +                                             theTemplate,
  +                                             sourceTree,
  +                                             sourceNodeContext,
  +                                             mode,
  +                                             xslToken,
  +                                             selectStackFrameIndex,
  +                                             keys,
  +                                             *sourceNodes,
  +                                             nNodes);
  +                     }
                }
        }
        else if (keys.size() > 0)
        {
  -             sourceNodes = sourceNodeContext->getChildNodes();
  +             const XalanNodeList* const      childNodes =
  +                                             
sourceNodeContext->getChildNodes();
  +
  +             const unsigned int      nNodes = childNodes->getLength();
  +
  +             if (nNodes > 0)
  +             {
  +                     doTransformSelectedChildren(
  +                                     executionContext,
  +                                     stylesheetTree,
  +                                     xslInstruction,
  +                                     theTemplate,
  +                                     sourceTree,
  +                                     sourceNodeContext,
  +                                     mode,
  +                                     xslToken,
  +                                     selectStackFrameIndex,
  +                                     keys,
  +                                     *childNodes,
  +                                     nNodes);
  +                     }
        }
  +}
  +
   
  -     const unsigned int      nNodes = sourceNodes.getLength();
   
  -     if(nNodes > 0)
  +void
  +ElemTemplateElement::doTransformSelectedChildren(
  +                     StylesheetExecutionContext&                             
        executionContext,
  +                     const Stylesheet&                                       
                stylesheetTree,
  +                     const ElemTemplateElement&                              
        xslInstruction,
  +                     const ElemTemplateElement*                              
        theTemplate,
  +                     XalanNode*                                              
                        sourceTree,
  +                     XalanNode*                                              
                        sourceNodeContext,
  +                     const QName&                                            
                mode,
  +                     int                                                     
                                xslToken,
  +                     int                                                     
                                selectStackFrameIndex,
  +                     const NodeSorter::NodeSortKeyVectorType&        keys,
  +                     const NodeRefListBase&                                  
        sourceNodes,
  +                     unsigned int                                            
                sourceNodesCount) const
  +{
  +     typedef StylesheetExecutionContext::SetAndRestoreCurrentStackFrameIndex 
        SetAndRestoreCurrentStackFrameIndex;
  +
  +     if (keys.size() > 0)
        {
  -             if (keys.size() > 0)
  +             MutableNodeRefList      sortedSourceNodes =
  +                             executionContext.createMutableNodeRefList();
  +
  +             sortedSourceNodes = sourceNodes;
  +
                {
  -                     NodeSorter sorter(executionContext);
  +                     NodeSorter      sorter;
   
                        SetAndRestoreCurrentStackFrameIndex             
theSetAndRestore(
  -                             executionContext,
  -                             selectStackFrameIndex);
  +                                     executionContext,
  +                                     selectStackFrameIndex);
   
  -                     sorter.sort(sourceNodes, keys);
  +                     sorter.sort(executionContext, sortedSourceNodes, keys);
                }
   
  -             if(executionContext.getTraceSelects() == true)
  -             {
  -                     executionContext.traceSelect(
  -                             xslInstruction,
  -                             sourceNodes);
  -             }
  +             doTransformSelectedChildren(
  +                     executionContext,
  +                     stylesheetTree,
  +                     xslInstruction,
  +                     theTemplate,
  +                     sourceTree,
  +                     sourceNodeContext,
  +                     mode,
  +                     xslToken,
  +                     sortedSourceNodes,
  +                     sourceNodesCount);
  +     }
  +     else
  +     {
  +             doTransformSelectedChildren(
  +                     executionContext,
  +                     stylesheetTree,
  +                     xslInstruction,
  +                     theTemplate,
  +                     sourceTree,
  +                     sourceNodeContext,
  +                     mode,
  +                     xslToken,
  +                     sourceNodes,
  +                     sourceNodesCount);
  +     }
  +}
  +
  +
  +
  +void
  +ElemTemplateElement::doTransformSelectedChildren(
  +                     StylesheetExecutionContext&                             
        executionContext,
  +                     const Stylesheet&                                       
                stylesheetTree,
  +                     const ElemTemplateElement&                              
        xslInstruction,
  +                     const ElemTemplateElement*                              
        theTemplate,
  +                     XalanNode*                                              
                        sourceTree,
  +                     XalanNode*                                              
                        sourceNodeContext,
  +                     const QName&                                            
                mode,
  +                     int                                                     
                                xslToken,
  +                     int                                                     
                                selectStackFrameIndex,
  +                     const NodeSorter::NodeSortKeyVectorType&        keys,
  +                     const XalanNodeList&                                    
        childNodes,
  +                     unsigned int                                            
                childNodeCount) const
  +{
  +     MutableNodeRefList      sourceNodes = 
executionContext.createMutableNodeRefList();
  +
  +     sourceNodes = &childNodes;
  +
  +     doTransformSelectedChildren(
  +                     executionContext,
  +                     stylesheetTree,
  +                     xslInstruction,
  +                     theTemplate,
  +                     sourceTree,
  +                     sourceNodeContext,
  +                     mode,
  +                     xslToken,
  +                     selectStackFrameIndex,
  +                     keys,
  +                     sourceNodes,
  +                     childNodeCount);
  +}
   
  -             // Create an object to set and restore the context node list...
  -             StylesheetExecutionContext::ContextNodeListSetAndRestore        
theSetAndRestore(
  +
  +
  +void
  +ElemTemplateElement::doTransformSelectedChildren(
  +                     StylesheetExecutionContext&                     
executionContext,
  +                     const Stylesheet&                                       
stylesheetTree,
  +                     const ElemTemplateElement&                      
xslInstruction,
  +                     const ElemTemplateElement*                      
theTemplate,
  +                     XalanNode*                                              
        sourceTree,
  +                     XalanNode*                                              
        sourceNodeContext,
  +                     const QName&                                            
mode,
  +                     int                                                     
                xslToken,
  +                     const NodeRefListBase&                          
sourceNodes,
  +                     unsigned int                                            
sourceNodesCount) const
  +{
  +     if(executionContext.getTraceSelects() == true)
  +     {
  +             executionContext.traceSelect(
  +                     xslInstruction,
  +                     sourceNodes);
  +     }
  +
  +     // Create an object to set and restore the context node list...
  +     StylesheetExecutionContext::ContextNodeListSetAndRestore        
theSetAndRestore(
                                executionContext,
                                sourceNodes);
   
  -             for(unsigned int i = 0; i < nNodes; i++) 
  -             {
  -                     XalanNode*                              childNode = 
sourceNodes.item(i);
  -                     assert(childNode != 0);
  -
  -                     XalanDocument* const    ownerDoc = 
childNode->getOwnerDocument();
  +     for(unsigned int i = 0; i < sourceNodesCount; i++) 
  +     {
  +             XalanNode* const                childNode = sourceNodes.item(i);
  +             assert(childNode != 0);
   
  -                     if(XalanNode::DOCUMENT_NODE != childNode->getNodeType() 
&& ownerDoc == 0)
  -                     {
  -                             error(XalanDOMString("Child node does not have 
an owner document!"));
  -                     }
  +             XalanDocument* const    ownerDoc = 
childNode->getOwnerDocument();
   
  -                     transformChild(
  -                                     executionContext,
  -                                     stylesheetTree,
  -                                     &xslInstruction,
  -                                     theTemplate,
  -                                     sourceTree,
  -                                     sourceNodeContext, 
  -                                     childNode,
  -                                     mode,
  -                                     xslToken);
  +             if(XalanNode::DOCUMENT_NODE != childNode->getNodeType() && 
ownerDoc == 0)
  +             {
  +                     error(XalanDOMString("Child node does not have an owner 
document!"));
                }
  +
  +             transformChild(
  +                             executionContext,
  +                             stylesheetTree,
  +                             &xslInstruction,
  +                             theTemplate,
  +                             sourceTree,
  +                             sourceNodeContext, 
  +                             childNode,
  +                             mode,
  +                             xslToken);
        }
   }
   
  
  
  
  1.13      +82 -2     xml-xalan/c/src/XSLT/ElemTemplateElement.hpp
  
  Index: ElemTemplateElement.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemTemplateElement.hpp,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ElemTemplateElement.hpp   2000/06/08 17:54:26     1.12
  +++ ElemTemplateElement.hpp   2000/07/25 14:49:32     1.13
  @@ -81,7 +81,12 @@
   
   
   
  +#include <XSLT/NodeSorter.hpp>
  +
  +
  +
   class AttributeList;
  +class NodeRefListBase;
   class QName;
   class Stylesheet;
   class StylesheetConstructionContext;
  @@ -676,8 +681,83 @@
                        XalanNode*                                              
sourceNodeContext,
                        const QName&                                    mode,
                        const XPath*                                    
selectPattern,
  -                     int     xslToken,
  -                     int selectStackFrameIndex) const;
  +                     int                                                     
        xslToken,
  +                     int                                                     
        selectStackFrameIndex) const;
  +
  +     /**
  +      * Perform a query if needed, and call transformChild for each child.
  +      * 
  +      * @param stylesheetTree The owning stylesheet tree.
  +      * @param xslInstruction The stylesheet element context (deprecated -- 
I do 
  +      *      not think we need this).
  +      * @param template The owning template context.
  +      * @param sourceTree The input source tree.
  +      * @param sourceNodeContext The current source node context.
  +      * @param mode The current mode.
  +      * @param selectPattern The XPath with which to perform the selection.
  +      * @param xslToken The current XSLT instruction (deprecated -- I do not 
    
  +      *     think we want this).
  +      * @param selectStackFrameIndex stack frame context for executing the
  +      *                              select statement
  +      */
  +     void
  +     doTransformSelectedChildren(
  +                     StylesheetExecutionContext&                             
        executionContext,
  +                     const Stylesheet&                                       
                stylesheetTree,
  +                     const ElemTemplateElement&                              
        xslInstruction,
  +                     const ElemTemplateElement*                              
        theTemplate,
  +                     XalanNode*                                              
                        sourceTree,
  +                     XalanNode*                                              
                        sourceNodeContext,
  +                     const QName&                                            
                mode,
  +                     int                                                     
                                xslToken,
  +                     int                                                     
                                selectStackFrameIndex,
  +                     const NodeSorter::NodeSortKeyVectorType&        keys,
  +                     const NodeRefListBase&                                  
        sourceNodes,
  +                     unsigned int                                            
                sourceNodesCount) const;
  +
  +     /**
  +      * Perform a query if needed, and call transformChild for each child.
  +      * 
  +      * @param stylesheetTree The owning stylesheet tree.
  +      * @param xslInstruction The stylesheet element context (deprecated -- 
I do 
  +      *      not think we need this).
  +      * @param template The owning template context.
  +      * @param sourceTree The input source tree.
  +      * @param sourceNodeContext The current source node context.
  +      * @param mode The current mode.
  +      * @param selectPattern The XPath with which to perform the selection.
  +      * @param xslToken The current XSLT instruction (deprecated -- I do not 
    
  +      *     think we want this).
  +      * @param selectStackFrameIndex stack frame context for executing the
  +      *                              select statement
  +      */
  +     void
  +     doTransformSelectedChildren(
  +                     StylesheetExecutionContext&                             
        executionContext,
  +                     const Stylesheet&                                       
                stylesheetTree,
  +                     const ElemTemplateElement&                              
        xslInstruction,
  +                     const ElemTemplateElement*                              
        theTemplate,
  +                     XalanNode*                                              
                        sourceTree,
  +                     XalanNode*                                              
                        sourceNodeContext,
  +                     const QName&                                            
                mode,
  +                     int                                                     
                                xslToken,
  +                     int                                                     
                                selectStackFrameIndex,
  +                     const NodeSorter::NodeSortKeyVectorType&        keys,
  +                     const XalanNodeList&                                    
        childNodes,
  +                     unsigned int                                            
                childNodeCount) const;
  +
  +     void
  +     doTransformSelectedChildren(
  +                     StylesheetExecutionContext&                     
executionContext,
  +                     const Stylesheet&                                       
stylesheetTree,
  +                     const ElemTemplateElement&                      
xslInstruction,
  +                     const ElemTemplateElement*                      
theTemplate,
  +                     XalanNode*                                              
        sourceTree,
  +                     XalanNode*                                              
        sourceNodeContext,
  +                     const QName&                                            
mode,
  +                     int                                                     
                xslToken,
  +                     const NodeRefListBase&                          
sourceNodes,
  +                     unsigned int                                            
sourceNodesCount) const;
   
     /**
      * Tell if the result namespace decl should be excluded.  Should be called 
before 
  
  
  

Reply via email to