dbertoni    01/04/27 12:19:27

  Modified:    c/src/PlatformSupport XalanDOMStringPool.cpp
                        XalanDOMStringPool.hpp
  Log:
  Improve insertion speed of keys.
  
  Revision  Changes    Path
  1.8       +18 -10    xml-xalan/c/src/PlatformSupport/XalanDOMStringPool.cpp
  
  Index: XalanDOMStringPool.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/XalanDOMStringPool.cpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XalanDOMStringPool.cpp    2001/04/13 01:48:05     1.7
  +++ XalanDOMStringPool.cpp    2001/04/27 19:19:26     1.8
  @@ -166,14 +166,24 @@
        {
                const unsigned int      theActualLength = theLength == 
unsigned(-1) ? length(theString) : theLength;
   
  -             // Find the string...
  -             const IndexMapType::const_iterator      i =
  -                     m_index.find(IndexMapType::key_type(theString, 
theActualLength));
  +#if defined(XALAN_NO_NAMESPACES)
  +             typedef pair<IndexMapType::iterator, bool>                      
InsertPairType;
  +#else
  +             typedef std::pair<IndexMapType::iterator, bool>         
InsertPairType;
  +#endif
   
  -             if (i != m_index.end())
  +             // Insert an entry into the index map.
  +             InsertPairType  i =
  +                     m_index.insert(
  +                             IndexMapType::value_type(
  +                                     IndexMapType::key_type(theString, 
theActualLength),
  +                                     0));
  +
  +             // Was it added?
  +             if (i.second == false)
                {
                        // Already there, so return it...
  -                     return *(*i).second;
  +                     return *(*(i.first)).second;
                }
                else
                {
  @@ -187,11 +197,9 @@
   
                        assert(theActualLength == length(theNewString));
   
  -                     // Add an index entry...
  -                     m_index.insert(
  -                             IndexMapType::value_type(
  -                                     
IndexMapType::key_type(toCharArray(theNewString), theActualLength),
  -                                     &theNewString));
  +                     // Update the index entry that we just inserted...
  +                     (*(i.first)).second = &theNewString;
  +                     
(*(i.first)).first.changePointer(toCharArray(theNewString));
   
                        assert(m_strings.size() == m_index.size());
   
  
  
  
  1.7       +29 -2     xml-xalan/c/src/PlatformSupport/XalanDOMStringPool.hpp
  
  Index: XalanDOMStringPool.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/XalanDOMStringPool.hpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XalanDOMStringPool.hpp    2001/04/11 02:14:08     1.6
  +++ XalanDOMStringPool.hpp    2001/04/27 19:19:26     1.7
  @@ -99,11 +99,38 @@
                bool
                operator<(const StringKey&      theRHS) const;
   
  +             /*
  +              * OK, this is a really big hack.  The problem is that we index
  +              * the strings in the pool by const XalanDOMChar* which are not
  +              * necessarily null-terminated.  An added problem is that is too
  +              * inefficient to search the map for the string, then add it if 
it
  +              * wasn't found.  Instead, we want to insert a new entry in the
  +              * map, then figure out from the result of the insert whether or
  +              * not the entry was found.  This call allows us to change the
  +              * pointer for the key to the persistent pointer from the new
  +              * string that we created, instead of the pointer that was 
passed
  +              * into the call, which is not persistent.  This won't screw up
  +              * the map since the map is ordered on the _value_ of the string
  +              * and not the pointer itself.
  +              *
  +              * @param theNewPointer The new pointer value to use for the 
key.
  +              */
  +             void
  +             changePointer(const XalanDOMChar*       theNewPointer) const
  +             {
  +                     assert(theNewPointer != 0 && equals(theNewPointer, 
m_string, m_length));
  +#if defined(XALAN_NO_MUTABLE)
  +                     ((StringKey*)this)->m_string = theNewPointer;
  +#else
  +                     m_string = theNewPointer;
  +#endif
  +             }
  +
        private:
   
  -             const XalanDOMChar*             m_string;
  +             mutable const XalanDOMChar*             m_string;
   
  -             unsigned int                    m_length;
  +             unsigned int                                    m_length;
        };
   
   #if defined(XALAN_NO_NAMESPACES)
  
  
  

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

Reply via email to