From 3cd617fe394ee9e53805b948909e46e9a65232e2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 4 Feb 2006 18:53:34 +0000 Subject: [PATCH] new hash function is faster than the old --- src/common/kernel/item.h | 1 - src/common/util/command.c | 2 + src/common/util/goodies.c | 12 +++--- src/common/util/language.c | 88 +++++++++++++++++++------------------- src/res/de/strings.xml | 12 +++--- 5 files changed, 57 insertions(+), 58 deletions(-) diff --git a/src/common/kernel/item.h b/src/common/kernel/item.h index 76e57fda6..7a9334d39 100644 --- a/src/common/kernel/item.h +++ b/src/common/kernel/item.h @@ -321,7 +321,6 @@ enum { R_AURAKULUM, R_SEASERPENTHEAD, R_SPHERE_OF_INVISIBILITY, - R_TOADSLIME, R_BAG_OF_HOLDING, R_SACK_OF_CONSERVATION, R_TACTICCRYSTAL, diff --git a/src/common/util/command.c b/src/common/util/command.c index 899f3325d..556ebe7bf 100644 --- a/src/common/util/command.c +++ b/src/common/util/command.c @@ -93,6 +93,8 @@ do_command_i(const struct tnode * keys, void * u, const char * str, struct order return E_TOK_NOMATCH; } +struct unit; +struct order; extern char * getcommand(struct order * ord); extern char * unitname(struct unit * u); diff --git a/src/common/util/goodies.c b/src/common/util/goodies.c index 540a81643..e28e3b2e5 100644 --- a/src/common/util/goodies.c +++ b/src/common/util/goodies.c @@ -60,13 +60,11 @@ intlist_find(int *i_p, int fi) unsigned int hashstring(const char* s) { - unsigned int key = 0; - size_t i = strlen(s); - - while (i>0) { - key = (s[--i] + key*37); - } - return key % 0x7FFFFFFF; + unsigned int key = 0; + while (*s) { + key = key*37 + *s++; + } + return key % 0x7FFFFFFF; } const char * diff --git a/src/common/util/language.c b/src/common/util/language.c index e2e088aea..a5c1f0875 100644 --- a/src/common/util/language.c +++ b/src/common/util/language.c @@ -91,62 +91,62 @@ locale_getstring(const locale * lang, const char * key) const char * locale_string(const locale * lang, const char * key) { - if (key==NULL) return NULL; - else { - unsigned int hkey = hashstring(key); - unsigned int id = hkey % SMAXHASH; - struct locale_str * find; + if (key==NULL) return NULL; + else { + unsigned int hkey = hashstring(key); + unsigned int id = hkey % SMAXHASH; + struct locale_str * find; - if (key == NULL || *key==0) return NULL; - if (lang == NULL) return key; - find = lang->strings[id]; - while (find) { - if (find->hashkey == hkey && !strcmp(key, find->key)) break; - find = find->nexthash; - } - if (!find) { - const char * s = key; - log_warning(("missing translation for \"%s\" in locale %s\n", key, lang->name)); - if (lang!=default_locale) { - s = locale_string(default_locale, key); - } - if (s_logfile) { + if (key == NULL || *key==0) return NULL; + if (lang == NULL) return key; + find = lang->strings[id]; + while (find) { + if (find->hashkey == hkey && !strcmp(key, find->key)) break; + find = find->nexthash; + } + if (!find) { + const char * s = key; + log_warning(("missing translation for \"%s\" in locale %s\n", key, lang->name)); + if (lang!=default_locale) { + s = locale_string(default_locale, key); + } + if (s_logfile) { s_debug = s_debug?s_debug:fopen(s_logfile, "w+"); if (s_debug) { fprintf(s_debug, "%s;%s;%s\n", key, lang->name, s); fflush(s_debug); locale_setstring((struct locale*)lang, key, s); } - } - return s; - } - return find->str; - } + } + return s; + } + return find->str; + } } void locale_setstring(locale * lang, const char * key, const char * value) { - int nval = atoi(key); - unsigned int hkey = nval?nval:hashstring(key); - unsigned int id = hkey % SMAXHASH; - struct locale_str * find; - - if (lang==NULL) lang=default_locale; - find = lang->strings[id]; - while (find) { - if (find->hashkey==hkey && !strcmp(key, find->key)) break; - find=find->nexthash; - } - if (!find) { - find = calloc(1, sizeof(struct locale_str)); - find->nexthash = lang->strings[id]; - lang->strings[id] = find; - find->hashkey = hkey; - find->key = strdup(key); - find->str = strdup(value); - } - else { + int nval = atoi(key); + unsigned int hkey = nval?nval:hashstring(key); + unsigned int id = hkey % SMAXHASH; + struct locale_str * find; + + if (lang==NULL) lang=default_locale; + find = lang->strings[id]; + while (find) { + if (find->hashkey==hkey && !strcmp(key, find->key)) break; + find=find->nexthash; + } + if (!find) { + find = calloc(1, sizeof(struct locale_str)); + find->nexthash = lang->strings[id]; + lang->strings[id] = find; + find->hashkey = hkey; + find->key = strdup(key); + find->str = strdup(value); + } + else { if (strcmp(find->str, value)!=0) { log_error(("Duplicate key %s for '%s' and '%s'\n", key, value, find->str)); } diff --git a/src/res/de/strings.xml b/src/res/de/strings.xml index 5911cc52d..733024924 100644 --- a/src/res/de/strings.xml +++ b/src/res/de/strings.xml @@ -321,28 +321,28 @@ wenige - few + few viele - many + many relativ viele - rather many + rather many sehr wenige - very few + very few sehr viele - a great many - beaucoup de + a great many + beaucoup de