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.11 by greg, Sun Apr 9 21:33:24 2017 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines