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);
  }
This commit is contained in:
Daniel Eklöf 2021-02-07 14:52:04 +01:00
parent 63a50afc8e
commit 4bad85b593
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 36 additions and 25 deletions

View file

@ -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)
free(it->item.data);
tll_free(term->ptmx_buffers);
tll_foreach(term->ptmx_paste_buffers, it)
free(it->item.data);
tll_free(term->ptmx_paste_buffers);
tll_free(term->tab_stops);
tll_foreach(term->normal.sixel_images, it)
tll_foreach(term->ptmx_buffers, it) {
free(it->item.data);
tll_remove(term->ptmx_buffers, it);
}
tll_foreach(term->ptmx_paste_buffers, it) {
free(it->item.data);
tll_remove(term->ptmx_paste_buffers, 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);