--- deliantra/server/common/shstr.C 2006/08/13 17:16:01 1.1 +++ deliantra/server/common/shstr.C 2006/08/29 08:01:36 1.2 @@ -1,6 +1,6 @@ /* * static char *rcsid_shstr_c = - * "$Id: shstr.C,v 1.1 2006/08/13 17:16:01 elmex Exp $"; + * "$Id: shstr.C,v 1.2 2006/08/29 08:01:36 root Exp $"; * * shstr.c * @@ -65,10 +65,10 @@ GATHER(hash_stats.calls); for (p = str; i < MAXSTRING && *p; p++, i++) { - hash ^= (unsigned long) *p << rot; - rot += 2; - if (rot >= (sizeof(long) - sizeof(char)) * CHAR_BIT) - rot = 0; + hash ^= (unsigned long) *p << rot; + rot += 2; + if (rot >= (sizeof(long) - sizeof(char)) * CHAR_BIT) + rot = 0; } return (hash % TABLESIZE); } @@ -87,7 +87,7 @@ * shared_string struct. */ ss = (shared_string *) malloc(sizeof(shared_string) - PADDING + - strlen(str) + 1); + strlen(str) + 1); ss->u.previous = NULL; ss->next = NULL; ss->refcount = 1; @@ -117,9 +117,9 @@ */ if (str==NULL) { #ifdef MANY_CORES - abort(); + abort(); #else - return NULL; + return NULL; #endif } @@ -129,64 +129,64 @@ /* Is there an entry for that hash? */ if (ss) { - /* Simple case first: See if the first pointer matches. - */ - if (str != ss->string) { - GATHER(add_stats.strcmps); - if (strcmp(ss->string, str)) { - /* Apparantly, a string with the same hash value has this - * slot. We must see in the list if "str" has been - * registered earlier. - */ - while (ss->next) { - GATHER(add_stats.search); - ss = ss->next; - if (ss->string != str) { - GATHER(add_stats.strcmps); - if (strcmp(ss->string, str)) { - /* This wasn't the right string... - */ - continue; - } - } - /* We found an entry for this string. Fix the - * refcount and exit. - */ - GATHER(add_stats.linked); - ++(ss->refcount); - - return ss->string; - } - /* There are no occurences of this string in the hash table. - */ - { - shared_string *new_ss; - - GATHER(add_stats.linked); - new_ss = new_shared_string(str); - ss->next = new_ss; - new_ss->u.previous = ss; - return new_ss->string; - } - } - /* Fall through. - */ - } - GATHER(add_stats.hashed); - ++(ss->refcount); - return ss->string; + /* Simple case first: See if the first pointer matches. + */ + if (str != ss->string) { + GATHER(add_stats.strcmps); + if (strcmp(ss->string, str)) { + /* Apparantly, a string with the same hash value has this + * slot. We must see in the list if "str" has been + * registered earlier. + */ + while (ss->next) { + GATHER(add_stats.search); + ss = ss->next; + if (ss->string != str) { + GATHER(add_stats.strcmps); + if (strcmp(ss->string, str)) { + /* This wasn't the right string... + */ + continue; + } + } + /* We found an entry for this string. Fix the + * refcount and exit. + */ + GATHER(add_stats.linked); + ++(ss->refcount); + + return ss->string; + } + /* There are no occurences of this string in the hash table. + */ + { + shared_string *new_ss; + + GATHER(add_stats.linked); + new_ss = new_shared_string(str); + ss->next = new_ss; + new_ss->u.previous = ss; + return new_ss->string; + } + } + /* Fall through. + */ + } + GATHER(add_stats.hashed); + ++(ss->refcount); + return ss->string; } else { - /* The string isn't registered, and the slot is empty. - */ - GATHER(add_stats.hashed); - hash_table[ind] = new_shared_string(str); - - /* One bit in refcount is used to keep track of the union. - */ - hash_table[ind]->refcount |= TOPBIT; - hash_table[ind]->u.array = &(hash_table[ind]); + /* The string isn't registered, and the slot is empty. + */ + GATHER(add_stats.hashed); + hash_table[ind] = new_shared_string(str); + + /* One bit in refcount is used to keep track of the union. + */ + hash_table[ind]->refcount |= TOPBIT; + hash_table[ind]->u.array = &(hash_table[ind]); - return hash_table[ind]->string; + return hash_table[ind]->string; } } @@ -246,27 +246,27 @@ /* Is there an entry for that hash? */ if (ss) { - /* Simple case first: Is the first string the right one? - */ - GATHER(find_stats.strcmps); - if (!strcmp(ss->string, str)) { - GATHER(find_stats.hashed); - return ss->string; - } else { - /* Recurse through the linked list, if there's one. - */ - while (ss->next) { - GATHER(find_stats.search); - GATHER(find_stats.strcmps); - ss = ss->next; - if (!strcmp(ss->string, str)) { - GATHER(find_stats.linked); - return ss->string; - } - } - /* No match. Fall through. - */ - } + /* Simple case first: Is the first string the right one? + */ + GATHER(find_stats.strcmps); + if (!strcmp(ss->string, str)) { + GATHER(find_stats.hashed); + return ss->string; + } else { + /* Recurse through the linked list, if there's one. + */ + while (ss->next) { + GATHER(find_stats.search); + GATHER(find_stats.strcmps); + ss = ss->next; + if (!strcmp(ss->string, str)) { + GATHER(find_stats.linked); + return ss->string; + } + } + /* No match. Fall through. + */ + } } return NULL; } @@ -288,27 +288,27 @@ ss = SS(str); if ((--ss->refcount & ~TOPBIT) == 0) { - /* Remove this entry. - */ - if (ss->refcount & TOPBIT) { - /* We must put a new value into the hash_table[]. - */ - if (ss->next) { - *(ss->u.array) = ss->next; - ss->next->u.array = ss->u.array; - ss->next->refcount |= TOPBIT; - } else { - *(ss->u.array) = NULL; - } - free(ss); - } else { - /* Relink and free this struct. - */ - if (ss->next) - ss->next->u.previous = ss->u.previous; - ss->u.previous->next = ss->next; - free(ss); - } + /* Remove this entry. + */ + if (ss->refcount & TOPBIT) { + /* We must put a new value into the hash_table[]. + */ + if (ss->next) { + *(ss->u.array) = ss->next; + ss->next->u.array = ss->u.array; + ss->next->refcount |= TOPBIT; + } else { + *(ss->u.array) = NULL; + } + free(ss); + } else { + /* Relink and free this struct. + */ + if (ss->next) + ss->next->u.previous = ss->u.previous; + ss->u.previous->next = ss->next; + free(ss); + } } } @@ -330,23 +330,23 @@ static char line[80]; sprintf(errmsg, "%-13s %6s %6s %6s %6s %6s\n", - "", "calls", "hashed", "strcmp", "search", "linked"); + "", "calls", "hashed", "strcmp", "search", "linked"); sprintf(line, "%-13s %6d %6d %6d %6d %6d\n", - "add_string:", add_stats.calls, add_stats.hashed, - add_stats.strcmps, add_stats.search, add_stats.linked); + "add_string:", add_stats.calls, add_stats.hashed, + add_stats.strcmps, add_stats.search, add_stats.linked); strcat(errmsg, line); sprintf(line, "%-13s %6d\n", - "add_refcount:", add_ref_stats.calls); + "add_refcount:", add_ref_stats.calls); strcat(errmsg, line); sprintf(line, "%-13s %6d\n", - "free_string:", free_stats.calls); + "free_string:", free_stats.calls); strcat(errmsg, line); sprintf(line, "%-13s %6d %6d %6d %6d %6d\n", - "find_string:", find_stats.calls, find_stats.hashed, - find_stats.strcmps, find_stats.search, find_stats.linked); + "find_string:", find_stats.calls, find_stats.hashed, + find_stats.strcmps, find_stats.search, find_stats.linked); strcat(errmsg, line); sprintf(line, "%-13s %6d\n", - "hashstr:", hash_stats.calls); + "hashstr:", hash_stats.calls); strcat(errmsg, line); } #endif /* SS_STATISTICS */ @@ -367,35 +367,35 @@ int i; for (i = 0; i < TABLESIZE; i++) { - shared_string *ss; - - if ((ss = hash_table[i])!=NULL) { - ++entries; - refs += (ss->refcount & ~TOPBIT); + shared_string *ss; + + if ((ss = hash_table[i])!=NULL) { + ++entries; + refs += (ss->refcount & ~TOPBIT); #if 1 /* Can't use stderr any longer, need to include global.h and - if (what & SS_DUMP_TABLE) + if (what & SS_DUMP_TABLE) * use logfile. */ - fprintf(stderr, "%4d -- %4d refs '%s' %c\n", - i, (ss->refcount & ~TOPBIT), ss->string, - (ss->refcount & TOPBIT ? ' ' : '#')); + fprintf(stderr, "%4d -- %4d refs '%s' %c\n", + i, (ss->refcount & ~TOPBIT), ss->string, + (ss->refcount & TOPBIT ? ' ' : '#')); #endif - while (ss->next) { - ss = ss->next; - ++links; - refs += (ss->refcount & ~TOPBIT); + while (ss->next) { + ss = ss->next; + ++links; + refs += (ss->refcount & ~TOPBIT); #if 1 - if (what & SS_DUMP_TABLE) - fprintf(stderr, " -- %4d refs '%s' %c\n", - (ss->refcount & ~TOPBIT), ss->string, - (ss->refcount & TOPBIT ? '*' : ' ')); + if (what & SS_DUMP_TABLE) + fprintf(stderr, " -- %4d refs '%s' %c\n", + (ss->refcount & ~TOPBIT), ss->string, + (ss->refcount & TOPBIT ? '*' : ' ')); #endif - } - } + } + } } if (what & SS_DUMP_TOTALS) { - sprintf(totals, "\n%d entries, %d refs, %d links.", - entries, refs, links); + sprintf(totals, "\n%d entries, %d refs, %d links.", + entries, refs, links); return totals; } return NULL; @@ -411,11 +411,11 @@ int len1 = 0, len2 = 0; if (buf1) - len1 = strlen (buf1); + len1 = strlen (buf1); if (buf2) - len2 = strlen (buf2); + len2 = strlen (buf2); if ((len1 + len2) >= bufsize) - return 1; + return 1; return 0; }