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.13 by greg, Fri May 7 03:09:45 2021 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines