From a2f7d03d4ef7f606680894693f52150a8eb1ac28 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Wed, 23 Jul 2014 15:28:37 +0200 Subject: rc: fix slow Xqdol(), avoid recursion in conclist(), estrdup(), avoid copying Xqdol() used to take quadratic time because of strcat(), the code isnt really needed as list2str() aready does the same thing in linear time without the strcat(). add estrdup() which uses emalloc() so allocation error are catched. move strdups() of name from callers into newvar(). avoid recursion of conclist(), and avoid copying of word strings by providing Newword() function which doesnt copy the word string. --- sys/src/cmd/rc/simple.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'sys/src/cmd/rc/simple.c') diff --git a/sys/src/cmd/rc/simple.c b/sys/src/cmd/rc/simple.c index d4b897cd1..fb50ce31d 100644 --- a/sys/src/cmd/rc/simple.c +++ b/sys/src/cmd/rc/simple.c @@ -131,7 +131,7 @@ execfunc(var *func) runq->argv->words = 0; poplist(); start(func->fn, func->pc, runq->local); - runq->local = newvar(strdup("*"), runq->local); + runq->local = newvar("*", runq->local); runq->local->val = starval; runq->local->changed = 1; } @@ -172,7 +172,7 @@ execcd(void) dir = smprint("%s/%s", cdpath->word, a->next->word); else - dir = strdup(a->next->word); + dir = estrdup(a->next->word); if(dochdir(dir) >= 0){ if(cdpath->word[0] != '\0' && @@ -355,14 +355,14 @@ execdot(void) Xerror1("Usage: . [-i] file [arg ...]"); return; } - zero = strdup(p->argv->words->word); + zero = estrdup(p->argv->words->word); popword(); fd = -1; for(path = searchpath(zero); path; path = path->next){ if(path->word[0] != '\0') file = smprint("%s/%s", path->word, zero); else - file = strdup(zero); + file = estrdup(zero); fd = open(file, 0); free(file); @@ -480,7 +480,7 @@ execwhatis(void){ /* mildly wrong -- should fork before writing */ file = smprint("%s/%s", path->word, a->word); else - file = strdup(a->word); + file = estrdup(a->word); if(Executable(file)){ pfmt(out, "%s\n", file); free(file); -- cgit v1.2.3