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:
Daniel Eklöf 2021-09-14 09:50:49 +02:00
parent ac2091f107
commit 37b15adcd8
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 87 additions and 42 deletions

View file

@ -513,10 +513,12 @@ render_cell(struct terminal *term, pixman_image_t *pix,
if (base != 0) {
if (unlikely(
/* Classic box drawings */
(base >= 0x2500 && base <= 0x259f) ||
(base >= GLYPH_BOX_DRAWING_FIRST &&
base <= GLYPH_BOX_DRAWING_LAST) ||
/* Braille */
(base >= 0x2800 && base <= 0x28ff) ||
(base >= GLYPH_BRAILLE_FIRST &&
base <= GLYPH_BRAILLE_LAST) ||
/*
* Unicode 13 "Symbols for Legacy Computing"
@ -524,42 +526,50 @@ render_cell(struct terminal *term, pixman_image_t *pix,
*
* Note, the full range is U+1FB00 - U+1FBF9
*/
/* Unicode 13 sextants */
(base >= 0x1fb00 && base <= 0x1fb8b) ||
(base >= 0x1fb9a && base <= 0x1fb9b)) &&
(base >= GLYPH_LEGACY_FIRST &&
base <= GLYPH_LEGACY_LAST)) &&
likely(!term->conf->box_drawings_uses_font_glyphs))
{
/* Box drawing characters */
size_t idx = base >= 0x1fb00
? (base >= 0x1fb9a
? base - 0x1fb9a + 556
: base - 0x1fb00 + 416)
: (base >= 0x2800
? base - 0x2800 + 160
: base - 0x2500);
struct fcft_glyph ***arr;
size_t count;
size_t idx;
xassert(idx < ALEN(term->box_drawing));
if (base >= GLYPH_LEGACY_FIRST) {
arr = &term->custom_glyphs.legacy;
count = GLYPH_LEGACY_COUNT;
idx = base - GLYPH_LEGACY_FIRST;
} else if (base >= GLYPH_BRAILLE_FIRST) {
arr = &term->custom_glyphs.braille;
count = GLYPH_BRAILLE_COUNT;
idx = base - GLYPH_BRAILLE_FIRST;
} else {
arr = &term->custom_glyphs.box_drawing;
count = GLYPH_BOX_DRAWING_COUNT;
idx = base - GLYPH_BOX_DRAWING_FIRST;
}
if (likely(term->box_drawing[idx] != NULL))
single = term->box_drawing[idx];
if (unlikely(*arr == NULL))
*arr = xcalloc(count, sizeof((*arr)[0]));
if (likely((*arr)[idx] != NULL))
single = (*arr)[idx];
else {
mtx_lock(&term->render.workers.lock);
/* Other thread may have instantiated it while we
* acquired the lock */
if (term->box_drawing[idx] == NULL)
term->box_drawing[idx] = box_drawing(term, base);
single = (*arr)[idx];
if (likely(single == NULL))
single = (*arr)[idx] = box_drawing(term, base);
mtx_unlock(&term->render.workers.lock);
single = term->box_drawing[idx];
xassert(single != NULL);
}
glyph_count = 1;
glyphs = &single;
cell_cols = single->cols;
if (single != NULL) {
glyph_count = 1;
glyphs = &single;
cell_cols = single->cols;
}
}
else if (base >= CELL_COMB_CHARS_LO && base <= CELL_COMB_CHARS_HI)