ben         2004/04/11 11:10:49

  Modified:    hooks    Tag: APU_0_9_BRANCH apr_hooks.c
  Log:
  Make the topological sort pull out-of-order items to the front, instead of
  pushing them to the back. This makes things stay where they want to be better.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.47.2.2  +24 -2     apr-util/hooks/apr_hooks.c
  
  Index: apr_hooks.c
  ===================================================================
  RCS file: /home/cvs/apr-util/hooks/apr_hooks.c,v
  retrieving revision 1.47.2.1
  retrieving revision 1.47.2.2
  diff -u -r1.47.2.1 -r1.47.2.2
  --- apr_hooks.c       13 Feb 2004 09:52:42 -0000      1.47.2.1
  +++ apr_hooks.c       11 Apr 2004 18:10:49 -0000      1.47.2.2
  @@ -126,6 +126,13 @@
       return pData;
   }
   
  +/* Topologically sort, dragging out-of-order items to the front. Note that
  +   this tends to preserve things that want to be near the front better, and
  +   changing that behaviour might compromise some of Apache's behaviour (in
  +   particular, mod_log_forensic might otherwise get pushed to the end, and
  +   core.c's log open function used to end up at the end when pushing items
  +   to the back was the methedology).
  +*/
   static TSort *tsort(TSort *pData,int nItems)
   {
       int nTotal;
  @@ -138,9 +145,23 @@
        for(n=0 ; ; ++n) {
            if(n == nItems)
                assert(0);      /* we have a loop... */
  -         if(!pData[n].pNext && !pData[n].nPredecessors)
  +         if(!pData[n].pNext)
                break;
        }
  +     if(pData[n].nPredecessors) {
  +         for(k=0 ; ; ++k) {
  +             assert(k < nItems);
  +             if(pData[n].ppPredecessors[k])
  +                 break;
  +         }
  +         for(i=0 ; ; ++i) {
  +             assert(i < nItems);
  +             if(&pData[i] == pData[n].ppPredecessors[k]) {
  +                 n=i;
  +                 break;
  +             }
  +         }
  +     }
        if(pTail)
            pTail->pNext=&pData[n];
        else
  @@ -148,9 +169,10 @@
        pTail=&pData[n];
        pTail->pNext=pTail;     /* fudge it so it looks linked */
        for(i=0 ; i < nItems ; ++i)
  -         for(k=0 ; pData[i].ppPredecessors[k] ; ++k)
  +         for(k=0 ; k < nItems ; ++k)
                if(pData[i].ppPredecessors[k] == &pData[n]) {
                    --pData[i].nPredecessors;
  +                 pData[i].ppPredecessors[k]=NULL;
                    break;
                }
       }
  
  
  

Reply via email to