xterm - 1996/1/7 - patch #5 - T.Dickey
This patch modifies the object code, by replacing indexing expressions with
temporary variables with the full indexing expression. At first glance, this
seems inefficient (it did to me ;-), until remembering comments made in the
compilers newsgroups that trying to "help" the compiler doesn't really work
that well. A good optimizing compiler can do a better job than the programmer
can. (There's a moral in the use of 'register' variables also, but I won't fix
those...).
Anyway, the revised code generates a smaller object...
charproc.c:
+ recode index expressions in ShowCursor() and HideCursor()
using SCRN_BUF_xxxxS macros - changes object.
+ replace constant '4' by MAX_PTRS - n/c.
ptyx.h:
+ defined the SCRN_BUF_xxxxS macros in terms of BUF_xxxxS
macros, to pick up references to ScrnBuf data directly, and
added MAX_PTRS symbol to pick up those '4' constants strewn
about the code - n/c.
screen.c:
+ recode index expressions in ScreenWrite() using
SCRN_BUF_xxxxS macros - changes object.
+ replace constant '4' by MAX_PTRS - n/c.
+ use macros BUF_CHARS, BUF_ATTRS - n/c.
+ cast calloc to 'Char *' to fix compiler warning on IRIX - n/c
scrollbar.c:
+ replace constant '4' by MAX_PTRS - n/c.
+ cast calloc to 'Char *' to fix compiler warning on IRIX - n/c
--------------------------------------------------------------------------------
charproc.c | 30 +++++++++++++---------
ptyx.h | 17 +++++++++---
screen.c | 77 +++++++++++++++++++++++++++++++---------------------------
scrollbar.c | 10 +++----
4 files changed, 78 insertions, 56 deletions
--------------------------------------------------------------------------------
Index: charproc.c
--- xterm-original/charproc.c Sun Jan 7 16:35:40 1996
+++ xterm-patched/charproc.c Sun Jan 7 18:30:22 1996
@@ -2340,12 +2340,14 @@
register TScreen *screen;
{
register int rows = screen->max_row + 1;
- char *save [4 * MAX_ROWS];
+ char *save [MAX_PTRS * MAX_ROWS];
- memmove( (char *)save, (char *)screen->buf, 4 * sizeof(char *) * rows);
+ memmove( (char *)save, (char *)screen->buf,
+ MAX_PTRS * sizeof(char *) * rows);
memmove( (char *)screen->buf, (char *)screen->altbuf,
- 4 * sizeof(char *) * rows);
- memmove( (char *)screen->altbuf, (char *)save, 4 * sizeof(char *) * rows);
+ MAX_PTRS * sizeof(char *) * rows);
+ memmove( (char *)screen->altbuf, (char *)save,
+ MAX_PTRS * sizeof(char *) * rows);
}
void
@@ -2479,7 +2481,7 @@
screen->allbuf = Allocate (nrows, screen->max_col + 1,
&screen->sbuf_address);
if (screen->scrollWidget)
- screen->buf = &screen->allbuf[4 * screen->savelines];
+ screen->buf = &screen->allbuf[MAX_PTRS * screen->savelines];
else
screen->buf = screen->allbuf;
return;
@@ -2985,9 +2987,12 @@
if (screen->cur_row - screen->topline > screen->max_row)
return;
- c = screen->buf[y = 4 * (screen->cursor_row = screen->cur_row)]
- [x = screen->cursor_col = screen->cur_col];
- flags = screen->buf[y + 1][x];
+
+ screen->cursor_row = screen->cur_row;
+ screen->cursor_col = screen->cur_col;
+
+ c = SCRN_BUF_CHARS(screen, screen->cursor_row)[screen->cursor_col];
+ flags = SCRN_BUF_ATTRS(screen, screen->cursor_row)[screen->cursor_col];
if (c == 0)
c = ' ';
@@ -3103,10 +3108,11 @@
if(screen->cursor_row - screen->topline > screen->max_row)
return;
- c = screen->buf[y = 4 * screen->cursor_row][x = screen->cursor_col];
- flags = screen->buf[y + 1][x];
- fg = screen->buf[y + 2][x];
- bg = screen->buf[y + 3][x];
+
+ c = SCRN_BUF_CHARS(screen, screen->cursor_row)[screen->cursor_col];
+ flags = SCRN_BUF_ATTRS(screen, screen->cursor_row)[screen->cursor_col];
+ fg = SCRN_BUF_FORES(screen, screen->cursor_row)[screen->cursor_col];
+ bg = SCRN_BUF_BACKS(screen, screen->cursor_row)[screen->cursor_col];
fg_pix = (flags&FG_COLOR) ?
screen->colors[fg] : screen->foreground;
Index: ptyx.h
--- xterm-original/ptyx.h Sun Jan 7 16:20:17 1996
+++ xterm-patched/ptyx.h Sun Jan 7 17:58:50 1996
@@ -261,10 +261,19 @@
#define COLOR_BD 16
#define COLOR_UL 17
-#define SCRN_BUF_CHARS(screen, row) (screen->buf[4 * (row) + 0])
-#define SCRN_BUF_ATTRS(screen, row) (screen->buf[4 * (row) + 1])
-#define SCRN_BUF_FORES(screen, row) (screen->buf[4 * (row) + 2])
-#define SCRN_BUF_BACKS(screen, row) (screen->buf[4 * (row) + 3])
+#define MAX_PTRS 4 /* the number of pointers per row in 'ScrnBuf' */
+
+ /* ScrnBuf-level macros */
+#define BUF_CHARS(buf, row) (buf[MAX_PTRS * (row) + 0])
+#define BUF_ATTRS(buf, row) (buf[MAX_PTRS * (row) + 1])
+#define BUF_FORES(buf, row) (buf[MAX_PTRS * (row) + 2])
+#define BUF_BACKS(buf, row) (buf[MAX_PTRS * (row) + 3])
+
+ /* TScreen-level macros */
+#define SCRN_BUF_CHARS(screen, row) BUF_CHARS(screen->buf, row)
+#define SCRN_BUF_ATTRS(screen, row) BUF_ATTRS(screen->buf, row)
+#define SCRN_BUF_FORES(screen, row) BUF_FORES(screen->buf, row)
+#define SCRN_BUF_BACKS(screen, row) BUF_BACKS(screen->buf, row)
typedef struct {
/* These parameters apply to both windows */
Index: screen.c
--- xterm-original/screen.c Sun Jan 7 16:33:06 1996
+++ xterm-patched/screen.c Sun Jan 7 18:54:31 1996
@@ -84,10 +84,10 @@
register Char *tmp;
register int i;
- if ((base = (ScrnBuf) calloc ((unsigned)(nrow *= 4), sizeof (char *))) == 0)
+ if ((base = (ScrnBuf) calloc ((unsigned)(nrow *= MAX_PTRS), sizeof (char *))) == 0)
SysError (ERROR_SCALLOC);
- if ((tmp = calloc ((unsigned) (nrow * ncol), sizeof(char))) == 0)
+ if ((tmp = (Char *)calloc ((unsigned) (nrow * ncol), sizeof(Char))) == 0)
SysError (ERROR_SCALLOC2);
*addr = tmp;
@@ -118,7 +118,7 @@
if (sbuf == NULL || *sbuf == NULL)
return 0;
- oldrow *= 4;
+ oldrow *= MAX_PTRS;
oldbuf = *sbufaddr;
/*
@@ -133,11 +133,11 @@
* If the screen shrinks, remove lines off the top of the buffer
* if resizeGravity resource says to do so.
*/
- nrow *= 4;
+ nrow *= MAX_PTRS;
if (nrow < oldrow && term->misc.resizeGravity == SouthWestGravity) {
/* Remove lines off the top of the buffer if necessary. */
move_up = oldrow-nrow
- - 4*(term->screen.max_row - term->screen.cur_row);
+ - MAX_PTRS*(term->screen.max_row - term->screen.cur_row);
if (move_up < 0)
move_up = 0;
/* Overlapping memmove here! */
@@ -154,14 +154,14 @@
* create the new buffer space and copy old buffer contents there
* line by line.
*/
- if ((tmp = calloc((unsigned) (nrow * ncol), sizeof(char))) == 0)
+ if ((tmp = (Char *)calloc((unsigned) (nrow * ncol), sizeof(Char))) == 0)
SysError(ERROR_SREALLOC);
*sbufaddr = tmp;
minrows = (oldrow < nrow) ? oldrow : nrow;
mincols = (oldcol < ncol) ? oldcol : ncol;
if (nrow > oldrow && term->misc.resizeGravity == SouthWestGravity) {
/* move data down to bottom of expanded screen */
- move_down = Min(nrow-oldrow, 4*term->screen.savedlines);
+ move_down = Min(nrow-oldrow, MAX_PTRS*term->screen.savedlines);
tmp += ncol*move_down;
}
for (i = 0; i < minrows; i++, tmp += ncol) {
@@ -176,7 +176,7 @@
/* Now free the old buffer */
free(oldbuf);
- return move_down ? move_down/4 : -move_up/4; /* convert to rows */
+ return move_down ? move_down/MAX_PTRS : -move_up/MAX_PTRS; /* convert to rows */
}
void
@@ -201,11 +201,12 @@
if (length <= 0)
return;
- col = screen->buf[avail = 4 * screen->cur_row] + screen->cur_col;
- attrs = attrs0 = screen->buf[avail + 1] + screen->cur_col;
- fgs = screen->buf[avail + 2] + screen->cur_col;
- bgs = screen->buf[avail + 3] + screen->cur_col;
+ col = SCRN_BUF_CHARS(screen, screen->cur_row) + screen->cur_col;
+ attrs = SCRN_BUF_ATTRS(screen, screen->cur_row) + screen->cur_col;
+ fgs = SCRN_BUF_FORES(screen, screen->cur_row) + screen->cur_col;
+ bgs = SCRN_BUF_BACKS(screen, screen->cur_row) + screen->cur_col;
+ attrs0 = attrs;
wrappedbit = *attrs0&LINEWRAPPED;
flags &= ATTRIBUTES;
flags |= CHARDRAWN;
@@ -233,15 +234,14 @@
register int where, n, size;
{
register int i;
- char *save [4 * MAX_ROWS];
-
+ char *save [MAX_PTRS * MAX_ROWS];
/* save n lines at bottom */
- memmove( (char *) save, (char *) &sb [4 * (last -= n - 1)],
- 4 * sizeof (char *) * n);
+ memmove( (char *) save, (char *) &sb [MAX_PTRS * (last -= n - 1)],
+ MAX_PTRS * sizeof (char *) * n);
/* clear contents of old rows */
- for (i = 4 * n - 1; i >= 0; i--)
+ for (i = MAX_PTRS * n - 1; i >= 0; i--)
bzero ((char *) save [i], size);
/*
@@ -253,11 +253,14 @@
*
* +--------|---------|----+
*/
- memmove( (char *) &sb [4 * (where + n)], (char *) &sb [4 * where],
- 4 * sizeof (char *) * (last - where));
+ memmove( (char *) &sb [MAX_PTRS * (where + n)],
+ (char *) &sb [MAX_PTRS * where],
+ MAX_PTRS * sizeof (char *) * (last - where));
/* reuse storage for new lines at where */
- memmove( (char *) &sb[4 * where], (char *)save, 4 * sizeof(char *) * n);
+ memmove( (char *) &sb[MAX_PTRS * where],
+ (char *)save,
+ MAX_PTRS * sizeof(char *) * n);
}
void
@@ -273,22 +276,26 @@
int where;
{
register int i;
- char *save [4 * MAX_ROWS];
+ char *save [MAX_PTRS * MAX_ROWS];
/* save n lines at where */
- memmove( (char *)save, (char *) &sb[4 * where], 4 * sizeof(char *) * n);
+ memmove( (char *)save,
+ (char *) &sb[MAX_PTRS * where],
+ MAX_PTRS * sizeof(char *) * n);
/* clear contents of old rows */
- for (i = 4 * n - 1 ; i >= 0 ; i--)
+ for (i = MAX_PTRS * n - 1 ; i >= 0 ; i--)
bzero ((char *) save [i], size);
/* move up lines */
- memmove( (char *) &sb[4 * where], (char *) &sb[4 * (where + n)],
- 4 * sizeof (char *) * ((last -= n - 1) - where));
+ memmove( (char *) &sb[MAX_PTRS * where],
+ (char *) &sb[MAX_PTRS * (where + n)],
+ MAX_PTRS * sizeof (char *) * ((last -= n - 1) - where));
/* reuse storage for new bottom lines */
- memmove( (char *) &sb[4 * last], (char *)save,
- 4 * sizeof(char *) * n);
+ memmove( (char *) &sb[MAX_PTRS * last],
+ (char *)save,
+ MAX_PTRS * sizeof(char *) * n);
}
void
@@ -301,8 +308,8 @@
register int col, n;
{
register int i, j;
- register Char *ptr = sb [4 * row];
- register Char *attrs = sb [4 * row + 1];
+ register Char *ptr = BUF_CHARS(sb, row);
+ register Char *attrs = BUF_ATTRS(sb, row);
int wrappedbit = attrs[0]&LINEWRAPPED;
attrs[0] &= ~LINEWRAPPED; /* make sure the bit isn't moved */
@@ -329,8 +336,8 @@
register int row, size;
register int n, col;
{
- register Char *ptr = sb[4 * row];
- register Char *attrs = sb[4 * row + 1];
+ register Char *ptr = BUF_CHARS(sb, row);
+ register Char *attrs = BUF_ATTRS(sb, row);
register Size_t nbytes = (size - n - col);
int wrappedbit = attrs[0]&LINEWRAPPED;
@@ -543,8 +550,8 @@
register TScreen *screen;
register int first, last;
{
- first *= 4;
- last = 4 * last + 3;
+ first *= MAX_PTRS;
+ last = MAX_PTRS * last + (MAX_PTRS-1);
while (first <= last)
bzero (screen->buf [first++], (screen->max_col + 1));
}
@@ -625,7 +632,7 @@
rows + savelines, cols,
screen->max_row + 1 + savelines,
screen->max_col + 1);
- screen->buf = &screen->allbuf[4 * savelines];
+ screen->buf = &screen->allbuf[MAX_PTRS * savelines];
screen->max_row += delta_rows;
screen->max_col = cols - 1;
@@ -767,7 +774,7 @@
register int row, col, len;
{
register int i;
- register Char *ptr = sb [4 * row];
+ register Char *ptr = BUF_CHARS(sb, row);
for (i = col; i < len; i++) {
if (ptr[i])
Index: scrollbar.c
--- xterm-original/scrollbar.c Sat Jan 6 20:05:37 1996
+++ xterm-patched/scrollbar.c Sun Jan 7 18:54:56 1996
@@ -353,17 +353,17 @@
if (doalloc && screen->allbuf) {
if((screen->allbuf =
(ScrnBuf) realloc((char *) screen->buf,
- (unsigned) 4*(screen->max_row + 2 +
+ (unsigned) MAX_PTRS*(screen->max_row + 2 +
screen->savelines) *
sizeof(char *)))
== NULL)
Error (ERROR_SBRALLOC);
- screen->buf = &screen->allbuf[4 * screen->savelines];
+ screen->buf = &screen->allbuf[MAX_PTRS * screen->savelines];
memmove( (char *)screen->buf, (char *)screen->allbuf,
- 4 * (screen->max_row + 2) * sizeof (char *));
- for(i = 4 * screen->savelines - 1 ; i >= 0 ; i--)
+ MAX_PTRS * (screen->max_row + 2) * sizeof (char *));
+ for(i = MAX_PTRS * screen->savelines - 1 ; i >= 0 ; i--)
if((screen->allbuf[i] =
- calloc((unsigned) screen->max_col + 1, sizeof(char))) ==
+ (Char *)calloc((unsigned) screen->max_col + 1, sizeof(Char))) ==
NULL)
Error (ERROR_SBRALLOC2);
}