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 "crmessage.h"
|
||||||
|
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
#include "goodies.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -66,13 +67,15 @@ typedef struct crmessage_type {
|
||||||
struct crmessage_type * next;
|
struct crmessage_type * next;
|
||||||
} crmessage_type;
|
} crmessage_type;
|
||||||
|
|
||||||
static crmessage_type * messagetypes;
|
#define CRMAXHASH 63
|
||||||
|
static crmessage_type * messagetypes[CRMAXHASH];
|
||||||
|
|
||||||
static crmessage_type *
|
static crmessage_type *
|
||||||
crt_find(const struct message_type * mtype)
|
crt_find(const struct message_type * mtype)
|
||||||
{
|
{
|
||||||
|
unsigned int hash = hashstring(mtype->name) % CRMAXHASH;
|
||||||
crmessage_type * found = NULL;
|
crmessage_type * found = NULL;
|
||||||
crmessage_type * type = messagetypes;
|
crmessage_type * type = messagetypes[hash];
|
||||||
while (type) {
|
while (type) {
|
||||||
if (type->mtype==mtype) found = type;
|
if (type->mtype==mtype) found = type;
|
||||||
type = type->next;
|
type = type->next;
|
||||||
|
@ -83,7 +86,8 @@ crt_find(const struct message_type * mtype)
|
||||||
void
|
void
|
||||||
crt_register(const struct message_type * mtype)
|
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) {
|
while (crt && crt->mtype!=mtype) {
|
||||||
crt = crt->next;
|
crt = crt->next;
|
||||||
}
|
}
|
||||||
|
@ -91,8 +95,8 @@ crt_register(const struct message_type * mtype)
|
||||||
int i;
|
int i;
|
||||||
crt = malloc(sizeof(crmessage_type));
|
crt = malloc(sizeof(crmessage_type));
|
||||||
crt->mtype = mtype;
|
crt->mtype = mtype;
|
||||||
crt->next = messagetypes;
|
crt->next = messagetypes[hash];
|
||||||
messagetypes = crt;
|
messagetypes[hash] = crt;
|
||||||
if(mtype->nparameters > 0) {
|
if(mtype->nparameters > 0) {
|
||||||
crt->renderers = malloc(sizeof(tostring_f)*mtype->nparameters);
|
crt->renderers = malloc(sizeof(tostring_f)*mtype->nparameters);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue