16 #include <sys/types.h>
22 #if defined(__sun__) && defined(StupidSunHeaders)
37 #ifdef HAVE_LIBDMALLOC
49 #if !defined(__STDC__)
62 static unsigned long hashstr(
const char *str) {
63 unsigned long hash = 0;
70 for (p = str; i <
MAXSTRING && *p; p++, i++) {
71 hash ^= (
unsigned long)*p<<rot;
73 if (rot >= (
sizeof(
unsigned long)-
sizeof(
char))*CHAR_BIT)
135 ss = hash_table[ind];
142 GATHER(add_stats.strcmps);
143 if (strcmp(ss->
string, str)) {
152 GATHER(add_stats.strcmps);
153 if (strcmp(ss->
string, str)) {
189 hash_table[ind]->
u.
array = &(hash_table[ind]);
191 return hash_table[ind]->
string;
203 GATHER(add_ref_stats.calls);
204 ++(
SS(str)->refcount);
235 ss = hash_table[ind];
241 GATHER(find_stats.strcmps);
242 if (!strcmp(ss->
string, str)) {
243 GATHER(find_stats.hashed);
248 GATHER(find_stats.search);
249 GATHER(find_stats.strcmps);
251 if (!strcmp(ss->
string, str)) {
252 GATHER(find_stats.linked);
316 static char line[80];
318 snprintf(buf, size,
"%-13s %6s %6s %6s %6s %6s\n",
"",
"calls",
"hashed",
"strcmp",
"search",
"linked");
319 snprintf(line,
sizeof(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);
320 snprintf(buf+strlen(buf), size-strlen(buf),
"%s", line);
321 snprintf(line,
sizeof(line),
"%-13s %6d\n",
"add_refcount:", add_ref_stats.calls);
322 snprintf(buf+strlen(buf), size-strlen(buf),
"%s", line);
323 snprintf(line,
sizeof(line),
"%-13s %6d\n",
"free_string:", free_stats.calls);
324 snprintf(buf+strlen(buf), size-strlen(buf),
"%s", line);
325 snprintf(line,
sizeof(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);
326 snprintf(buf+strlen(buf), size-strlen(buf),
"%s", line);
327 snprintf(line,
sizeof(line),
"%-13s %6d\n",
"hashstr:", hash_stats.calls);
328 snprintf(buf+strlen(buf), size-strlen(buf),
"%s", line);
347 int entries = 0, refs = 0, links = 0;
353 if ((ss = hash_table[i]) != NULL) {
373 snprintf(buf, size,
"\n%d entries, %d refs, %d links.", entries, refs, links);
394 size_t len1 = 0, len2 = 0;
400 if ((len1+len2) >= bufsize)
union _shared_string::@3 u
sstring add_refcount(sstring str)
int query_refcount(sstring str)
void free_string(sstring str)
struct _shared_string * previous
struct _shared_string * next
sstring find_string(const char *str)
void init_hash_table(void)
int buf_overflow(const char *buf1, const char *buf2, size_t bufsize)
struct _shared_string ** array
unsigned REFCOUNT_TYPE refcount
char * ss_dump_table(int what, char *buf, size_t size)
static shared_string * hash_table[TABLESIZE]
int snprintf(char *dest, int max, const char *format,...)
static unsigned long hashstr(const char *str)
void ss_dump_statistics(char *buf, size_t size)
static shared_string * new_shared_string(const char *str)
sstring add_string(const char *str)
void LOG(LogLevel logLevel, const char *format,...)