[hackers] [st] replaced memset by loops in tresize(); turns out it's faster. || Aurélien Aptel

From: <hg_AT_suckless.org>
Date: Tue, 12 Oct 2010 23:26:31 +0000 (UTC)

changeset: 153:ae558fc2eb69
tag: tip
user: Aurélien Aptel <aurelien.aptel_AT_gmail.com>
date: Wed Oct 13 01:27:09 2010 +0200
files: st.c
description:
replaced memset by loops in tresize(); turns out it's faster.

diff -r 22a503e72521 -r ae558fc2eb69 st.c
--- a/st.c Wed Oct 13 01:25:04 2010 +0200
+++ b/st.c Wed Oct 13 01:27:09 2010 +0200
@@ -677,7 +677,7 @@
 
 void
 tclearregion(int x1, int y1, int x2, int y2) {
- int y, temp;
+ int x, y, temp;
 
         if(x1 > x2)
                 temp = x1, x1 = x2, x2 = temp;
@@ -690,7 +690,8 @@
         LIMIT(y2, 0, term.row-1);
 
         for(y = y1; y <= y2; y++)
- memset(&term.line[y][x1], 0, sizeof(Glyph)*(x2-x1+1));
+ for(x = x1; x <= x2; x++)
+ term.line[y][x].state = 0;
 }
 
 void
@@ -1192,7 +1193,7 @@
 
 void
 tresize(int col, int row) {
- int i;
+ int i, x;
         int minrow = MIN(row, term.row);
         int mincol = MIN(col, term.col);
         int slide = term.c.y - row + 1;
@@ -1226,8 +1227,10 @@
         for(i = 0; i < minrow; i++) {
                 term.line[i] = realloc(term.line[i], col * sizeof(Glyph));
                 term.alt[i] = realloc(term.alt[i], col * sizeof(Glyph));
- memset(term.line[i] + mincol, 0, (col - mincol) * sizeof(Glyph));
- memset(term.alt[i] + mincol, 0, (col - mincol) * sizeof(Glyph));
+ for(x = mincol; x < col; x++) {
+ term.line[i][x].state = 0;
+ term.alt[i][x].state = 0;
+ }
         }
 
         /* allocate any new rows */
Received on Wed Oct 13 2010 - 01:26:31 CEST

This archive was generated by hypermail 2.2.0 : Wed Oct 13 2010 - 01:36:06 CEST