From 3248053efe38940207cc7332cc3a0023968e863b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 7 Feb 2006 21:31:55 +0000 Subject: [PATCH] =?UTF-8?q?Messages=20benutzen=20alte=20Hashfunktion=20f?= =?UTF-8?q?=C3=BCr=20Typ-Key.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/gamecode/creport.c | 4 ++-- src/common/util/message.c | 16 +++++++++++++++- src/common/util/message.h | 3 ++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index 739832454..e1c5ceacd 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -454,7 +454,7 @@ report_crtypes(FILE * F, const struct locale* lang) for (kmt=mtypehash[i];kmt;kmt=kmt->nexthash) { const struct nrmessage_type * nrt = nrt_find(lang, kmt->mtype); if (nrt) { - unsigned int hash = hashstring(mt_name(kmt->mtype)); + unsigned int hash = kmt->mtype->key; fprintf(F, "MESSAGETYPE %d\n", hash); fputc('\"', F); fputs(escape_string(nrt_string(nrt), NULL, 0), F); @@ -478,7 +478,7 @@ render_messages(FILE * F, faction * f, message_list *msgs) char crbuffer[1024*32]; /* gross, wegen spionage-messages :-( */ boolean printed = false; const struct message_type * mtype = m->msg->type; - unsigned int hash = hashstring(mtype->name); + unsigned int hash = mtype->key; #ifdef RENDER_CRMESSAGES char nrbuffer[1024*32]; nrbuffer[0] = '\0'; diff --git a/src/common/util/message.c b/src/common/util/message.c index ab3734ed5..0f5400304 100644 --- a/src/common/util/message.c +++ b/src/common/util/message.c @@ -174,18 +174,32 @@ mt_find(const char * name) return found; } +static unsigned int +mt_id(const message_type * mtype) +{ + unsigned int key = 0; + size_t i = strlen(mtype->name); + + while (i>0) { + key = (mtype->name[--i] + key*37); + } + return key % 0x7FFFFFFF; +} + const message_type * -mt_register(const message_type * type) +mt_register(message_type * type) { unsigned int hash = hashstring(type->name) % MT_MAXHASH; messagetype_list * mtl = messagetypes[hash]; + while (mtl && mtl->data!=type) mtl=mtl->next; if (mtl==NULL) { mtl = (messagetype_list*)malloc(sizeof(messagetype_list)); mtl->data = type; mtl->next = messagetypes[hash]; messagetypes[hash] = mtl; + type->key = mt_id(type); } return type; } diff --git a/src/common/util/message.h b/src/common/util/message.h index c765a55a3..6c582c0cc 100644 --- a/src/common/util/message.h +++ b/src/common/util/message.h @@ -29,6 +29,7 @@ typedef struct arg_type { } arg_type; typedef struct message_type { + unsigned int key; const char * name; int nparameters; const char ** pnames; @@ -56,7 +57,7 @@ extern struct message * msg_addref(struct message * msg); extern const char * mt_name(const struct message_type* mtype); /** message_type registry (optional): **/ -extern const struct message_type * mt_register(const struct message_type *); +extern const struct message_type * mt_register(struct message_type *); extern const struct message_type * mt_find(const char *); extern void register_argtype(const char * name, void(*free_arg)(variant), variant (*copy_arg)(variant), variant_type);