markup substitutions enhancements.
Do not preemptively allocate a g_markup_escape_text for substitutions, just remember what we want to substitute markup with, and substitute it in the final buffer efficiently. Signed-off-by: Pierre Habouzit <madcoder@debian.org>
This commit is contained in:
parent
943e2035fa
commit
37d69b8dcc
4
client.c
4
client.c
|
@ -769,8 +769,7 @@ char *
|
||||||
client_markup_parse(client_t *c, const char *str, ssize_t len)
|
client_markup_parse(client_t *c, const char *str, ssize_t len)
|
||||||
{
|
{
|
||||||
const char *elements[] = { "title", NULL };
|
const char *elements[] = { "title", NULL };
|
||||||
char *title_esc = g_markup_escape_text(c->name, -1);
|
const char *elements_sub[] = { c->name , NULL };
|
||||||
const char *elements_sub[] = { title_esc , NULL };
|
|
||||||
markup_parser_data_t p;
|
markup_parser_data_t p;
|
||||||
char *ret;
|
char *ret;
|
||||||
|
|
||||||
|
@ -784,7 +783,6 @@ client_markup_parse(client_t *c, const char *str, ssize_t len)
|
||||||
ret = a_strdup(str);
|
ret = a_strdup(str);
|
||||||
|
|
||||||
markup_parser_data_wipe(&p);
|
markup_parser_data_wipe(&p);
|
||||||
p_delete(&title_esc);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ markup_parse_start_element(GMarkupParseContext *context __attribute__ ((unused))
|
||||||
|
|
||||||
if(p->elements_sub && p->elements_sub[i])
|
if(p->elements_sub && p->elements_sub[i])
|
||||||
{
|
{
|
||||||
buffer_adds(&p->text, p->elements_sub[i]);
|
buffer_add_xmlescaped(&p->text, p->elements_sub[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -58,22 +58,18 @@ static char *
|
||||||
tag_markup_parse(tag_t *t, const char *str, ssize_t len)
|
tag_markup_parse(tag_t *t, const char *str, ssize_t len)
|
||||||
{
|
{
|
||||||
const char *elements[] = { "title", NULL };
|
const char *elements[] = { "title", NULL };
|
||||||
char *title_esc = g_markup_escape_text(t->name, -1);
|
const char *elements_sub[] = { t->name , NULL };
|
||||||
const char *elements_sub[] = { title_esc , NULL };
|
|
||||||
markup_parser_data_t p;
|
markup_parser_data_t p;
|
||||||
char *ret;
|
char *ret;
|
||||||
|
|
||||||
markup_parser_data_init(&p, elements, elements_sub, countof(elements));
|
markup_parser_data_init(&p, elements, elements_sub, countof(elements));
|
||||||
|
|
||||||
if(markup_parse(&p, str, len))
|
if(markup_parse(&p, str, len))
|
||||||
{
|
|
||||||
ret = buffer_detach(&p.text);
|
ret = buffer_detach(&p.text);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
ret = a_strdup(str);
|
ret = a_strdup(str);
|
||||||
|
|
||||||
markup_parser_data_wipe(&p);
|
markup_parser_data_wipe(&p);
|
||||||
p_delete(&title_esc);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue