rio: do backspace \b processing inplace avoiding buffer allocation

This commit is contained in:
cinap_lenrek 2013-11-03 04:03:38 +01:00
parent 9619a621ac
commit c5a70cc23d

View file

@ -164,7 +164,7 @@ showcandidates(Window *, Completion *);
void void
winctl(void *arg) winctl(void *arg)
{ {
Rune *rp, *bp, *tp, *up; Rune *rp, *up;
uint qh, q0; uint qh, q0;
int nr, nb, c, wid, i, npart, initial, lastb; int nr, nb, c, wid, i, npart, initial, lastb;
char *s, *t, part[3]; char *s, *t, part[3];
@ -346,23 +346,18 @@ winctl(void *arg)
recv(cwm.cw, &pair); recv(cwm.cw, &pair);
rp = pair.s; rp = pair.s;
nr = pair.ns; nr = pair.ns;
bp = rp;
for(i=0; i<nr; i++) for(i=0; i<nr; i++)
if(*bp++ == '\b'){ if(rp[i] == '\b'){
--bp; up = rp+i;
initial = 0; initial = 0;
tp = runemalloc(nr);
runemove(tp, rp, i);
up = tp+i;
for(; i<nr; i++){ for(; i<nr; i++){
*up = *bp++; if(rp[i] == '\b'){
if(*up == '\b') if(up == rp)
if(up == tp)
initial++; initial++;
else else
--up; up--;
else }else
up++; *up++ = rp[i];
} }
if(initial){ if(initial){
if(initial > w->qh) if(initial > w->qh)
@ -371,10 +366,7 @@ winctl(void *arg)
wdelete(w, qh, qh+initial); wdelete(w, qh, qh+initial);
w->qh = qh; w->qh = qh;
} }
free(rp); nr = up - rp;
rp = tp;
nr = up-tp;
rp[nr] = 0;
break; break;
} }
w->qh = winsert(w, rp, nr, w->qh)+nr; w->qh = winsert(w, rp, nr, w->qh)+nr;