From 004e49aabfcc34316041b8d61703efa746e485f4 Mon Sep 17 00:00:00 2001 From: rlar Date: Sun, 30 Oct 2016 20:25:26 +0100 Subject: [PATCH] breakp2.c, settrace(), cleanup #1/2 "save" command, reduce complexity from O(2) to O(1) --- src/frontend/breakp2.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/frontend/breakp2.c b/src/frontend/breakp2.c index 83fc05831..ef9b8d21a 100644 --- a/src/frontend/breakp2.c +++ b/src/frontend/breakp2.c @@ -49,7 +49,7 @@ com_save2(wordlist *wl, char *name) void settrace(wordlist *wl, int what, char *name) { - struct dbcomm *d, *td; + struct dbcomm *d, *last; char *s; if (!ft_curckt) { @@ -57,6 +57,12 @@ settrace(wordlist *wl, int what, char *name) return; } + if (dbs) + for (last = dbs; last->db_next; last = last->db_next) + ; + else + last = NULL; + while (wl) { s = cp_unquote(wl->wl_word); d = TMALLOC(struct dbcomm, 1); @@ -96,13 +102,12 @@ settrace(wordlist *wl, int what, char *name) tfree(s); /*DG avoid memoy leak */ - if (dbs) { - for (td = dbs; td->db_next; td = td->db_next) - ; - td->db_next = d; - } else { + if (last) + last->db_next = d; + else ft_curckt->ci_dbs = dbs = d; - } + + last = d; wl = wl->wl_next; }