forked from github/server
messagetype_list, another special-cased list type, bites the dust and is replaced by the quicklist.
This commit is contained in:
parent
c278a3b71f
commit
fd2b30a0ff
|
@ -283,7 +283,7 @@ void
|
|||
ct_register(const curse_type * ct)
|
||||
{
|
||||
unsigned int hash = tolower(ct->cname[0]);
|
||||
quicklist ** ctlp = &cursetypes[hash];
|
||||
quicklist ** ctlp = cursetypes+hash;
|
||||
|
||||
ql_set_insert(ctlp, (void *)ct);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "goodies.h"
|
||||
#include "log.h"
|
||||
#include "quicklist.h"
|
||||
|
||||
/* libc includes */
|
||||
#include <assert.h>
|
||||
|
@ -153,28 +154,23 @@ msg_create(const struct message_type * mtype, variant args[])
|
|||
return msg;
|
||||
}
|
||||
|
||||
typedef struct messagetype_list {
|
||||
struct messagetype_list * next;
|
||||
const struct message_type * data;
|
||||
} messagetype_list;
|
||||
|
||||
#define MT_MAXHASH 1021
|
||||
static messagetype_list * messagetypes[MT_MAXHASH];
|
||||
static quicklist * messagetypes[MT_MAXHASH];
|
||||
|
||||
const message_type *
|
||||
mt_find(const char * name)
|
||||
{
|
||||
const struct message_type * found = NULL;
|
||||
unsigned int hash = hashstring(name) % MT_MAXHASH;
|
||||
messagetype_list * type = messagetypes[hash];
|
||||
while (type) {
|
||||
if (strcmp(type->data->name, name)==0) {
|
||||
if (found==NULL) found = type->data;
|
||||
break;
|
||||
quicklist * ql = messagetypes[hash];
|
||||
int qi;
|
||||
|
||||
for (qi=0;ql;ql_advance(&ql, &qi, 1)) {
|
||||
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
|
||||
|
@ -194,14 +190,9 @@ const message_type *
|
|||
mt_register(message_type * type)
|
||||
{
|
||||
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 (mtl==NULL) {
|
||||
mtl = (messagetype_list*)malloc(sizeof(messagetype_list));
|
||||
mtl->data = type;
|
||||
mtl->next = messagetypes[hash];
|
||||
messagetypes[hash] = mtl;
|
||||
if (ql_set_insert(qlp, type)==0) {
|
||||
type->key = mt_id(type);
|
||||
}
|
||||
return type;
|
||||
|
|
Loading…
Reference in New Issue