forked from github/server
new hash function is faster than the old
This commit is contained in:
parent
939773826b
commit
3cd617fe39
|
@ -321,7 +321,6 @@ enum {
|
||||||
R_AURAKULUM,
|
R_AURAKULUM,
|
||||||
R_SEASERPENTHEAD,
|
R_SEASERPENTHEAD,
|
||||||
R_SPHERE_OF_INVISIBILITY,
|
R_SPHERE_OF_INVISIBILITY,
|
||||||
R_TOADSLIME,
|
|
||||||
R_BAG_OF_HOLDING,
|
R_BAG_OF_HOLDING,
|
||||||
R_SACK_OF_CONSERVATION,
|
R_SACK_OF_CONSERVATION,
|
||||||
R_TACTICCRYSTAL,
|
R_TACTICCRYSTAL,
|
||||||
|
|
|
@ -93,6 +93,8 @@ do_command_i(const struct tnode * keys, void * u, const char * str, struct order
|
||||||
return E_TOK_NOMATCH;
|
return E_TOK_NOMATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct unit;
|
||||||
|
struct order;
|
||||||
extern char * getcommand(struct order * ord);
|
extern char * getcommand(struct order * ord);
|
||||||
extern char * unitname(struct unit * u);
|
extern char * unitname(struct unit * u);
|
||||||
|
|
||||||
|
|
|
@ -60,13 +60,11 @@ intlist_find(int *i_p, int fi)
|
||||||
unsigned int
|
unsigned int
|
||||||
hashstring(const char* s)
|
hashstring(const char* s)
|
||||||
{
|
{
|
||||||
unsigned int key = 0;
|
unsigned int key = 0;
|
||||||
size_t i = strlen(s);
|
while (*s) {
|
||||||
|
key = key*37 + *s++;
|
||||||
while (i>0) {
|
}
|
||||||
key = (s[--i] + key*37);
|
return key % 0x7FFFFFFF;
|
||||||
}
|
|
||||||
return key % 0x7FFFFFFF;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
|
|
@ -91,62 +91,62 @@ locale_getstring(const locale * lang, const char * key)
|
||||||
const char *
|
const char *
|
||||||
locale_string(const locale * lang, const char * key)
|
locale_string(const locale * lang, const char * key)
|
||||||
{
|
{
|
||||||
if (key==NULL) return NULL;
|
if (key==NULL) return NULL;
|
||||||
else {
|
else {
|
||||||
unsigned int hkey = hashstring(key);
|
unsigned int hkey = hashstring(key);
|
||||||
unsigned int id = hkey % SMAXHASH;
|
unsigned int id = hkey % SMAXHASH;
|
||||||
struct locale_str * find;
|
struct locale_str * find;
|
||||||
|
|
||||||
if (key == NULL || *key==0) return NULL;
|
if (key == NULL || *key==0) return NULL;
|
||||||
if (lang == NULL) return key;
|
if (lang == NULL) return key;
|
||||||
find = lang->strings[id];
|
find = lang->strings[id];
|
||||||
while (find) {
|
while (find) {
|
||||||
if (find->hashkey == hkey && !strcmp(key, find->key)) break;
|
if (find->hashkey == hkey && !strcmp(key, find->key)) break;
|
||||||
find = find->nexthash;
|
find = find->nexthash;
|
||||||
}
|
}
|
||||||
if (!find) {
|
if (!find) {
|
||||||
const char * s = key;
|
const char * s = key;
|
||||||
log_warning(("missing translation for \"%s\" in locale %s\n", key, lang->name));
|
log_warning(("missing translation for \"%s\" in locale %s\n", key, lang->name));
|
||||||
if (lang!=default_locale) {
|
if (lang!=default_locale) {
|
||||||
s = locale_string(default_locale, key);
|
s = locale_string(default_locale, key);
|
||||||
}
|
}
|
||||||
if (s_logfile) {
|
if (s_logfile) {
|
||||||
s_debug = s_debug?s_debug:fopen(s_logfile, "w+");
|
s_debug = s_debug?s_debug:fopen(s_logfile, "w+");
|
||||||
if (s_debug) {
|
if (s_debug) {
|
||||||
fprintf(s_debug, "%s;%s;%s\n", key, lang->name, s);
|
fprintf(s_debug, "%s;%s;%s\n", key, lang->name, s);
|
||||||
fflush(s_debug);
|
fflush(s_debug);
|
||||||
locale_setstring((struct locale*)lang, key, s);
|
locale_setstring((struct locale*)lang, key, s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
return find->str;
|
return find->str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
locale_setstring(locale * lang, const char * key, const char * value)
|
locale_setstring(locale * lang, const char * key, const char * value)
|
||||||
{
|
{
|
||||||
int nval = atoi(key);
|
int nval = atoi(key);
|
||||||
unsigned int hkey = nval?nval:hashstring(key);
|
unsigned int hkey = nval?nval:hashstring(key);
|
||||||
unsigned int id = hkey % SMAXHASH;
|
unsigned int id = hkey % SMAXHASH;
|
||||||
struct locale_str * find;
|
struct locale_str * find;
|
||||||
|
|
||||||
if (lang==NULL) lang=default_locale;
|
if (lang==NULL) lang=default_locale;
|
||||||
find = lang->strings[id];
|
find = lang->strings[id];
|
||||||
while (find) {
|
while (find) {
|
||||||
if (find->hashkey==hkey && !strcmp(key, find->key)) break;
|
if (find->hashkey==hkey && !strcmp(key, find->key)) break;
|
||||||
find=find->nexthash;
|
find=find->nexthash;
|
||||||
}
|
}
|
||||||
if (!find) {
|
if (!find) {
|
||||||
find = calloc(1, sizeof(struct locale_str));
|
find = calloc(1, sizeof(struct locale_str));
|
||||||
find->nexthash = lang->strings[id];
|
find->nexthash = lang->strings[id];
|
||||||
lang->strings[id] = find;
|
lang->strings[id] = find;
|
||||||
find->hashkey = hkey;
|
find->hashkey = hkey;
|
||||||
find->key = strdup(key);
|
find->key = strdup(key);
|
||||||
find->str = strdup(value);
|
find->str = strdup(value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (strcmp(find->str, value)!=0) {
|
if (strcmp(find->str, value)!=0) {
|
||||||
log_error(("Duplicate key %s for '%s' and '%s'\n", key, value, find->str));
|
log_error(("Duplicate key %s for '%s' and '%s'\n", key, value, find->str));
|
||||||
}
|
}
|
||||||
|
|
|
@ -321,28 +321,28 @@
|
||||||
|
|
||||||
<string name="wenige">
|
<string name="wenige">
|
||||||
<text locale="de">wenige</text>
|
<text locale="de">wenige</text>
|
||||||
<text locale="en">few </text>
|
<text locale="en">few</text>
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
<string name="viele">
|
<string name="viele">
|
||||||
<text locale="de">viele</text>
|
<text locale="de">viele</text>
|
||||||
<text locale="en">many </text>
|
<text locale="en">many</text>
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
<string name="relativ viele">
|
<string name="relativ viele">
|
||||||
<text locale="de">relativ viele</text>
|
<text locale="de">relativ viele</text>
|
||||||
<text locale="en">rather many </text>
|
<text locale="en">rather many</text>
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
<string name="sehr wenige">
|
<string name="sehr wenige">
|
||||||
<text locale="de">sehr wenige</text>
|
<text locale="de">sehr wenige</text>
|
||||||
<text locale="en">very few </text>
|
<text locale="en">very few</text>
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
<string name="sehr viele">
|
<string name="sehr viele">
|
||||||
<text locale="de">sehr viele</text>
|
<text locale="de">sehr viele</text>
|
||||||
<text locale="en">a great many </text>
|
<text locale="en">a great many</text>
|
||||||
<text locale="fr">beaucoup de </text>
|
<text locale="fr">beaucoup de</text>
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
<string name="nr_spell_description">
|
<string name="nr_spell_description">
|
||||||
|
|
Loading…
Reference in New Issue