diff options
author | Jesse Luehrs <doy@tozt.net> | 2017-02-12 16:36:12 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2017-02-12 16:36:12 -0500 |
commit | 99ec8a898b7571c07fb322e2365b186df1681687 (patch) | |
tree | c54ef209ea2c1f5aa33fcb9ea7bfcac6a475aada /src/display.c | |
parent | 23590b5069a2ad466c3c85997c35bf9b07bc6339 (diff) | |
download | runes-99ec8a898b7571c07fb322e2365b186df1681687.tar.gz runes-99ec8a898b7571c07fb322e2365b186df1681687.zip |
avoid an allocation on every glyph string draw
probably not super meaningful compared to the cost of the cairo
operations, but may as well
Diffstat (limited to 'src/display.c')
-rw-r--r-- | src/display.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/display.c b/src/display.c index 9c7ce87..59b7b14 100644 --- a/src/display.c +++ b/src/display.c @@ -44,6 +44,16 @@ RunesDisplay *runes_display_new(char *font_name) return display; } +void runes_display_set_window_size(RunesTerm *t, int row, int col) +{ + RunesDisplay *display = t->display; + + UNUSED(row); + + free(display->glyph_buf); + display->glyph_buf = malloc(col * sizeof(cairo_glyph_t)); +} + void runes_display_set_context(RunesTerm *t, cairo_t *cr) { RunesDisplay *display = t->display; @@ -244,6 +254,7 @@ void runes_display_maybe_clear_selection(RunesTerm *t) void runes_display_delete(RunesDisplay *display) { free(display->ascii_glyph_index_cache); + free(display->glyph_buf); cairo_scaled_font_destroy(display->scaled_font); cairo_pattern_destroy(display->buffer); g_object_unref(display->layout); @@ -492,37 +503,33 @@ static void runes_display_draw_glyphs_fast( size_t len, int row, int col) { RunesDisplay *display = t->display; - cairo_glyph_t *glyphs; size_t i; - glyphs = malloc(len * sizeof(cairo_glyph_t)); - for (i = 0; i < len; ++i) { + cairo_glyph_t *glyph = &display->glyph_buf[i]; switch (cells[i]->len) { case 0: - glyphs[i].index = display->ascii_glyph_index_cache[' ']; + glyph->index = display->ascii_glyph_index_cache[' ']; break; case 1: { char c = cells[i]->contents[0]; - glyphs[i].index = display->ascii_glyph_index_cache[(int)c]; + glyph->index = display->ascii_glyph_index_cache[(int)c]; break; } default: fprintf(stderr, "runes_display_draw_glyphs_fast requires ascii\n"); return; } - glyphs[i].x = (col + i) * display->fontx; - glyphs[i].y = (row + 1) * display->fonty - display->font_descent; + glyph->x = (col + i) * display->fontx; + glyph->y = (row + 1) * display->fonty - display->font_descent; } cairo_save(display->cr); cairo_move_to(display->cr, col * display->fontx, row * display->fonty); cairo_set_source(display->cr, pattern); cairo_set_scaled_font(display->cr, display->scaled_font); - cairo_show_glyphs(display->cr, glyphs, len); + cairo_show_glyphs(display->cr, display->glyph_buf, len); cairo_restore(display->cr); - - free(glyphs); } static void runes_display_draw_glyphs_slow( |