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

Comparing ray/src/common/savestr.c (file contents):
Revision 2.10 by greg, Thu Mar 4 16:34:34 2004 UTC vs.
Revision 2.15 by greg, Mon Jun 23 19:55:51 2025 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 <string.h>
23   #include <stdlib.h>
24  
26 #include "rtmisc.h"
25   #include "rterror.h"
26   #include "rtio.h"
27  
28   #ifndef  NHASH
29 + #ifdef  SMLMEM
30   #define  NHASH          2039            /* hash table size (prime!) */
31 + #else
32 + #define  NHASH          17117           /* hash table size (prime!) */
33   #endif
34 + #endif
35  
36   typedef struct s_head {
37          struct s_head  *next;           /* next in hash list */
# Line 48 | Line 50 | static S_HEAD  *stab[NHASH];
50  
51  
52   char *
53 < savestr(char *str)                              /* save a string */
53 > savestr(const char *str)                        /* save a string */
54   {
55 <        register int  hval;
56 <        register S_HEAD  *sp;
55 >        int  hval;
56 >        S_HEAD  *sp;
57  
58          if (str == NULL)
59                  return(NULL);
60 +        if (!*str)
61 +                return "";
62          hval = hash(str);
63          for (sp = stab[hval]; sp != NULL; sp = sp->next)
64                  if (!strcmp(str, string(sp))) {
# Line 77 | Line 81 | void
81   freestr(char *s)                                /* free a string */
82   {
83          int  hval;
84 <        register S_HEAD  *spl, *sp;
84 >        S_HEAD  *spl, *sp;
85  
86 <        if (s == NULL)
86 >        if (s == NULL || !*s)
87                  return;
88          hval = hash(s);
89          for (spl = NULL, sp = stab[hval]; sp != NULL; spl = sp, sp = sp->next)
# Line 97 | Line 101 | freestr(char *s)                               /* free a string */
101  
102  
103   int
104 < shash(register char  *s)
104 > shash(const char *s)
105   {
106 <        register int  h = 0;
106 >        int  h = 0;
107  
108          while (*s)
109                  h = (h<<1 & 0x7fff) ^ (*s++ & 0xff);

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)