summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurélien Aptel2010-08-26 21:37:12 +0200
committerAurélien Aptel2010-08-26 21:37:12 +0200
commit4db3df312ada9d92564d5580fb4e67f7704efff8 (patch)
tree5c1eb097091bdde2b595ba72fe3430880e17850c
parente8c13ebe8001a7870a70b698d8b8fa80b7c90fd3 (diff)
downloadst-4db3df312ada9d92564d5580fb4e67f7704efff8.tar.gz
st-4db3df312ada9d92564d5580fb4e67f7704efff8.tar.xz
st-4db3df312ada9d92564d5580fb4e67f7704efff8.zip
faster resizing.
-rw-r--r--st.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/st.c b/st.c
index e288902..f44db79 100644
--- a/st.c
+++ b/st.c
@@ -1001,23 +1001,21 @@ tputs(char *s, int len) {
void
tresize(int col, int row) {
int i;
- Line *line;
int minrow = MIN(row, term.row);
int mincol = MIN(col, term.col);
if(col < 1 || row < 1)
return;
- /* alloc */
- line = calloc(row, sizeof(Line));
- for(i = 0 ; i < row; i++)
- line[i] = calloc(col, sizeof(Glyph));
- /* copy */
- for(i = 0 ; i < minrow; i++)
- memcpy(line[i], term.line[i], mincol * sizeof(Glyph));
- /* free */
- for(i = 0; i < term.row; i++)
+
+ for(i = row; i < term.row; i++)
free(term.line[i]);
- free(term.line);
+ term.line = realloc(term.line, row * sizeof(Line));
+ for(i = 0; i < minrow; i++) {
+ term.line[i] = realloc(term.line[i], col * sizeof(Glyph));
+ memset(term.line[i] + mincol, 0, (col - mincol) * sizeof(Glyph));
+ }
+ for(/* i == minrow */; i < row; i++)
+ term.line[i] = calloc(col, sizeof(Glyph));
LIMIT(term.c.x, 0, col-1);
LIMIT(term.c.y, 0, row-1);
@@ -1025,7 +1023,6 @@ tresize(int col, int row) {
LIMIT(term.bot, 0, row-1);
term.bot = row-1;
- term.line = line;
term.col = col, term.row = row;
}