rio: eleminate temporary allocations before frinsert() and in namecomplete()

frinsert() shouldnt modify the runes passed and the
buffer isnt going to be modified my us during the call
so removing the temporary copies.

namecomplete() makes utf-8 copies of the rune strings so
theres no need to copy the runes.
This commit is contained in:
cinap_lenrek 2013-11-05 08:00:26 +01:00
parent f73bf5f90d
commit 118cf5e36a

View file

@ -569,11 +569,9 @@ namecomplete(Window *w)
if(w->q0<w->nr && w->r[w->q0]>' ') /* must be at end of word */ if(w->q0<w->nr && w->r[w->q0]>' ') /* must be at end of word */
return; return;
nstr = windfilewidth(w, w->q0, TRUE); nstr = windfilewidth(w, w->q0, TRUE);
str = runemalloc(nstr); str = w->r+(w->q0-nstr);
runemove(str, w->r+(w->q0-nstr), nstr);
npath = windfilewidth(w, w->q0-nstr, FALSE); npath = windfilewidth(w, w->q0-nstr, FALSE);
path = runemalloc(npath); path = w->r+(w->q0-nstr-npath);
runemove(path, w->r+(w->q0-nstr-npath), npath);
/* is path rooted? if not, we need to make it relative to window path */ /* is path rooted? if not, we need to make it relative to window path */
if(npath>0 && path[0]=='/') if(npath>0 && path[0]=='/')
@ -585,6 +583,8 @@ namecomplete(Window *w)
root = w->dir; root = w->dir;
dir = smprint("%s/%.*S", root, npath, path); dir = smprint("%s/%.*S", root, npath, path);
} }
if(dir == nil)
return;
/* run in background, winctl will collect the result on w->complete chan */ /* run in background, winctl will collect the result on w->complete chan */
job = emalloc(sizeof *job); job = emalloc(sizeof *job);
@ -593,9 +593,6 @@ namecomplete(Window *w)
job->win = w; job->win = w;
incref(w); incref(w);
proccreate(completeproc, job, STACK); proccreate(completeproc, job, STACK);
free(path);
free(str);
} }
void void
@ -1640,10 +1637,8 @@ wsetorigin(Window *w, uint org, int exact)
fixup = 1; /* frdelete can leave end of last line in wrong selection mode; it doesn't know what follows */ fixup = 1; /* frdelete can leave end of last line in wrong selection mode; it doesn't know what follows */
}else if(a<0 && -a<w->nchars){ }else if(a<0 && -a<w->nchars){
n = w->org - org; n = w->org - org;
r = runemalloc(n); r = w->r+org;
runemove(r, w->r+org, n);
frinsert(w, r, r+n, 0); frinsert(w, r, r+n, 0);
free(r);
}else }else
frdelete(w, 0, w->nchars); frdelete(w, 0, w->nchars);
w->org = org; w->org = org;
@ -1764,16 +1759,14 @@ wfill(Window *w)
Rune *rp; Rune *rp;
int i, n, m, nl; int i, n, m, nl;
if(w->lastlinefull) while(w->lastlinefull == FALSE){
return;
rp = malloc(messagesize);
do{
n = w->nr-(w->org+w->nchars); n = w->nr-(w->org+w->nchars);
if(n == 0) if(n == 0)
break; break;
if(n > 2000) /* educated guess at reasonable amount */ if(n > 2000) /* educated guess at reasonable amount */
n = 2000; n = 2000;
runemove(rp, w->r+(w->org+w->nchars), n); rp = w->r+(w->org+w->nchars);
/* /*
* it's expensive to frinsert more than we need, so * it's expensive to frinsert more than we need, so
* count newlines. * count newlines.
@ -1788,8 +1781,7 @@ wfill(Window *w)
} }
} }
frinsert(w, rp, rp+i, w->nchars); frinsert(w, rp, rp+i, w->nchars);
}while(w->lastlinefull == FALSE); }
free(rp);
} }
char* char*