dbertoni    2002/08/14 17:44:01

  Modified:    c/src/ICUBridge ICUBridgeCollationCompareFunctorImpl.cpp
                        ICUBridgeCollationCompareFunctorImpl.hpp
  Log:
  Vastly simplified cache.
  
  Revision  Changes    Path
  1.4       +19 -38    
xml-xalan/c/src/ICUBridge/ICUBridgeCollationCompareFunctorImpl.cpp
  
  Index: ICUBridgeCollationCompareFunctorImpl.cpp
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/c/src/ICUBridge/ICUBridgeCollationCompareFunctorImpl.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ICUBridgeCollationCompareFunctorImpl.cpp  12 Aug 2002 03:54:43 -0000      
1.3
  +++ ICUBridgeCollationCompareFunctorImpl.cpp  15 Aug 2002 00:44:01 -0000      
1.4
  @@ -434,14 +434,14 @@
        using std::find_if;
   #endif
   
  -     CollatorCacheDequeType&         theNonConstCache =
  +     CollatorCacheListType&          theNonConstCache =
   #if defined(XALAN_NO_MUTABLE)
  -             (CollatorCacheDequeType*)m_collatorCache;
  +             (CollatorCacheListType*)m_collatorCache;
   #else
                m_collatorCache;
   #endif
   
  -     CollatorCacheDequeType::iterator        i =
  +     CollatorCacheListType::iterator i =
                find_if(
                        theNonConstCache.begin(),
                        theNonConstCache.end(),
  @@ -456,7 +456,7 @@
                // Let's do a quick check to see if we found the first entry.
                // If so, we don't have to update the cache, so just return the
                // appropriate value...
  -             const CollatorCacheDequeType::iterator  theBegin =
  +             const CollatorCacheListType::iterator   theBegin =
                        theNonConstCache.begin();
   
                if (i == theBegin)
  @@ -465,35 +465,14 @@
                }
                else
                {
  -                     // Make a new instance for the cache, then swap it with
  -                     // the one we found.
  -                     CollatorCacheDequeType::value_type      theEntry;
  -
  -                     theEntry.swap(*i);
  -
  -                     // Protect the collator instance, since what we're doing
  -                     // might throw an exception...
  -                     XalanAutoPtr<CollatorType>      
theCollator(theEntry.m_collator);
  -
  -                     // OK, now swap everything from i down to begin()...
  -                     
  -                     CollatorCacheDequeType::iterator        theOther(i);
  -
  -                     do
  -                     {
  -                             --theOther;
  -
  -                             (*i).swap(*theOther);
  -
  -                             --i;
  -                     }
  -                     while(i != theBegin);
  -
  -                     // Now, swap the latest one into the front...
  -                     theEntry.swap(*theBegin);
  -                     
  -                     // Everything's OK, so release to return the value...
  -                     return theCollator.release();
  +                     // Save the collator, because splice() may invalidate
  +                     // i.
  +                     CollatorType* const             theCollator = 
(*i).m_collator;
  +
  +                     // Move the entry to the beginning the cache
  +                     theNonConstCache.splice(theBegin, theNonConstCache, i);
  +
  +                     return theCollator;
                }
        }
   }
  @@ -508,23 +487,25 @@
        assert(theCollator != 0);
        assert(theLocale != 0);
   
  -     CollatorCacheDequeType&         theNonConstCache =
  +     CollatorCacheListType&          theNonConstCache =
   #if defined(XALAN_NO_MUTABLE)
  -             (CollatorCacheDequeType*)m_collatorCache;
  +             (CollatorCacheListType*)m_collatorCache;
   #else
                m_collatorCache;
   #endif
   
  +     // Is the cache full?
        if (theNonConstCache.size() == eCacheMax)
        {
  -             delete theNonConstCache.back().m_collator;
  +             // Yes, so guard the collator instance, in case pop_back() 
throws...
  +             XalanAutoPtr<CollatorType>      
theCollatorGuard(theNonConstCache.back().m_collator);
   
                theNonConstCache.pop_back();
        }
   
  -     theNonConstCache.push_front(CollatorCacheDequeType::value_type());
  +     theNonConstCache.push_front(CollatorCacheListType::value_type());
   
  -     CollatorCacheDequeType::value_type&             theEntry = 
  +     CollatorCacheListType::value_type&              theEntry = 
                theNonConstCache.front();
   
        // Set the locale first, since that might throw an exception...
  
  
  
  1.4       +4 -4      
xml-xalan/c/src/ICUBridge/ICUBridgeCollationCompareFunctorImpl.hpp
  
  Index: ICUBridgeCollationCompareFunctorImpl.hpp
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/c/src/ICUBridge/ICUBridgeCollationCompareFunctorImpl.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ICUBridgeCollationCompareFunctorImpl.hpp  12 Aug 2002 03:54:43 -0000      
1.3
  +++ ICUBridgeCollationCompareFunctorImpl.hpp  15 Aug 2002 00:44:01 -0000      
1.4
  @@ -64,7 +64,7 @@
   
   
   
  -#include <deque>
  +#include <list>
   
   
   
  @@ -177,9 +177,9 @@
        };
   
   #if defined(XALAN_NO_NAMESPACES)
  -     typedef deque<CollationCacheStruct>                     
CollatorCacheDequeType;
  +     typedef list<CollationCacheStruct>                      
CollatorCacheListType;
   #else
  -     typedef std::deque<CollationCacheStruct>        CollatorCacheDequeType;
  +     typedef std::list<CollationCacheStruct>         CollatorCacheListType;
   #endif
   
        enum { eCacheMax = 10 };
  @@ -236,7 +236,7 @@
   
        bool                                                    
m_cacheCollators;
   
  -     mutable CollatorCacheDequeType  m_collatorCache;
  +     mutable CollatorCacheListType   m_collatorCache;
   
        const static 
StylesheetExecutionContextDefault::DefaultCollationCompareFunctor  
s_defaultFunctor;
   };
  
  
  

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

Reply via email to