vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit dbac9814c64cb8208539633debbea591a85d5fb0
parent 86145282b9346b856e9595411139439f2a712e8c
Author: Mateusz Okulus <mmokulus@gmail.com>
Date:   Sun, 15 Nov 2020 20:40:08 +0100

view: make view_selections_dispose_all O(n)

The for loop in selection_free won't run because the next element
will always be NULL, because we are freeing from the end.

Close #852

Diffstat:
Mview.c | 7+++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/view.c b/view.c @@ -1196,8 +1196,11 @@ void view_selections_clear_all(View *view) { } void view_selections_dispose_all(View *view) { - for (Selection *s = view->selections, *next; s; s = next) { - next = s->next; + Selection *last = view->selections; + while (last->next) + last = last->next; + for (Selection *s = last, *prev; s; s = prev) { + prev = s->prev; if (s != view->selection) selection_free(s); }