messagetype_list, another special-cased list type, bites the dust and is replaced by the quicklist.

This commit is contained in:
Enno Rehling 2011-02-25 08:04:25 -08:00
parent c278a3b71f
commit fd2b30a0ff
2 changed files with 25 additions and 34 deletions

View file

@ -283,7 +283,7 @@ void
ct_register(const curse_type * ct) ct_register(const curse_type * ct)
{ {
unsigned int hash = tolower(ct->cname[0]); unsigned int hash = tolower(ct->cname[0]);
quicklist ** ctlp = &cursetypes[hash]; quicklist ** ctlp = cursetypes+hash;
ql_set_insert(ctlp, (void *)ct); ql_set_insert(ctlp, (void *)ct);
} }

View file

@ -16,6 +16,7 @@
#include "goodies.h" #include "goodies.h"
#include "log.h" #include "log.h"
#include "quicklist.h"
/* libc includes */ /* libc includes */
#include <assert.h> #include <assert.h>
@ -153,28 +154,23 @@ msg_create(const struct message_type * mtype, variant args[])
return msg; return msg;
} }
typedef struct messagetype_list {
struct messagetype_list * next;
const struct message_type * data;
} messagetype_list;
#define MT_MAXHASH 1021 #define MT_MAXHASH 1021
static messagetype_list * messagetypes[MT_MAXHASH]; static quicklist * messagetypes[MT_MAXHASH];
const message_type * const message_type *
mt_find(const char * name) mt_find(const char * name)
{ {
const struct message_type * found = NULL;
unsigned int hash = hashstring(name) % MT_MAXHASH; unsigned int hash = hashstring(name) % MT_MAXHASH;
messagetype_list * type = messagetypes[hash]; quicklist * ql = messagetypes[hash];
while (type) { int qi;
if (strcmp(type->data->name, name)==0) {
if (found==NULL) found = type->data; for (qi=0;ql;ql_advance(&ql, &qi, 1)) {
break; message_type * data = (message_type *)ql_get(ql, qi);
if (strcmp(data->name, name)==0) {
return data;
} }
type = type->next;
} }
return found; return 0;
} }
static unsigned int static unsigned int
@ -194,14 +190,9 @@ const message_type *
mt_register(message_type * type) mt_register(message_type * type)
{ {
unsigned int hash = hashstring(type->name) % MT_MAXHASH; unsigned int hash = hashstring(type->name) % MT_MAXHASH;
messagetype_list * mtl = messagetypes[hash]; quicklist ** qlp = messagetypes+hash;
while (mtl && mtl->data!=type) mtl=mtl->next; if (ql_set_insert(qlp, type)==0) {
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); type->key = mt_id(type);
} }
return type; return type;