[hackers] [st] faster resizing. || Aurélien Aptel

From: <hg_AT_suckless.org>
Date: Thu, 26 Aug 2010 17:39:56 +0000 (UTC)

changeset: 92:faf5564c7b60
tag: tip
user: Aurélien Aptel <aurelien.aptel_AT_gmail.com>
date: Thu Aug 26 21:37:12 2010 +0200
files: st.c
description:
faster resizing.

diff -r b688fd476748 -r faf5564c7b60 st.c
--- a/st.c Thu Aug 26 21:36:21 2010 +0200
+++ b/st.c Thu Aug 26 21:37:12 2010 +0200
@@ -1001,23 +1001,21 @@
 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 @@
         LIMIT(term.bot, 0, row-1);
         
         term.bot = row-1;
- term.line = line;
         term.col = col, term.row = row;
 }
 
Received on Thu Aug 26 2010 - 19:39:56 CEST

This archive was generated by hypermail 2.2.0 : Thu Aug 26 2010 - 19:48:08 CEST