--- ray/src/common/savestr.c 1989/02/02 10:34:40 1.1 +++ ray/src/common/savestr.c 1993/09/23 12:15:21 2.4 @@ -1,8 +1,10 @@ -/* +/* Copyright 1988 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; #endif + +/* * savestr.c - routines for efficient string storage. * * Savestr(s) stores a shared read-only string. @@ -31,6 +33,8 @@ typedef struct s_head { static S_HEAD *stab[NHASH]; +#define hash(s) (shash(s)%NHASH) + extern char *savestr(), *strcpy(), *malloc(); #define NULL 0 @@ -51,7 +55,7 @@ char *str; if (str == NULL) return(NULL); - hval = shash(str); + hval = hash(str); for (sp = stab[hval]; sp != NULL; sp = sp->next) if (!strcmp(str, string(sp))) { sp->nl++; @@ -77,7 +81,7 @@ char *s; if (s == NULL) return; - hval = shash(s); + hval = hash(s); for (spl = NULL, sp = stab[hval]; sp != NULL; spl = sp, sp = sp->next) if (s == string(sp)) { if (--sp->nl > 0) @@ -93,28 +97,12 @@ char *s; int -strcmp(s1, s2) /* check for s1==s2 */ -register char *s1, *s2; -{ - if (s1 == s2) - return(0); - - while (*s1 == *s2++) - if (!*s1++) - return(0); - - return(*s1 - *--s2); -} - - -static int -shash(s) /* hash a string */ +shash(s) register char *s; { register int h = 0; while (*s) - h += *s++; - - return(h % NHASH); + h = (h<<1 & 0x7fff) ^ (*s++ & 0xff); + return(h); }