From 4bad85b59334467ac839ed2dd91abb6625bc5b89 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 7 Feb 2021 14:52:04 +0100 Subject: misc: when free:ing tll lists, prefer tll_remove() over tll_free() In many places we have the following pattern: tll_foreach(list, it) free(it->item.thing); tll_free(list); Since all tll functions are macros, and thus inlined, and since tll_free in itself expands to a tll_foreach(), the above pattern expands to more native code than necessary. This is somewhat smaller: tll_foreach(list, it) { free(it->item.thing); tll_remove(list, it); } --- terminal.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 91a442ec..8e1e1841 100644 --- a/terminal.c +++ b/terminal.c @@ -1474,20 +1474,25 @@ term_destroy(struct terminal *term) xassert(tll_length(term->render.workers.queue) == 0); tll_free(term->render.workers.queue); - tll_foreach(term->ptmx_buffers, it) + tll_free(term->tab_stops); + + tll_foreach(term->ptmx_buffers, it) { free(it->item.data); - tll_free(term->ptmx_buffers); - tll_foreach(term->ptmx_paste_buffers, it) + tll_remove(term->ptmx_buffers, it); + } + tll_foreach(term->ptmx_paste_buffers, it) { free(it->item.data); - tll_free(term->ptmx_paste_buffers); - tll_free(term->tab_stops); + tll_remove(term->ptmx_paste_buffers, it); + } - tll_foreach(term->normal.sixel_images, it) + tll_foreach(term->normal.sixel_images, it) { sixel_destroy(&it->item); - tll_free(term->normal.sixel_images); - tll_foreach(term->alt.sixel_images, it) + tll_remove(term->normal.sixel_images, it); + } + tll_foreach(term->alt.sixel_images, it) { sixel_destroy(&it->item); - tll_free(term->alt.sixel_images); + tll_remove(term->alt.sixel_images, it); + } sixel_fini(term); urls_reset(term); @@ -1642,12 +1647,14 @@ term_reset(struct terminal *term, bool hard) term->meta.esc_prefix = true; term->meta.eight_bit = true; - tll_foreach(term->normal.sixel_images, it) + tll_foreach(term->normal.sixel_images, it) { sixel_destroy(&it->item); - tll_free(term->normal.sixel_images); - tll_foreach(term->alt.sixel_images, it) + tll_remove(term->normal.sixel_images, it); + } + tll_foreach(term->alt.sixel_images, it) { sixel_destroy(&it->item); - tll_free(term->alt.sixel_images); + tll_remove(term->alt.sixel_images, it); + } #if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED term_ime_enable(term); -- cgit v1.3