[hackers] [st] Optimize tputtab. || noname

From: <git_AT_suckless.org>
Date: Sat, 26 Apr 2014 00:00:14 +0200

commit 844c503c800e5e1db1e409f5db729431ee2e5c00
Author: noname <noname_AT_inventati.org>
Date: Wed Apr 23 23:12:45 2014 +0400

    Optimize tputtab.
    
    Before this patch executing
            printf '\e[10000000000I'
    or
            printf '\e[10000000000Z'
    resulted in long delay.

diff --git a/st.c b/st.c
index ff9bdd8..c9ef574 100644
--- a/st.c
+++ b/st.c
_AT_@ -375,7 +375,7 @@ static void tmoveto(int, int);
 static void tmoveato(int, int);
 static void tnew(int, int);
 static void tnewline(int);
-static void tputtab(bool);
+static void tputtab(int);
 static void tputc(char *, int);
 static void treset(void);
 static int tresize(int, int);
_AT_@ -1996,8 +1996,7 @@ csihandle(void) {
                 break;
         case 'I': /* CHT -- Cursor Forward Tabulation <n> tab stops */
                 DEFAULT(csiescseq.arg[0], 1);
- while(csiescseq.arg[0]--)
- tputtab(1);
+ tputtab(csiescseq.arg[0]);
                 break;
         case 'J': /* ED -- Clear screen */
                 selclear(NULL);
_AT_@ -2065,8 +2064,7 @@ csihandle(void) {
                 break;
         case 'Z': /* CBT -- Cursor Backward Tabulation <n> tab stops */
                 DEFAULT(csiescseq.arg[0], 1);
- while(csiescseq.arg[0]--)
- tputtab(0);
+ tputtab(-csiescseq.arg[0]);
                 break;
         case 'd': /* VPA -- Move to <row> */
                 DEFAULT(csiescseq.arg[0], 1);
_AT_@ -2281,19 +2279,17 @@ tdump(void) {
 }
 
 void
-tputtab(bool forward) {
+tputtab(int n) {
         uint x = term.c.x;
 
- if(forward) {
- if(x == term.col)
- return;
- for(++x; x < term.col && !term.tabs[x]; ++x)
- /* nothing */ ;
- } else {
- if(x == 0)
- return;
- for(--x; x > 0 && !term.tabs[x]; --x)
- /* nothing */ ;
+ if(n > 0) {
+ while(x < term.col && n--)
+ for(++x; x < term.col && !term.tabs[x]; ++x)
+ /* nothing */ ;
+ } else if(n < 0) {
+ while(x > 0 && n++)
+ for(--x; x > 0 && !term.tabs[x]; --x)
+ /* nothing */ ;
         }
         tmoveto(x, term.c.y);
 }
Received on Sat Apr 26 2014 - 00:00:14 CEST

This archive was generated by hypermail 2.3.0 : Sat Apr 26 2014 - 00:00:28 CEST