From: Pierre Habouzit Date: Fri, 10 Aug 2007 15:28:31 +0000 (+0200) Subject: More optimizations X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=058608e1586891e4e40beb8785a3317957658365;p=apps%2Fmadtty.git More optimizations Signed-off-by: Pierre Habouzit --- diff --git a/demo/boxshell.c b/demo/boxshell.c index dbb47e4..b3c8f2d 100644 --- a/demo/boxshell.c +++ b/demo/boxshell.c @@ -27,8 +27,6 @@ int main(void) { struct timeval next = { 0, 0 }; madtty_t *rt; - int pos = 0; - char buf[BUFSIZ]; signal(SIGCHLD, sigchld); @@ -47,7 +45,6 @@ int main(void) /* keep reading keypresses from the user and passing them to the terminal; * also, redraw the terminal to the window at each iteration */ - pos = 0; while (!getout) { fd_set rfds; struct timeval tv = { 0 , 1000 }, t; diff --git a/madtty/madtty.c b/madtty/madtty.c index 2b5fae2..289172e 100644 --- a/madtty/madtty.c +++ b/madtty/madtty.c @@ -65,7 +65,6 @@ static void mtty_row_set(mtty_row_t *row, int start, int len, uint16_t attr) } } -__attribute__((noinline)) static void mtty_row_roll(mtty_row_t *start, mtty_row_t *end, int count) { int n = end - start; @@ -124,6 +123,7 @@ static void cursor_line_up(madtty_t *rt) mtty_row_set(rt->curs_row, 0, rt->cols, 0); } +__attribute__((const)) static uint16_t build_attrs(unsigned curattrs) { return ((curattrs & ~A_COLOR) | COLOR_PAIR(curattrs & 0xff)) @@ -295,36 +295,28 @@ static void interpret_csi_SGR(madtty_t *rt, int param[], int pcount) /* interprets an 'erase display' (ED) escape sequence */ static void interpret_csi_ED(madtty_t *rt, int param[], int pcount) { - int r; - int start_row, start_col, end_row, end_col; + mtty_row_t *row, *start, *end; + attr_t attr = build_attrs(rt->curattrs); /* decide range */ if (pcount && param[0] == 2) { - start_row = 0; - start_col = 0; - end_row = rt->rows - 1; - end_col = rt->cols - 1; + start = rt->lines; + end = rt->lines + rt->rows; } else if (pcount && param[0] == 1) { - start_row = 0; - start_col = 0; - end_row = rt->curs_row - rt->lines; - end_col = rt->curs_col; + start = rt->lines; + end = rt->curs_row; + mtty_row_set(rt->curs_row, 0, rt->curs_col + 1, attr); } else { - start_row = rt->curs_row - rt->lines; - start_col = rt->curs_col; - end_row = rt->rows - 1; - end_col = rt->cols - 1; + mtty_row_set(rt->curs_row, rt->curs_col, + rt->cols - rt->curs_col, attr); + start = rt->curs_row + 1; + end = rt->lines + rt->rows; } - /* clean range */ - mtty_row_set(rt->lines + start_row, start_col, rt->cols - start_col, - build_attrs(rt->curattrs)); - for (r = start_row + 1; r < end_row; r++) { - mtty_row_set(rt->lines + r, 0, rt->cols, build_attrs(rt->curattrs)); + for (row = start; row < end; row++) { + mtty_row_set(row, 0, rt->cols, attr); } - mtty_row_set(rt->lines + end_row, 0, end_col + 1, - build_attrs(rt->curattrs)); } /* interprets a 'move cursor' (CUP) escape sequence */ @@ -397,6 +389,10 @@ static void interpret_csi_ICH(madtty_t *rt, int param[], int pcount) int n = (pcount && param[0] > 0) ? param[0] : 1; int i; + if (rt->curs_col + n > rt->cols) { + n = rt->cols - rt->curs_col; + } + for (i = rt->cols - 1; i >= rt->curs_col + n; i--) { row->text[i] = row->text[i - n]; row->attr[i] = row->attr[i - n]; @@ -412,15 +408,16 @@ static void interpret_csi_DCH(madtty_t *rt, int param[], int pcount) int n = (pcount && param[0] > 0) ? param[0] : 1; int i; - for (i = rt->curs_col; i < rt->cols; i++) { - if (i + n < rt->cols) { - row->text[i] = row->text[i + n]; - row->attr[i] = row->attr[i + n]; - } else { - row->text[i] = 0; - row->attr[i] = build_attrs(rt->curattrs); - } + if (rt->curs_col + n > rt->cols) { + n = rt->cols - rt->curs_col; + } + + for (i = rt->curs_col; i < rt->cols - n; i++) { + row->text[i] = row->text[i + n]; + row->attr[i] = row->attr[i + n]; } + + mtty_row_set(row, rt->cols - n, n, build_attrs(rt->curattrs)); } /* Interpret an 'insert line' sequence (IL) */ @@ -452,7 +449,6 @@ static void interpret_csi_DL(madtty_t *rt, int param[], int pcount) } } else { mtty_row_roll(rt->curs_row, rt->scroll_bot, -n); - for (mtty_row_t *row = rt->scroll_bot - n; row < rt->scroll_bot; row++) { mtty_row_set(row, 0, rt->cols, build_attrs(rt->curattrs)); } @@ -485,7 +481,7 @@ static void interpret_csi_DECSTBM(madtty_t *rt, int param[], int pcount) case 2: new_top = param[0] - 1; - new_bot = param[1] - 1; + new_bot = param[1]; /* clamp to bounds */ if (new_top < 0)