aboutsummaryrefslogtreecommitdiff
path: root/terminal.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-09-14 07:50:49 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-09-14 07:50:49 +0000
commit37b15adcd8306652ce21804cb6140d1361adc94f (patch)
tree171295b380458ed96a2bbbd3b6502eff608c227e /terminal.c
parentbox-drawing: NOINLINE braille (diff)
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.
Diffstat (limited to 'terminal.c')
-rw-r--r--terminal.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/terminal.c b/terminal.c
index 0138aa15..e6837977 100644
--- a/terminal.c
+++ b/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);