mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-02 07:15:31 -04:00
term: turn ‘box-drawings’ array into three dynamically allocated arrays
The box_drawings array is now quite large, and uses up ~4K when *empty*. This patch splits it up into three separate, dynamically allocated arrays; one for the traditional box+line drawing and block elements glyphs, one for braille, and one for the legacy computing symbols. When we need to render a glyph, the *entire* array (that it belongs to) is allocated. I.e this is one step closer to a dynamic glyph cache (like the one fcft uses), but doesn’t go all the way. This is especially nice for people with ‘box-drawings-uses-font-glyphs=yes’; for them, the custom glyphs now uses 3*8 bytes (for the three array pointers), instead of 4K.
This commit is contained in:
parent
ac2091f107
commit
37b15adcd8
3 changed files with 87 additions and 42 deletions
42
terminal.c
42
terminal.c
|
|
@ -626,15 +626,28 @@ err_sem_destroy:
|
|||
}
|
||||
|
||||
static void
|
||||
free_box_drawing(struct fcft_glyph **box_drawing)
|
||||
free_custom_glyph(struct fcft_glyph **glyph)
|
||||
{
|
||||
if (*box_drawing == NULL)
|
||||
if (*glyph == NULL)
|
||||
return;
|
||||
|
||||
free(pixman_image_get_data((*box_drawing)->pix));
|
||||
pixman_image_unref((*box_drawing)->pix);
|
||||
free(*box_drawing);
|
||||
*box_drawing = NULL;
|
||||
free(pixman_image_get_data((*glyph)->pix));
|
||||
pixman_image_unref((*glyph)->pix);
|
||||
free(*glyph);
|
||||
*glyph = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
free_custom_glyphs(struct fcft_glyph ***glyphs, size_t count)
|
||||
{
|
||||
if (*glyphs == NULL)
|
||||
return;
|
||||
|
||||
for (size_t i = 0; i < count; i++)
|
||||
free_custom_glyph(&(*glyphs)[i]);
|
||||
|
||||
free(*glyphs);
|
||||
*glyphs = NULL;
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
@ -647,8 +660,12 @@ term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4])
|
|||
term->fonts[i] = fonts[i];
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < ALEN(term->box_drawing); i++)
|
||||
free_box_drawing(&term->box_drawing[i]);
|
||||
free_custom_glyphs(
|
||||
&term->custom_glyphs.box_drawing, GLYPH_BOX_DRAWING_COUNT);
|
||||
free_custom_glyphs(
|
||||
&term->custom_glyphs.braille, GLYPH_BRAILLE_COUNT);
|
||||
free_custom_glyphs(
|
||||
&term->custom_glyphs.legacy, GLYPH_LEGACY_COUNT);
|
||||
|
||||
const int old_cell_width = term->cell_width;
|
||||
const int old_cell_height = term->cell_height;
|
||||
|
|
@ -1590,8 +1607,13 @@ term_destroy(struct terminal *term)
|
|||
for (size_t i = 0; i < 4; i++)
|
||||
free(term->font_sizes[i]);
|
||||
|
||||
for (size_t i = 0; i < ALEN(term->box_drawing); i++)
|
||||
free_box_drawing(&term->box_drawing[i]);
|
||||
|
||||
free_custom_glyphs(
|
||||
&term->custom_glyphs.box_drawing, GLYPH_BOX_DRAWING_COUNT);
|
||||
free_custom_glyphs(
|
||||
&term->custom_glyphs.braille, GLYPH_BRAILLE_COUNT);
|
||||
free_custom_glyphs(
|
||||
&term->custom_glyphs.legacy, GLYPH_LEGACY_COUNT);
|
||||
|
||||
free(term->search.buf);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue