forked from github/server
speeding up crt_find lookups because they are visible in the profile.
This commit is contained in:
parent
1d0590d4c7
commit
9b0daeced4
|
@ -15,6 +15,7 @@
|
|||
#include "crmessage.h"
|
||||
|
||||
#include "message.h"
|
||||
#include "goodies.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -66,13 +67,15 @@ typedef struct crmessage_type {
|
|||
struct crmessage_type * next;
|
||||
} crmessage_type;
|
||||
|
||||
static crmessage_type * messagetypes;
|
||||
#define CRMAXHASH 63
|
||||
static crmessage_type * messagetypes[CRMAXHASH];
|
||||
|
||||
static crmessage_type *
|
||||
crt_find(const struct message_type * mtype)
|
||||
{
|
||||
unsigned int hash = hashstring(mtype->name) % CRMAXHASH;
|
||||
crmessage_type * found = NULL;
|
||||
crmessage_type * type = messagetypes;
|
||||
crmessage_type * type = messagetypes[hash];
|
||||
while (type) {
|
||||
if (type->mtype==mtype) found = type;
|
||||
type = type->next;
|
||||
|
@ -83,7 +86,8 @@ crt_find(const struct message_type * mtype)
|
|||
void
|
||||
crt_register(const struct message_type * mtype)
|
||||
{
|
||||
crmessage_type * crt = messagetypes;
|
||||
unsigned int hash = hashstring(mtype->name) % CRMAXHASH;
|
||||
crmessage_type * crt = messagetypes[hash];
|
||||
while (crt && crt->mtype!=mtype) {
|
||||
crt = crt->next;
|
||||
}
|
||||
|
@ -91,8 +95,8 @@ crt_register(const struct message_type * mtype)
|
|||
int i;
|
||||
crt = malloc(sizeof(crmessage_type));
|
||||
crt->mtype = mtype;
|
||||
crt->next = messagetypes;
|
||||
messagetypes = crt;
|
||||
crt->next = messagetypes[hash];
|
||||
messagetypes[hash] = crt;
|
||||
if(mtype->nparameters > 0) {
|
||||
crt->renderers = malloc(sizeof(tostring_f)*mtype->nparameters);
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue