From 4005fb5bfb6464d607d1cc85f7bd4601d23fd1a6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 16 Feb 2025 10:44:13 +0530 Subject: [PATCH] Micro optimize by using hb_buffer_add_codepoints This skips harfbuzz buffer validation which we dont need since out codepoints are already valid. HarfBuzz docs claim it does "deep-sanity checking" no idea what that is, but I dont think its actually necessary, we will see if it causes any actual text rendering regressions. --- kitty/fonts.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/kitty/fonts.c b/kitty/fonts.c index 0ccf633b3..754121a31 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -1103,18 +1103,16 @@ render_box_cell(FontGroup *fg, RunFont rf, CPUCell *cpu_cell, GPUCell *gpu_cell, static void load_hb_buffer(CPUCell *first_cpu_cell, index_type num_cells, const TextCache *tc, ListOfChars *lc) { - index_type num; + size_t num = 0; hb_buffer_clear_contents(harfbuzz_buffer); - while (num_cells) { - for (num = 0; num_cells; first_cpu_cell++, num_cells--) { - if (first_cpu_cell->is_multicell && first_cpu_cell->x) continue; - text_in_cell(first_cpu_cell, tc, lc); - const size_t count = MIN(lc->count, arraysz(shape_buffer) - num); - memcpy(shape_buffer + num, lc->chars, count * sizeof(shape_buffer[0])); - num += count; - } - hb_buffer_add_utf32(harfbuzz_buffer, shape_buffer, num, 0, num); + for (; num_cells; first_cpu_cell++, num_cells--) { + if (first_cpu_cell->is_multicell && first_cpu_cell->x) continue; + text_in_cell(first_cpu_cell, tc, lc); + const size_t count = MIN(lc->count, arraysz(shape_buffer) - num); + memcpy(shape_buffer + num, lc->chars, count * sizeof(shape_buffer[0])); + num += count; } + hb_buffer_add_codepoints(harfbuzz_buffer, shape_buffer, num, 0, num); hb_buffer_guess_segment_properties(harfbuzz_buffer); if (OPT(force_ltr)) hb_buffer_set_direction(harfbuzz_buffer, HB_DIRECTION_LTR); }