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>
|
||||||
|
@ -61,49 +62,52 @@ tsf_register(const char * name, tostring_f fun)
|
||||||
|
|
||||||
/** crmesssage **/
|
/** crmesssage **/
|
||||||
typedef struct crmessage_type {
|
typedef struct crmessage_type {
|
||||||
const struct message_type * mtype;
|
const struct message_type * mtype;
|
||||||
tostring_f * renderers;
|
tostring_f * renderers;
|
||||||
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)
|
||||||
{
|
{
|
||||||
crmessage_type * found = NULL;
|
unsigned int hash = hashstring(mtype->name) % CRMAXHASH;
|
||||||
crmessage_type * type = messagetypes;
|
crmessage_type * found = NULL;
|
||||||
while (type) {
|
crmessage_type * type = messagetypes[hash];
|
||||||
if (type->mtype==mtype) found = type;
|
while (type) {
|
||||||
type = type->next;
|
if (type->mtype==mtype) found = type;
|
||||||
}
|
type = type->next;
|
||||||
return found;
|
}
|
||||||
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
while (crt && crt->mtype!=mtype) {
|
crmessage_type * crt = messagetypes[hash];
|
||||||
crt = crt->next;
|
while (crt && crt->mtype!=mtype) {
|
||||||
}
|
crt = crt->next;
|
||||||
if (!crt) {
|
}
|
||||||
int i;
|
if (!crt) {
|
||||||
crt = malloc(sizeof(crmessage_type));
|
int i;
|
||||||
crt->mtype = mtype;
|
crt = malloc(sizeof(crmessage_type));
|
||||||
crt->next = messagetypes;
|
crt->mtype = mtype;
|
||||||
messagetypes = crt;
|
crt->next = messagetypes[hash];
|
||||||
if(mtype->nparameters > 0) {
|
messagetypes[hash] = crt;
|
||||||
crt->renderers = malloc(sizeof(tostring_f)*mtype->nparameters);
|
if(mtype->nparameters > 0) {
|
||||||
} else {
|
crt->renderers = malloc(sizeof(tostring_f)*mtype->nparameters);
|
||||||
crt->renderers = NULL;
|
} else {
|
||||||
}
|
crt->renderers = NULL;
|
||||||
|
}
|
||||||
/* can be scrapped for memory vs. speed */
|
|
||||||
for (i=0;i!=mtype->nparameters;++i) {
|
/* can be scrapped for memory vs. speed */
|
||||||
crt->renderers[i] = tsf_find(mtype->types[i]);
|
for (i=0;i!=mtype->nparameters;++i) {
|
||||||
}
|
crt->renderers[i] = tsf_find(mtype->types[i]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
Loading…
Reference in New Issue