reduce the footprint of nrmessage

This commit is contained in:
Enno Rehling 2018-05-18 02:46:34 +02:00
parent 3867388834
commit ef74b8e759
4 changed files with 20 additions and 28 deletions

View File

@ -512,17 +512,14 @@ static void report_crtypes(FILE * F, const struct locale *lang)
for (i = 0; i != MTMAXHASH; ++i) {
struct known_mtype *kmt;
for (kmt = mtypehash[i]; kmt; kmt = kmt->nexthash) {
const struct nrmessage_type *nrt = nrt_find(kmt->mtype);
if (nrt) {
char buffer[DISPLAYSIZE];
int hash = (int)kmt->mtype->key;
assert(hash > 0);
fprintf(F, "MESSAGETYPE %d\n", hash);
fputc('\"', F);
fputs(str_escape(nrt_string(nrt, lang), buffer, sizeof(buffer)), F);
fputs("\";text\n", F);
fprintf(F, "\"%s\";section\n", nrt_section(nrt));
}
char buffer[DISPLAYSIZE];
int hash = (int)kmt->mtype->key;
assert(hash > 0);
fprintf(F, "MESSAGETYPE %d\n", hash);
fputc('\"', F);
fputs(str_escape(nrt_string(kmt->mtype, lang), buffer, sizeof(buffer)), F);
fputs("\";text\n", F);
fprintf(F, "\"%s\";section\n", nrt_section(kmt->mtype));
}
while (mtypehash[i]) {
kmt = mtypehash[i];

View File

@ -723,7 +723,7 @@ rp_messages(struct stream *out, message_list * msgs, faction * viewer, int inden
struct mlist *m = msgs->begin;
while (m) {
/* messagetype * mt = m->type; */
if (!categorized || strcmp(nr_section(m->msg), section->name) == 0) {
if (!categorized || strcmp(nrt_section(m->msg->type), section->name) == 0) {
char lbuf[8192];
if (!k && categorized) {

View File

@ -30,17 +30,18 @@
#define NRT_MAXHASH 1021
static nrmessage_type *nrtypes[NRT_MAXHASH];
const char *nrt_string(const struct nrmessage_type *nrt, const struct locale *lang)
const char *nrt_string(const struct message_type *mtype,
const struct locale *lang)
{
const char * str = locale_getstring(lang, nrt->mtype->name);
const char * str = locale_getstring(lang, mtype->name);
if (!str) {
str = locale_getstring(default_locale, nrt->mtype->name);
str = locale_getstring(default_locale, mtype->name);
}
assert(str);
return str;
}
nrmessage_type *nrt_find(const struct message_type * mtype)
static nrmessage_type *nrt_find(const struct message_type * mtype)
{
nrmessage_type *found = NULL;
unsigned int hash = mtype->key % NRT_MAXHASH;
@ -139,7 +140,7 @@ size_t size, const void *userdata)
if (nrt) {
const char *m =
translate(nrt_string(nrt, lang), userdata, nrt->vars, msg->parameters);
translate(nrt_string(msg->type, lang), userdata, nrt->vars, msg->parameters);
if (m) {
return str_strlcpy((char *)buffer, m, size);
}
@ -152,14 +153,9 @@ size_t size, const void *userdata)
return 0;
}
const char *nr_section(const struct message *msg)
{
nrmessage_type *nrt = nrt_find(msg->type);
return nrt ? nrt->section : NULL;
}
const char *nrt_section(const nrmessage_type * nrt)
const char *nrt_section(const struct message_type * mtype)
{
nrmessage_type *nrt = nrt_find(mtype);
return nrt ? nrt->section : NULL;
}

View File

@ -35,13 +35,12 @@ extern "C" {
void free_nrmesssages(void);
void nrt_register(const struct message_type *mtype, const char *section);
struct nrmessage_type *nrt_find(const struct message_type *);
const char *nrt_string(const struct nrmessage_type *nrt, const struct locale *lang);
const char *nrt_section(const struct nrmessage_type *nrt);
const char *nrt_string(const struct message_type *mtype,
const struct locale *lang);
const char *nrt_section(const struct message_type *mtype);
size_t nr_render(const struct message *msg, const struct locale *lang,
char *buffer, size_t size, const void *userdata);
const char *nr_section(const struct message *msg);
#ifdef __cplusplus
}