dbertoni    2002/10/10 19:02:27

  Modified:    c/src/XSLT ResultNamespacesStack.cpp
                        ResultNamespacesStack.hpp
  Log:
  Experimental functionality.
  
  Revision  Changes    Path
  1.9       +67 -8     xml-xalan/c/src/XSLT/ResultNamespacesStack.cpp
  
  Index: ResultNamespacesStack.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/ResultNamespacesStack.cpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ResultNamespacesStack.cpp 21 Sep 2002 01:24:41 -0000      1.8
  +++ ResultNamespacesStack.cpp 11 Oct 2002 02:02:27 -0000      1.9
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights 
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -61,9 +61,15 @@
   
   
   ResultNamespacesStack::ResultNamespacesStack() :
  -     m_resultNamespaces(),
  +     m_resultNamespaces(1),
  +     m_stackBegin(m_resultNamespaces.begin()),
  +     m_stackPosition(m_stackBegin),
        m_createNewContextStack()
   {
  +     // m_resultNamespaces is initialized to a size of
  +     // 1, so we always have a dummy entry at the
  +     // beginning.  This makes the implementation
  +     // much simpler.
   }
   
   
  @@ -86,12 +92,20 @@
        // Check to see if we need to create a new context and do so if 
necessary...
        if (m_createNewContextStack.back() == true)
        {
  -             m_resultNamespaces.resize(m_resultNamespaces.size() + 1);
  +             ++m_stackPosition;
  +
  +             if (m_stackPosition == m_resultNamespaces.end())
  +             {
  +                     m_resultNamespaces.resize(m_resultNamespaces.size() + 
1);
  +
  +                     m_stackPosition = m_resultNamespaces.end() - 1;
  +                     m_stackBegin = m_resultNamespaces.begin();
  +             }
   
                m_createNewContextStack.back() = false;
        }
   
  -     NamespaceVectorType&    theCurrentNamespaces = 
m_resultNamespaces.back();
  +     NamespaceVectorType&    theCurrentNamespaces = *m_stackPosition;
   
        // Add a new namespace at the end of the current namespaces.
        theCurrentNamespaces.resize(theCurrentNamespaces.size() + 1);
  @@ -125,9 +139,12 @@
   
        if (m_createNewContextStack.back() == false)
        {
  -             assert(m_resultNamespaces.empty() == false);
  +             assert(m_resultNamespaces.empty() == false &&
  +                        m_stackPosition != m_resultNamespaces.begin());
   
  -             m_resultNamespaces.pop_back();
  +             (*m_stackPosition).clear();
  +
  +             --m_stackPosition;
        }
   
        m_createNewContextStack.pop_back();
  @@ -135,6 +152,42 @@
   
   
   
  +const XalanDOMString*
  +ResultNamespacesStack::getNamespaceForPrefix(const XalanDOMString&   
thePrefix) const
  +{
  +     if (m_stackPosition == m_stackBegin)
  +     {
  +             return 0;
  +     }
  +     else
  +     {
  +             return XalanQName::getNamespaceForPrefix(
  +                             m_stackBegin,
  +                             m_stackPosition + 1,
  +                             thePrefix);
  +     }
  +}
  +
  +
  +
  +const XalanDOMString*
  +ResultNamespacesStack::getPrefixForNamespace(const XalanDOMString&   
theNamespaceURI) const
  +{
  +     if (m_stackPosition == m_stackBegin)
  +     {
  +             return 0;
  +     }
  +     else
  +     {
  +             return XalanQName::getPrefixForNamespace(
  +                                     m_stackBegin,
  +                                     m_stackPosition + 1,
  +                                     theNamespaceURI);
  +     }
  +}
  +
  +
  +
   bool
   ResultNamespacesStack::prefixIsPresentLocal(const XalanDOMString&    
thePrefix)
   {
  @@ -145,7 +198,7 @@
        if (m_createNewContextStack.back() == false)
        {
                const NamespaceVectorType&      theNamespaces =
  -                     m_resultNamespaces.back();
  +                     *m_stackPosition;
   
                NamespaceVectorType::const_iterator                     i = 
theNamespaces.begin();
                const NamespaceVectorType::const_iterator       theEnd = 
theNamespaces.end();
  @@ -175,7 +228,13 @@
   void
   ResultNamespacesStack::clear()
   {
  -     m_resultNamespaces.clear();
  +     // Since we always keep one dummy entry at the beginning,
  +     // swap with an OutputContextStackType instance of size 1.
  +     NamespacesStackType(1).swap(m_resultNamespaces);
  +
  +     m_stackBegin = m_resultNamespaces.begin();
  +
  +     m_stackPosition = m_stackBegin;
   
        m_createNewContextStack.clear();
   }
  
  
  
  1.8       +12 -17    xml-xalan/c/src/XSLT/ResultNamespacesStack.hpp
  
  Index: ResultNamespacesStack.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/ResultNamespacesStack.hpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ResultNamespacesStack.hpp 21 Sep 2002 01:24:41 -0000      1.7
  +++ ResultNamespacesStack.hpp 11 Oct 2002 02:02:27 -0000      1.8
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights 
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -132,19 +132,10 @@
        popContext();
   
        const XalanDOMString*
  -     getNamespaceForPrefix(const XalanDOMString&             thePrefix) const
  -     {
  -             // Search vector from first element back
  -             return XalanQName::getNamespaceForPrefix(m_resultNamespaces, 
thePrefix, true);
  -     }
  +     getNamespaceForPrefix(const XalanDOMString&             thePrefix) 
const;
   
        const XalanDOMString*
  -     getPrefixForNamespace(const XalanDOMString&             
theNamespaceURI) const
  -     {
  -             // Search vector from first element back
  -             return XalanQName::getPrefixForNamespace(m_resultNamespaces, 
theNamespaceURI, true);
  -     }
  -
  +     getPrefixForNamespace(const XalanDOMString&             
theNamespaceURI) const;
   
        /**
         * See if the prefix has been mapped to a namespace in the current
  @@ -159,13 +150,13 @@
        size_type
        size() const
        {
  -             return m_resultNamespaces.size();
  +             return m_resultNamespaces.size() - 1;
        }
   
        bool
        empty() const
        {
  -             return m_resultNamespaces.empty();
  +             return NamespacesStackType::const_iterator(m_stackPosition) == 
m_resultNamespaces.begin() ? true : false;
        }
   
   private:
  @@ -179,14 +170,18 @@
        ResultNamespacesStack&
        operator=(const ResultNamespacesStack&);
   
  -     enum { eDefaultCreateNewContextStackSize = 100 };
  +     enum { eDefaultCreateNewContextStackSize = 25 };
   
        /**
         * A stack to keep track of the result tree namespaces.
         */
  -     NamespacesStackType             m_resultNamespaces;
  +     NamespacesStackType                             m_resultNamespaces;
  +
  +     NamespacesStackType::iterator   m_stackBegin;
  +
  +     NamespacesStackType::iterator   m_stackPosition;
   
  -     BoolVectorType                  m_createNewContextStack;
  +     BoolVectorType                                  m_createNewContextStack;
   };
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to