Changeset 5838 for trunk/src


Ignore:
Timestamp:
May 30, 2001, 3:02:55 PM (24 years ago)
Author:
phaller
Message:

.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/ccollection.cpp

    r5832 r5838  
    1 /* $Id: ccollection.cpp,v 1.3 2001-05-30 03:28:02 phaller Exp $ */
     1/* $Id: ccollection.cpp,v 1.4 2001-05-30 13:02:55 phaller Exp $ */
    22
    33/*
     
    652652    {
    653653        PHASHTABLEENTRY pHTE = (PHASHTABLEENTRY)pLLE->pObject;
    654         if (strcmp(pHTE->pszName, pszName) == 0)
    655         {
    656             // save old object pointer
    657             void* pTemp = pHTE->pObject;
    658             free(pHTE);
    659 
    660             // found the correct entry
    661             parrLists[ulHash]->removeElement(pLLE);
    662 
    663             // count allocated elements
    664             iElements--;
    665 
    666             // return old object pointer to signal success
    667             return pTemp;
    668         }
     654
     655        // quickly compare 1st character for equality
     656        // before doing the strcmp call
     657        if (*pHTE->pszName == *pszName)
     658            if (strcmp(pHTE->pszName, pszName) == 0)
     659            {
     660                // save old object pointer
     661                void* pTemp = pHTE->pObject;
     662                free(pHTE);
     663
     664                // found the correct entry
     665                parrLists[ulHash]->removeElement(pLLE);
     666
     667                // count allocated elements
     668                iElements--;
     669
     670                // return old object pointer to signal success
     671                return pTemp;
     672            }
    669673
    670674        pLLE = pLLE->pNext;
     
    702706    {
    703707        PHASHTABLEENTRY pHTE = (PHASHTABLEENTRY)pLLE->pObject;
    704         if (strcmp(pHTE->pszName, pszName) == 0)
    705         {
    706             // return result
    707             return pHTE->pObject;
    708         }
     708
     709        // quickly compare 1st character for equality
     710        // before doing the strcmp call
     711        if (*pHTE->pszName == *pszName)
     712            if (strcmp(pHTE->pszName, pszName) == 0)
     713            {
     714                // return result
     715                return pHTE->pObject;
     716            }
    709717
    710718        pLLE = pLLE->pNext;
     
    735743void  CHashtableLookup::rehash()
    736744{
     745    // if there are less slots than elements,
     746    // the blocking factor is expected to be high
     747    setSize(iElements);
     748}
     749
     750
     751void  CHashtableLookup::setSize(int iNewSize)
     752{
    737753    // determine number of allocated elements
    738754    // actually, we need the prime next to
    739755    // the given number.
    740     int iNewSize = nextPrime(iElements);
    741 
    742     setSize(iNewSize);
    743 }
    744 
    745 
    746 void  CHashtableLookup::setSize(int iNewSize)
     756    if (iSize < iNewSize)
     757        setSize0(nextPrime(iNewSize));
     758}
     759
     760
     761void  CHashtableLookup::setSize0(int iNewSize)
    747762{
    748763    // check if rehashing is necessary at all
Note: See TracChangeset for help on using the changeset viewer.