Changeset 8 for trunk/src/sh_hash.c


Ignore:
Timestamp:
Dec 31, 2005, 2:02:03 PM (19 years ago)
Author:
rainer
Message:

minor optimisations for speed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_hash.c

    r3 r8  
    7171static char * unquote_string (char * str)
    7272{
    73   int    i = 0, j, k = 0, len;
    74   char * tmp;
     73  int    i = 0, j, k = 0, len, t1, t2, l2;
     74  char * tmp = NULL;
    7575
    7676  SL_ENTER(_("unquote_string"));
    7777
    78   if (str == NULL)
    79     {
    80       SL_RETURN(NULL, _("unquote_string"));
    81     }
    82 
    83   len = sl_strlen(str);
    84 
    85   tmp = SH_ALLOC(len + 1);
    86   for (j = 0; j <= len; ++j)
    87     {
    88       if (str[j] == QUOTE_CHAR && j < (len-2))
    89         {
    90           if (sh_util_hexchar(str[j+1]) >= 0 && sh_util_hexchar(str[j+2]) >= 0)
    91             {
    92               i = 16 * sh_util_hexchar(str[j+1]) + sh_util_hexchar(str[j+2]);
    93               tmp[k] = i; j += 2;
    94             }
    95           else
     78  if (str != NULL)
     79    {
     80      len = sl_strlen(str);
     81      l2  = len - 2;
     82      tmp = SH_ALLOC(len + 1);
     83
     84      for (j = 0; j <= len; ++j)
     85        {
     86          if (str[j] != QUOTE_CHAR)
    9687            {
    9788              tmp[k] = str[j];
    9889            }
    99         }
    100       else
    101         tmp[k] = str[j];
    102       ++k;
     90          else if (str[j] == QUOTE_CHAR && j < l2)
     91            {
     92              t1 = sh_util_hexchar(str[j+1]);
     93              t2 = sh_util_hexchar(str[j+2]);
     94              if ((t1|t2) >= 0)
     95                {
     96                  i = 16 * t1 + t2;
     97                  tmp[k] = i;
     98                  j += 2;
     99                }
     100              else
     101                {
     102                  tmp[k] = str[j];
     103                }
     104            }
     105          else
     106            tmp[k] = str[j];
     107          ++k;
     108        }
    103109    }
    104110  SL_RETURN(tmp, _("unquote_string"));
     
    306312
    307313/* must fit an int              */
    308 #define TABSIZE 2048 
     314/* #define TABSIZE 2048         */
     315#define TABSIZE 65536
    309316
    310317/* must fit an unsigned short   */
     
    386393 *
    387394 **************************************************************/
     395
    388396static int hashfunc(char *s)
    389397{
     
    392400  for ( ; *s; s++)
    393401    n = 31 * n + *s;
    394   return n % TABSIZE;
     402  return n & 0xFFFF;/* % TABSIZE*/;
    395403}
     404
    396405
    397406int hashreport_missing( char *fullpath, int level)
     
    635644  SL_ENTER(_("hashsearch"));
    636645
    637   if (!s)
    638     SL_RETURN( NULL, _("hashsearch"));
    639 
    640   for (p = tab[hashfunc(s)]; p; p = p->next)
    641     if ((p->fullpath != NULL) && (0 == strcmp(s, p->fullpath)))
    642       SL_RETURN( p, _("hashsearch"));
     646  if (s)
     647    {
     648      for (p = tab[hashfunc(s)]; p; p = p->next)
     649        if ((p->fullpath != NULL) && (0 == strcmp(s, p->fullpath)))
     650          SL_RETURN( p, _("hashsearch"));
     651    }
    643652  SL_RETURN( NULL, _("hashsearch"));
    644653}
     
    672681        {
    673682          if (p && p->fullpath &&
    674               0 == strcmp(s->fullpath, p->fullpath) &&
    675               strlen(s->fullpath) == strlen(p->fullpath))
     683              0 == strcmp(s->fullpath, p->fullpath))
    676684            {
    677685              q = p->next;
     
    30643072int hash_remove_tree (char * s)
    30653073{
    3066   sh_file_t * p;
    3067   int         len;
    3068   int        i;
     3074  sh_file_t *  p;
     3075  size_t       len;
     3076  unsigned int i;
    30693077
    30703078  SL_ENTER(_("hash_remove_tree"));
    30713079
    3072   if (!s)
     3080  if (!s || *s == '\0')
    30733081    SL_RETURN ((-1), _("hash_remove_tree"));
    3074   else
    3075     len = sl_strlen(s);
     3082
     3083  len = sl_strlen(s);
    30763084
    30773085  if (IsInit != 1)
     
    30823090      for (p = tab[i]; p; p = p->next)
    30833091        {
    3084           if (sl_strncmp(s, p->fullpath, len) == 0)
     3092          if (p->fullpath && 0 == strncmp(s, p->fullpath, len))
    30853093            {
    30863094              p->allignore  = S_TRUE;
Note: See TracChangeset for help on using the changeset viewer.