diff options
| author | Aurélien Aptel <aurelien.aptel@gmail.com> | 2010-08-26 21:37:12 +0200 |
|---|---|---|
| committer | Aurélien Aptel <aurelien.aptel@gmail.com> | 2010-08-26 21:37:12 +0200 |
| commit | 4db3df312ada9d92564d5580fb4e67f7704efff8 (patch) | |
| tree | 5c1eb097091bdde2b595ba72fe3430880e17850c | |
| parent | e8c13ebe8001a7870a70b698d8b8fa80b7c90fd3 (diff) | |
| download | st-4db3df312ada9d92564d5580fb4e67f7704efff8.tar.gz st-4db3df312ada9d92564d5580fb4e67f7704efff8.zip | |
faster resizing.
| -rw-r--r-- | st.c | 21 |
1 files changed, 9 insertions, 12 deletions
| @@ -1001,23 +1001,21 @@ tputs(char *s, int len) { | |||
| 1001 | void | 1001 | void |
| 1002 | tresize(int col, int row) { | 1002 | tresize(int col, int row) { |
| 1003 | int i; | 1003 | int i; |
| 1004 | Line *line; | ||
| 1005 | int minrow = MIN(row, term.row); | 1004 | int minrow = MIN(row, term.row); |
| 1006 | int mincol = MIN(col, term.col); | 1005 | int mincol = MIN(col, term.col); |
| 1007 | 1006 | ||
| 1008 | if(col < 1 || row < 1) | 1007 | if(col < 1 || row < 1) |
| 1009 | return; | 1008 | return; |
| 1010 | /* alloc */ | 1009 | |
| 1011 | line = calloc(row, sizeof(Line)); | 1010 | for(i = row; i < term.row; i++) |
| 1012 | for(i = 0 ; i < row; i++) | ||
| 1013 | line[i] = calloc(col, sizeof(Glyph)); | ||
| 1014 | /* copy */ | ||
| 1015 | for(i = 0 ; i < minrow; i++) | ||
| 1016 | memcpy(line[i], term.line[i], mincol * sizeof(Glyph)); | ||
| 1017 | /* free */ | ||
| 1018 | for(i = 0; i < term.row; i++) | ||
| 1019 | free(term.line[i]); | 1011 | free(term.line[i]); |
| 1020 | free(term.line); | 1012 | term.line = realloc(term.line, row * sizeof(Line)); |
| 1013 | for(i = 0; i < minrow; i++) { | ||
| 1014 | term.line[i] = realloc(term.line[i], col * sizeof(Glyph)); | ||
| 1015 | memset(term.line[i] + mincol, 0, (col - mincol) * sizeof(Glyph)); | ||
| 1016 | } | ||
| 1017 | for(/* i == minrow */; i < row; i++) | ||
| 1018 | term.line[i] = calloc(col, sizeof(Glyph)); | ||
| 1021 | 1019 | ||
| 1022 | LIMIT(term.c.x, 0, col-1); | 1020 | LIMIT(term.c.x, 0, col-1); |
| 1023 | LIMIT(term.c.y, 0, row-1); | 1021 | LIMIT(term.c.y, 0, row-1); |
| @@ -1025,7 +1023,6 @@ tresize(int col, int row) { | |||
| 1025 | LIMIT(term.bot, 0, row-1); | 1023 | LIMIT(term.bot, 0, row-1); |
| 1026 | 1024 | ||
| 1027 | term.bot = row-1; | 1025 | term.bot = row-1; |
| 1028 | term.line = line; | ||
| 1029 | term.col = col, term.row = row; | 1026 | term.col = col, term.row = row; |
| 1030 | } | 1027 | } |
| 1031 | 1028 | ||
