new hash function is faster than the old

This commit is contained in:
Enno Rehling 2006-02-04 18:53:34 +00:00
parent 939773826b
commit 3cd617fe39
5 changed files with 57 additions and 58 deletions

View File

@ -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,

View File

@ -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);

View File

@ -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 *

View File

@ -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));
}

View File

@ -321,28 +321,28 @@
<string name="wenige">
<text locale="de">wenige</text>
<text locale="en">few </text>
<text locale="en">few</text>
</string>
<string name="viele">
<text locale="de">viele</text>
<text locale="en">many </text>
<text locale="en">many</text>
</string>
<string name="relativ viele">
<text locale="de">relativ viele</text>
<text locale="en">rather many </text>
<text locale="en">rather many</text>
</string>
<string name="sehr wenige">
<text locale="de">sehr wenige</text>
<text locale="en">very few </text>
<text locale="en">very few</text>
</string>
<string name="sehr viele">
<text locale="de">sehr viele</text>
<text locale="en">a great many </text>
<text locale="fr">beaucoup de </text>
<text locale="en">a great many</text>
<text locale="fr">beaucoup de</text>
</string>
<string name="nr_spell_description">