From 5ac315bc3a15bc153b1d93b8f88a33743462c244 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 7 May 2021 09:30:44 +0530 Subject: [PATCH] DRYer --- kitty/fonts.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/kitty/fonts.c b/kitty/fonts.c index 4760be0c2..2950f8363 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -1000,13 +1000,9 @@ render_groups(FontGroup *fg, Font *font, bool center_glyph) { if (group->num_glyphs) { size_t sz = MAX(group->num_glyphs, group->num_cells) + 16; if (global_glyph_render_scratch.sz < sz) { - free(global_glyph_render_scratch.glyphs); - global_glyph_render_scratch.glyphs = malloc(sz * sizeof(global_glyph_render_scratch.glyphs[0])); - if (!global_glyph_render_scratch.glyphs) fatal("Out of memory"); - free(global_glyph_render_scratch.sprite_positions); - global_glyph_render_scratch.sprite_positions = malloc(sz * sizeof(global_glyph_render_scratch.sprite_positions[0])); - if (!global_glyph_render_scratch.sprite_positions) fatal("Out of memory"); - global_glyph_render_scratch.sz = sz; +#define a(what) free(global_glyph_render_scratch.what); global_glyph_render_scratch.what = malloc(sz * sizeof(global_glyph_render_scratch.what[0])); if (!global_glyph_render_scratch.what) fatal("Out of memory"); + a(glyphs); a(sprite_positions); +#undef a } for (unsigned i = 0; i < group->num_glyphs; i++) global_glyph_render_scratch.glyphs[i] = G(info)[group->first_glyph_idx + i].codepoint; // We dont want to render the spaces in a space ligature because