You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by am...@apache.org on 2005/02/08 10:21:11 UTC

cvs commit: xml-xerces/c/src/xercesc/util RefHashTableOf.c RefHashTableOf.hpp

amassari    2005/02/08 01:21:11

  Modified:    c/src/xercesc/internal ReaderMgr.hpp
               c/src/xercesc/util RefHashTableOf.c RefHashTableOf.hpp
  Log:
  Removed warnings
  
  Revision  Changes    Path
  1.15      +14 -13    xml-xerces/c/src/xercesc/internal/ReaderMgr.hpp
  
  Index: ReaderMgr.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/ReaderMgr.hpp,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ReaderMgr.hpp	8 Sep 2004 13:56:13 -0000	1.14
  +++ ReaderMgr.hpp	8 Feb 2005 09:21:11 -0000	1.15
  @@ -16,6 +16,9 @@
   
   /*
    * $Log$
  + * Revision 1.15  2005/02/08 09:21:11  amassari
  + * Removed warnings
  + *
    * Revision 1.14  2004/09/08 13:56:13  peiyongz
    * Apache License Version 2.0
    *
  @@ -440,27 +443,25 @@
   
   inline void ReaderMgr::skipToChar(const XMLCh toSkipTo)
   {
  -    while (true)
  +	XMLCh nextCh = 0;
  +    do
       {
           // Get chars until we find the one to skip
  -        const XMLCh nextCh = getNextChar();
  -
  -        // Break out at end of input or the char to skip
  -        if ((nextCh == toSkipTo) || !nextCh)
  -            break;
  -    }
  +        nextCh = getNextChar();
  +	} 
  +    // Break out at end of input or the char to skip
  +	while((nextCh != toSkipTo) && nextCh!=0);
   }
   
   inline void ReaderMgr::skipPastChar(const XMLCh toSkipPast)
   {
  -    while (true)
  +	XMLCh nextCh = 0;
  +    do
       {
           // Get chars until we find the one to skip
  -        const XMLCh nextCh = getNextChar();
  -
  -        if ((nextCh == toSkipPast) || !nextCh)
  -            break;
  -    }
  +        nextCh = getNextChar();
  +	} 
  +	while((nextCh != toSkipPast) && nextCh!=0);
   }
   
   inline bool ReaderMgr::peekString(const XMLCh* const toPeek)
  
  
  
  1.20      +65 -78    xml-xerces/c/src/xercesc/util/RefHashTableOf.c
  
  Index: RefHashTableOf.c
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/RefHashTableOf.c,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- RefHashTableOf.c	7 Jan 2005 15:12:10 -0000	1.19
  +++ RefHashTableOf.c	8 Feb 2005 09:21:11 -0000	1.20
  @@ -16,6 +16,9 @@
   
   /**
    * $Log$
  + * Revision 1.20  2005/02/08 09:21:11  amassari
  + * Removed warnings
  + *
    * Revision 1.19  2005/01/07 15:12:10  amassari
    * Removed warnings
    *
  @@ -203,11 +206,7 @@
   
   template <class TVal> RefHashTableOf<TVal>::~RefHashTableOf()
   {
  -    removeAll();
  -
  -    // Then delete the bucket list & hasher
  -    fMemoryManager->deallocate(fBucketList); //delete [] fBucketList;
  -    delete fHash;
  +    cleanup();
   }
   
   
  @@ -216,13 +215,7 @@
   // ---------------------------------------------------------------------------
   template <class TVal> bool RefHashTableOf<TVal>::isEmpty() const
   {
  -    // Just check the bucket list for non-empty elements
  -    for (unsigned int buckInd = 0; buckInd < fHashModulus; buckInd++)
  -    {
  -        if (fBucketList[buckInd] != 0)
  -            return false;
  -    }
  -    return true;
  +    return fCount==0;
   }
   
   template <class TVal> bool RefHashTableOf<TVal>::
  @@ -236,12 +229,64 @@
   template <class TVal> void RefHashTableOf<TVal>::
   removeKey(const void* const key)
   {
  -    unsigned int hashVal;
  -    removeBucketElem(key, hashVal);
  +    // Hash the key
  +    unsigned int hashVal = fHash->getHashVal(key, fHashModulus, fMemoryManager);
  +    assert(hashVal < fHashModulus);
  +
  +    //
  +    //  Search the given bucket for this key. Keep up with the previous
  +    //  element so we can patch around it.
  +    //
  +    RefHashTableBucketElem<TVal>* curElem = fBucketList[hashVal];
  +    RefHashTableBucketElem<TVal>* lastElem = 0;
  +
  +    while (curElem)
  +    {
  +        if (fHash->equals(key, curElem->fKey))
  +        {
  +            if (!lastElem)
  +            {
  +                // It was the first in the bucket
  +                fBucketList[hashVal] = curElem->fNext;
  +            }
  +             else
  +            {
  +                // Patch around the current element
  +                lastElem->fNext = curElem->fNext;
  +            }
  +
  +            // If we adopted the data, then delete it too
  +            //    (Note:  the userdata hash table instance has data type of void *.
  +            //    This will generate compiler warnings here on some platforms, but they
  +            //    can be ignored since fAdoptedElements is false.
  +            if (fAdoptedElems)
  +                delete curElem->fData;
  +
  +            // Then delete the current element and move forward
  + 	        // delete curElem;
  +            // destructor doesn't do anything...
  +			// curElem->~RefHashTableBucketElem();
  +            fMemoryManager->deallocate(curElem);            
  +
  +            fCount--;
  +
  +            return;
  +        }
  +
  +        // Move both pointers upwards
  +        lastElem = curElem;
  +        curElem = curElem->fNext;
  +    }
  +
  +    // We never found that key
  +    ThrowXMLwithMemMgr(NoSuchElementException, XMLExcepts::HshTbl_NoSuchKeyExists, fMemoryManager);
   }
   
   template <class TVal> void RefHashTableOf<TVal>::removeAll()
   {
  +    if(isEmpty())
  +        return;
  +
       // Clean up the buckets first
       for (unsigned int buckInd = 0; buckInd < fHashModulus; buckInd++)
       {
  @@ -303,7 +348,7 @@
                   // It was the first in the bucket
                   fBucketList[hashVal] = curElem->fNext;
               }
  -             else
  +            else
               {
                   // Patch around the current element
                   lastElem->fNext = curElem->fNext;
  @@ -336,7 +381,7 @@
   //   similar to destructor
   //   called to cleanup the memory, in case destructor cannot be called
   //
  -template <class TElem> void RefHashTableOf<TElem>::cleanup()
  +template <class TVal> void RefHashTableOf<TVal>::cleanup()
   {
       removeAll();
   
  @@ -351,7 +396,7 @@
   //   similar to constructor
   //   called to re-construct the fElemList from scratch again
   //
  -template <class TElem> void RefHashTableOf<TElem>::reinitialize(HashBase* hashBase)
  +template <class TVal> void RefHashTableOf<TVal>::reinitialize(HashBase* hashBase)
   {
       if (fBucketList || fHash)
           cleanup();
  @@ -375,7 +420,7 @@
   // except that the data is not deleted in "removeKey" even it is adopted so that it
   // can be transferred to key2.
   // whatever key2 has originally will be purged (if adopted)
  -template <class TElem> void RefHashTableOf<TElem>::transferElement(const void* const key1, void* key2)
  +template <class TVal> void RefHashTableOf<TVal>::transferElement(const void* const key1, void* key2)
   {
       put(key2, orphanKey(key1));
   }
  @@ -451,7 +496,7 @@
           newBucket->fData = valueToAdopt;
   		newBucket->fKey = key;
       }
  -     else
  +    else
       {
           //newBucket = new (fMemoryManager) RefHashTableBucketElem<TVal>(key, valueToAdopt, fBucketList[hashVal]);
   		newBucket =
  @@ -550,61 +595,6 @@
   }
   
   
  -template <class TVal> void RefHashTableOf<TVal>::
  -removeBucketElem(const void* const key, unsigned int& hashVal)
  -{
  -    // Hash the key
  -    hashVal = fHash->getHashVal(key, fHashModulus, fMemoryManager);
  -    assert(hashVal < fHashModulus);
  -
  -    //
  -    //  Search the given bucket for this key. Keep up with the previous
  -    //  element so we can patch around it.
  -    //
  -    RefHashTableBucketElem<TVal>* curElem = fBucketList[hashVal];
  -    RefHashTableBucketElem<TVal>* lastElem = 0;
  -
  -    while (curElem)
  -    {
  -        if (fHash->equals(key, curElem->fKey))
  -        {
  -            if (!lastElem)
  -            {
  -                // It was the first in the bucket
  -                fBucketList[hashVal] = curElem->fNext;
  -            }
  -             else
  -            {
  -                // Patch around the current element
  -                lastElem->fNext = curElem->fNext;
  -            }
  -
  -            // If we adopted the elements, then delete the data
  -            if (fAdoptedElems)
  -                delete curElem->fData;
  -
  -            // Delete the current element
  -            // delete curElem;
  -            // destructor doesn't do anything...
  -			// curElem->~RefHashTableBucketElem();
  -            fMemoryManager->deallocate(curElem);            
  -
  -            fCount--;
  -
  -            return;
  -        }
  -
  -        // Move both pointers upwards
  -        lastElem = curElem;
  -        curElem = curElem->fNext;
  -    }
  -
  -    // We never found that key
  -    ThrowXMLwithMemMgr(NoSuchElementException, XMLExcepts::HshTbl_NoSuchKeyExists, fMemoryManager);
  -}
  -
  -
  -
   // ---------------------------------------------------------------------------
   //  RefHashTableOfEnumerator: Constructors and Destructor
   // ---------------------------------------------------------------------------
  @@ -725,11 +715,8 @@
               return;
   
           // Else find the next non-empty bucket
  -        while (true)
  +        while (fToEnum->fBucketList[fCurHash]==0)
           {
  -            if (fToEnum->fBucketList[fCurHash])
  -                break;
  -
               // Bump to the next hash value. If we max out return
               fCurHash++;
               if (fCurHash == fToEnum->fHashModulus)
  
  
  
  1.17      +6 -4      xml-xerces/c/src/xercesc/util/RefHashTableOf.hpp
  
  Index: RefHashTableOf.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/RefHashTableOf.hpp,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- RefHashTableOf.hpp	19 Nov 2004 00:50:22 -0000	1.16
  +++ RefHashTableOf.hpp	8 Feb 2005 09:21:11 -0000	1.17
  @@ -16,6 +16,9 @@
   
   /*
    * $Log$
  + * Revision 1.17  2005/02/08 09:21:11  amassari
  + * Removed warnings
  + *
    * Revision 1.16  2004/11/19 00:50:22  cargilld
    * Memory improvement to utility classes from Christian Will.  Remove dependency on XMemory.
    *
  @@ -238,7 +241,6 @@
       // -----------------------------------------------------------------------
       RefHashTableBucketElem<TVal>* findBucketElem(const void* const key, unsigned int& hashVal);
       const RefHashTableBucketElem<TVal>* findBucketElem(const void* const key, unsigned int& hashVal) const;
  -    void removeBucketElem(const void* const key, unsigned int& hashVal);
       void initialize(const unsigned int modulus);
       void rehash();
   
  @@ -258,9 +260,9 @@
       //  fHashModulus
       //      The modulus used for this hash table, to hash the keys. This is
       //      also the number of elements in the bucket list.
  -	//
  -	//  fHash
  -	//      The hasher for the key data type.
  +    //
  +    //  fHash
  +    //      The hasher for the key data type.
       // -----------------------------------------------------------------------
       MemoryManager*                 fMemoryManager;
       bool                           fAdoptedElems;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org