Remove lots and lots of useless mallocs.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
This commit is contained in:
parent
5c601dfd19
commit
3fb0b5127e
|
@ -279,27 +279,19 @@ draw_text(draw_context_t *ctx, font_t *font,
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
ssize_t len, olen;
|
ssize_t len, olen;
|
||||||
char *buf = NULL, *utf8 = NULL;
|
|
||||||
PangoRectangle ext;
|
PangoRectangle ext;
|
||||||
draw_parser_data_t parser_data;
|
draw_parser_data_t parser_data;
|
||||||
|
|
||||||
if(!(len = a_strlen(text)))
|
if(!(len = a_strlen(text)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
utf8 = a_strdup(text);
|
|
||||||
|
|
||||||
p_clear(&parser_data, 1);
|
p_clear(&parser_data, 1);
|
||||||
parser_data.connection = ctx->connection;
|
parser_data.connection = ctx->connection;
|
||||||
parser_data.phys_screen = ctx->phys_screen;
|
parser_data.phys_screen = ctx->phys_screen;
|
||||||
if(draw_text_markup_expand(&parser_data, utf8, len))
|
if(draw_text_markup_expand(&parser_data, text, len))
|
||||||
{
|
text = parser_data.text;
|
||||||
buf = parser_data.text;
|
|
||||||
p_delete(&utf8);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
buf = utf8;
|
|
||||||
|
|
||||||
len = olen = a_strlen(buf);
|
len = olen = a_strlen(text);
|
||||||
|
|
||||||
if(parser_data.has_bg_color)
|
if(parser_data.has_bg_color)
|
||||||
draw_rectangle(ctx, area, 1.0, true, parser_data.bg_color);
|
draw_rectangle(ctx, area, 1.0, true, parser_data.bg_color);
|
||||||
|
@ -315,7 +307,7 @@ draw_text(draw_context_t *ctx, font_t *font,
|
||||||
- (parser_data.margin.left
|
- (parser_data.margin.left
|
||||||
+ parser_data.margin.right)));
|
+ parser_data.margin.right)));
|
||||||
pango_layout_set_ellipsize(ctx->layout, PANGO_ELLIPSIZE_END);
|
pango_layout_set_ellipsize(ctx->layout, PANGO_ELLIPSIZE_END);
|
||||||
pango_layout_set_markup(ctx->layout, buf, len);
|
pango_layout_set_markup(ctx->layout, text, len);
|
||||||
pango_layout_set_font_description(ctx->layout, font->desc);
|
pango_layout_set_font_description(ctx->layout, font->desc);
|
||||||
pango_layout_get_pixel_extents(ctx->layout, NULL, &ext);
|
pango_layout_get_pixel_extents(ctx->layout, NULL, &ext);
|
||||||
|
|
||||||
|
@ -359,7 +351,7 @@ draw_text(draw_context_t *ctx, font_t *font,
|
||||||
pango_cairo_update_layout(ctx->cr, ctx->layout);
|
pango_cairo_update_layout(ctx->cr, ctx->layout);
|
||||||
pango_cairo_show_layout(ctx->cr, ctx->layout);
|
pango_cairo_show_layout(ctx->cr, ctx->layout);
|
||||||
|
|
||||||
p_delete(&buf);
|
p_delete(&parser_data.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Setup color-source for cairo (gradient or mono).
|
/** Setup color-source for cairo (gradient or mono).
|
||||||
|
@ -985,27 +977,18 @@ draw_text_extents(xcb_connection_t *conn, int phys_screen, font_t *font, const c
|
||||||
xcb_screen_t *s = xutil_screen_get(conn, phys_screen);
|
xcb_screen_t *s = xutil_screen_get(conn, phys_screen);
|
||||||
area_t geom = { 0, 0, 0, 0, NULL, NULL };
|
area_t geom = { 0, 0, 0, 0, NULL, NULL };
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
char *buf, *utf8;
|
|
||||||
draw_parser_data_t parser_data;
|
draw_parser_data_t parser_data;
|
||||||
|
|
||||||
if(!(len = a_strlen(text)))
|
if(!(len = a_strlen(text)))
|
||||||
return geom;
|
return geom;
|
||||||
|
|
||||||
/* try to convert it to UTF-8 */
|
|
||||||
utf8 = a_strdup(text);
|
|
||||||
|
|
||||||
p_clear(&parser_data, 1);
|
p_clear(&parser_data, 1);
|
||||||
parser_data.connection = conn;
|
parser_data.connection = conn;
|
||||||
parser_data.phys_screen = phys_screen;
|
parser_data.phys_screen = phys_screen;
|
||||||
if(draw_text_markup_expand(&parser_data, utf8, len))
|
if(draw_text_markup_expand(&parser_data, text, len))
|
||||||
{
|
text = parser_data.text;
|
||||||
buf = parser_data.text;
|
|
||||||
p_delete(&utf8);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
buf = utf8;
|
|
||||||
|
|
||||||
len = a_strlen(buf);
|
len = a_strlen(text);
|
||||||
|
|
||||||
surface = cairo_xcb_surface_create(conn, phys_screen,
|
surface = cairo_xcb_surface_create(conn, phys_screen,
|
||||||
draw_screen_default_visual(s),
|
draw_screen_default_visual(s),
|
||||||
|
@ -1014,7 +997,7 @@ draw_text_extents(xcb_connection_t *conn, int phys_screen, font_t *font, const c
|
||||||
|
|
||||||
cr = cairo_create(surface);
|
cr = cairo_create(surface);
|
||||||
layout = pango_cairo_create_layout(cr);
|
layout = pango_cairo_create_layout(cr);
|
||||||
pango_layout_set_markup(layout, buf, len);
|
pango_layout_set_markup(layout, text, len);
|
||||||
pango_layout_set_font_description(layout, font->desc);
|
pango_layout_set_font_description(layout, font->desc);
|
||||||
pango_layout_get_pixel_extents(layout, NULL, &ext);
|
pango_layout_get_pixel_extents(layout, NULL, &ext);
|
||||||
g_object_unref(layout);
|
g_object_unref(layout);
|
||||||
|
@ -1024,8 +1007,7 @@ draw_text_extents(xcb_connection_t *conn, int phys_screen, font_t *font, const c
|
||||||
geom.width = ext.width;
|
geom.width = ext.width;
|
||||||
geom.height = ext.height * 1.5;
|
geom.height = ext.height * 1.5;
|
||||||
|
|
||||||
p_delete(&buf);
|
p_delete(&parser_data.text);
|
||||||
|
|
||||||
return geom;
|
return geom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue