 |
Crossfire Server, Trunk
1.75.0
|
Go to the documentation of this file.
24 #include <sys/types.h>
30 #if defined(__sun__) && defined(StupidSunHeaders)
45 #ifdef HAVE_LIBDMALLOC
57 #if !defined(__STDC__)
70 static unsigned long hashstr(
const char *str) {
71 unsigned long hash = 0;
78 for (p = str; i <
MAXSTRING && *p; p++, i++) {
79 hash ^= (
unsigned long)*p<<rot;
81 if (rot >= (
sizeof(
unsigned long)-
sizeof(
char))*CHAR_BIT)
150 GATHER(add_stats.strcmps);
151 if (strcmp(ss->
string, str)) {
160 GATHER(add_stats.strcmps);
161 if (strcmp(ss->
string, str)) {
211 GATHER(add_ref_stats.calls);
212 ++(
SS(str)->refcount);
249 GATHER(find_stats.strcmps);
250 if (!strcmp(ss->
string, str)) {
251 GATHER(find_stats.hashed);
256 GATHER(find_stats.search);
257 GATHER(find_stats.strcmps);
259 if (!strcmp(ss->
string, str)) {
260 GATHER(find_stats.linked);
324 static char line[80];
326 snprintf(
buf, size,
"%-13s %6s %6s %6s %6s %6s\n",
"",
"calls",
"hashed",
"strcmp",
"search",
"linked");
327 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);
329 snprintf(
line,
sizeof(
line),
"%-13s %6d\n",
"add_refcount:", add_ref_stats.calls);
331 snprintf(
line,
sizeof(
line),
"%-13s %6d\n",
"free_string:", free_stats.calls);
333 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);
335 snprintf(
line,
sizeof(
line),
"%-13s %6d\n",
"hashstr:", hash_stats.calls);
355 int entries = 0, refs = 0, links = 0;
381 snprintf(
buf, size,
"\n%d entries, %d refs, %d links.", entries, refs, links);
399 size_t len1 = 0, len2 = 0;
407 if (len1 >= (bufsize-len2))
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
#define TABLESIZE
The size of the shared strings hashtable.
void ss_dump_statistics(char *buf, size_t size)
A call to this function will cause the statistics to be dumped into specified buffer.
static unsigned long hashstr(const char *str)
Hashing-function used by the shared string library.
unsigned REFCOUNT_TYPE refcount
sstring add_refcount(sstring str)
This will increase the refcount of the string str.
sstring add_string(const char *str)
This will add 'str' to the hash table.
sstring find_string(const char *str)
Searches a string in the shared strings.
#define SS(x)
SS(string) will return the address of the shared_string struct which contains "string".
char * ss_dump_table(int what, char *buf, size_t size)
Dump the contents of the share string tables.
int query_refcount(sstring str)
This will return the refcount of the string str.
static shared_string * hash_table[TABLESIZE]
Hash table to store our string.
void fatal(enum fatal_error err)
fatal() is meant to be called whenever a fatal signal is intercepted.
void free_string(sstring str)
This will reduce the refcount, and if it has reached 0, str will be freed.
void init_hash_table(void)
Initialises the hash-table used by the shared string library.
const typedef char * sstring
union shared_string::@7 u
One actual shared string.
int buf_overflow(const char *buf1, const char *buf2, size_t bufsize)
We don't want to exceed the buffer size of buf1 by adding on buf2!
static shared_string * new_shared_string(const char *str)
Allocates and initialises a new shared_string structure, containing the string str.
@ llevDebug
Only for debugging purposes.