ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/savestr.c
(Generate patch)

Comparing ray/src/common/savestr.c (file contents):
Revision 1.3 by greg, Mon Oct 28 09:47:27 1991 UTC vs.
Revision 2.4 by greg, Thu Sep 23 12:15:21 1993 UTC

# Line 33 | Line 33 | typedef struct s_head {
33  
34   static S_HEAD  *stab[NHASH];
35  
36 < static int  shash();
36 > #define  hash(s)        (shash(s)%NHASH)
37  
38   extern char  *savestr(), *strcpy(), *malloc();
39  
# Line 55 | Line 55 | char  *str;
55  
56          if (str == NULL)
57                  return(NULL);
58 <        hval = shash(str);
58 >        hval = hash(str);
59          for (sp = stab[hval]; sp != NULL; sp = sp->next)
60                  if (!strcmp(str, string(sp))) {
61                          sp->nl++;
# Line 81 | Line 81 | char  *s;
81  
82          if (s == NULL)
83                  return;
84 <        hval = shash(s);
84 >        hval = hash(s);
85          for (spl = NULL, sp = stab[hval]; sp != NULL; spl = sp, sp = sp->next)
86                  if (s == string(sp)) {
87                          if (--sp->nl > 0)
# Line 97 | Line 97 | char  *s;
97  
98  
99   int
100 < strcmp(s1, s2)                          /* check for s1==s2 */
101 < register char  *s1, *s2;
102 < {
103 <        if (s1 == s2)
104 <                return(0);
105 <
106 <        while (*s1 == *s2++)
107 <                if (!*s1++)
108 <                        return(0);
109 <
110 <        return(*s1 - *--s2);
111 < }
112 <
113 <
114 < static int
115 < shash(s)                                /* hash a string */
100 > shash(s)
101   register char  *s;
102   {
103          register int  h = 0;
104  
105          while (*s)
106 <                h += *s++;
107 <
123 <        return(h % NHASH);
106 >                h = (h<<1 & 0x7fff) ^ (*s++ & 0xff);
107 >        return(h);
108   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines