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.8 by schorsch, Mon Oct 27 10:19:31 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 <string.h>
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 46 | Line 47 | static S_HEAD  *stab[NHASH];
47  
48  
49   char *
50 < savestr(str)                            /* save a string */
50 < 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 73 | Line 75 | char  *str;
75  
76  
77   void
78 < freestr(s)                              /* free a string */
77 < 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 97 | Line 98 | char  *s;
98  
99  
100   int
101 < shash(s)
101 < 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