diff options
| author | noname <noname@inventati.org> | 2014-04-23 23:12:45 +0400 |
|---|---|---|
| committer | Roberto E. Vargas Caballero <k0ga@shike2.com> | 2014-04-25 23:57:44 +0200 |
| commit | 844c503c800e5e1db1e409f5db729431ee2e5c00 (patch) | |
| tree | 72f87a46dc995461976df64b0b2a76fdd7ac409c | |
| parent | 1b0b9759dca9739da04f5c8a206b2f8ee5ed8b25 (diff) | |
| download | st-844c503c800e5e1db1e409f5db729431ee2e5c00.tar.gz st-844c503c800e5e1db1e409f5db729431ee2e5c00.zip | |
Optimize tputtab.
Before this patch executing
printf '\e[10000000000I'
or
printf '\e[10000000000Z'
resulted in long delay.
| -rw-r--r-- | st.c | 28 |
1 files changed, 12 insertions, 16 deletions
| @@ -375,7 +375,7 @@ static void tmoveto(int, int); | |||
| 375 | static void tmoveato(int, int); | 375 | static void tmoveato(int, int); |
| 376 | static void tnew(int, int); | 376 | static void tnew(int, int); |
| 377 | static void tnewline(int); | 377 | static void tnewline(int); |
| 378 | static void tputtab(bool); | 378 | static void tputtab(int); |
| 379 | static void tputc(char *, int); | 379 | static void tputc(char *, int); |
| 380 | static void treset(void); | 380 | static void treset(void); |
| 381 | static int tresize(int, int); | 381 | static int tresize(int, int); |
| @@ -1996,8 +1996,7 @@ csihandle(void) { | |||
| 1996 | break; | 1996 | break; |
| 1997 | case 'I': /* CHT -- Cursor Forward Tabulation <n> tab stops */ | 1997 | case 'I': /* CHT -- Cursor Forward Tabulation <n> tab stops */ |
| 1998 | DEFAULT(csiescseq.arg[0], 1); | 1998 | DEFAULT(csiescseq.arg[0], 1); |
| 1999 | while(csiescseq.arg[0]--) | 1999 | tputtab(csiescseq.arg[0]); |
| 2000 | tputtab(1); | ||
| 2001 | break; | 2000 | break; |
| 2002 | case 'J': /* ED -- Clear screen */ | 2001 | case 'J': /* ED -- Clear screen */ |
| 2003 | selclear(NULL); | 2002 | selclear(NULL); |
| @@ -2065,8 +2064,7 @@ csihandle(void) { | |||
| 2065 | break; | 2064 | break; |
| 2066 | case 'Z': /* CBT -- Cursor Backward Tabulation <n> tab stops */ | 2065 | case 'Z': /* CBT -- Cursor Backward Tabulation <n> tab stops */ |
| 2067 | DEFAULT(csiescseq.arg[0], 1); | 2066 | DEFAULT(csiescseq.arg[0], 1); |
| 2068 | while(csiescseq.arg[0]--) | 2067 | tputtab(-csiescseq.arg[0]); |
| 2069 | tputtab(0); | ||
| 2070 | break; | 2068 | break; |
| 2071 | case 'd': /* VPA -- Move to <row> */ | 2069 | case 'd': /* VPA -- Move to <row> */ |
| 2072 | DEFAULT(csiescseq.arg[0], 1); | 2070 | DEFAULT(csiescseq.arg[0], 1); |
| @@ -2281,19 +2279,17 @@ tdump(void) { | |||
| 2281 | } | 2279 | } |
| 2282 | 2280 | ||
| 2283 | void | 2281 | void |
| 2284 | tputtab(bool forward) { | 2282 | tputtab(int n) { |
| 2285 | uint x = term.c.x; | 2283 | uint x = term.c.x; |
| 2286 | 2284 | ||
| 2287 | if(forward) { | 2285 | if(n > 0) { |
| 2288 | if(x == term.col) | 2286 | while(x < term.col && n--) |
| 2289 | return; | 2287 | for(++x; x < term.col && !term.tabs[x]; ++x) |
| 2290 | for(++x; x < term.col && !term.tabs[x]; ++x) | 2288 | /* nothing */ ; |
| 2291 | /* nothing */ ; | 2289 | } else if(n < 0) { |
| 2292 | } else { | 2290 | while(x > 0 && n++) |
| 2293 | if(x == 0) | 2291 | for(--x; x > 0 && !term.tabs[x]; --x) |
| 2294 | return; | 2292 | /* nothing */ ; |
| 2295 | for(--x; x > 0 && !term.tabs[x]; --x) | ||
| 2296 | /* nothing */ ; | ||
| 2297 | } | 2293 | } |
| 2298 | tmoveto(x, term.c.y); | 2294 | tmoveto(x, term.c.y); |
| 2299 | } | 2295 | } |
