breakp2.c, settrace(), cleanup #1/2

"save" command,
  reduce complexity from O(2) to O(1)
This commit is contained in:
rlar 2016-10-30 20:25:26 +01:00
parent b85270c30c
commit 004e49aabf
1 changed files with 12 additions and 7 deletions

View File

@ -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;
}