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 2.6 by greg, Tue Feb 25 02:47:22 2003 UTC vs.
Revision 2.12 by greg, Sat Dec 28 18:05:14 2019 UTC

# Line 20 | Line 20 | static const char      RCSid[] = "$Id$";
20  
21   #include "copyright.h"
22  
23 + #include <stdlib.h>
24 +
25 + #include "rtmisc.h"
26 + #include "rterror.h"
27 + #include "rtio.h"
28 +
29   #ifndef  NHASH
30 < #define  NHASH          509             /* hash table size (prime!) */
30 > #define  NHASH          2039            /* hash table size (prime!) */
31   #endif
32  
33   typedef struct s_head {
# Line 33 | Line 39 | static S_HEAD  *stab[NHASH];
39  
40   #define  hash(s)        (shash(s)%NHASH)
41  
36 extern char  *savestr(), *strcpy(), *malloc();
37
38 #define  NULL           0
39
42   #define  string(sp)     ((char *)((sp)+1))
43  
44   #define  salloc(str)    (S_HEAD *)malloc(sizeof(S_HEAD)+1+strlen(str))
# Line 45 | Line 47 | extern char  *savestr(), *strcpy(), *malloc();
47  
48  
49   char *
50 < savestr(str)                            /* save a string */
49 < char  *str;
50 > savestr(char *str)                              /* save a string */
51   {
52 <        register int  hval;
53 <        register S_HEAD  *sp;
52 >        int  hval;
53 >        S_HEAD  *sp;
54  
55          if (str == NULL)
56                  return(NULL);
57 +        if (!*str)
58 +                return "";
59          hval = hash(str);
60          for (sp = stab[hval]; sp != NULL; sp = sp->next)
61                  if (!strcmp(str, string(sp))) {
# Line 72 | Line 75 | char  *str;
75  
76  
77   void
78 < freestr(s)                              /* free a string */
76 < char  *s;
78 > freestr(char *s)                                /* free a string */
79   {
80          int  hval;
81 <        register S_HEAD  *spl, *sp;
81 >        S_HEAD  *spl, *sp;
82  
83 <        if (s == NULL)
83 >        if (s == NULL || !*s)
84                  return;
85          hval = hash(s);
86          for (spl = NULL, sp = stab[hval]; sp != NULL; spl = sp, sp = sp->next)
# Line 96 | Line 98 | char  *s;
98  
99  
100   int
101 < shash(s)
100 < register char  *s;
101 > shash(char *s)
102   {
103 <        register int  h = 0;
103 >        int  h = 0;
104  
105          while (*s)
106                  h = (h<<1 & 0x7fff) ^ (*s++ & 0xff);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines