term: more efficient management of scrolling history
authorAli Gholami Rudi <ali@rudi.ir>
Wed, 14 Aug 2013 17:03:19 +0000 (14 21:33 +0430)
committerAli Gholami Rudi <ali@rudi.ir>
Wed, 14 Aug 2013 17:05:39 +0000 (14 21:35 +0430)
fbpad.h
term.c

diff --git a/fbpad.h b/fbpad.h
index 57fd6d8..b06dc4e 100644 (file)
--- a/fbpad.h
+++ b/fbpad.h
@@ -8,7 +8,7 @@
 #define NCOLS          256             /* maximum number of screen columns */
 #define NROWS          128             /* maximum number of screen rows */
 #define NDOTS          1024            /* maximum pixels in glyphs */
-#define NHIST          32              /* scrolling history lines */
+#define NHIST          128             /* scrolling history lines */
 
 /* isdw.c */
 #define DWCHAR         0x40000000u     /* 2nd half of a fullwidth char */
@@ -33,6 +33,7 @@ struct term {
        char fgs[NROWS * NCOLS];
        char bgs[NROWS * NCOLS];
        struct term_state cur, sav;
+       int histtail;                   /* the next history row */
        int fd;
        int pid;
        int top, bot;
diff --git a/term.c b/term.c
index b266c10..7d9f105 100644 (file)
--- a/term.c
+++ b/term.c
@@ -431,13 +431,16 @@ static void blank_rows(int sr, int er)
        draw_cursor(1);
 }
 
+#define HISTROW(pos)   (term->hist + ((term->histtail + NHIST - (pos)) % NHIST) * pad_cols())
+
 static void scrl_rows(int nr)
 {
-       int nc = nr * pad_cols();
-       memmove(term->hist, term->hist + nc,
-                       (LEN(term->hist) - nc) * sizeof(term->hist[0]));
-       memcpy(term->hist + LEN(term->hist) - nc, term->screen,
-                       nc * sizeof(term->hist[0]));
+       int i;
+       for (i = 0; i < nr; i++) {
+               memcpy(HISTROW(0), screen + i * pad_cols(),
+                               pad_cols() * sizeof(screen[0]));
+               term->histtail = (term->histtail + 1) % NHIST;
+       }
 }
 
 void term_hist(int scrl)
@@ -448,12 +451,12 @@ void term_hist(int scrl)
        lazy_start();
        memset(dirty, 1, sizeof(dirty));
        for (i = 0; i < pad_rows(); i++) {
-               int off = (i - scrl) * pad_cols();
                if (i < scrl) {
-                       _scr = term->hist + LEN(term->hist) + off;
+                       _scr = HISTROW(scrl - i);
                        _fgs = NULL;
                        _bgs = NULL;
                } else {
+                       int off = (i - scrl) * pad_cols();
                        _scr = term->screen + off;
                        _fgs = term->fgs + off;
                        _bgs = term->bgs + off;