Re: rasops.c: avoid calculating offset several times

2016-09-26 Thread Martin Natano
On Mon, Sep 26, 2016 at 11:35:34AM +0200, Frederic Cambus wrote:
> Hi tech@,
> 
> Here is a diff to avoid calculating offset several times in rasops.c.
> This was done for a few functions already, but not all of them.
> 
> Comments? OK?

OK, that's more readable.


> 
> Index: sys/dev/rasops/rasops.c
> ===
> RCS file: /cvs/src/sys/dev/rasops/rasops.c,v
> retrieving revision 1.42
> diff -u -p -r1.42 rasops.c
> --- sys/dev/rasops/rasops.c   7 Sep 2015 18:00:58 -   1.42
> +++ sys/dev/rasops/rasops.c   21 Sep 2016 14:44:58 -
> @@ -1577,8 +1577,10 @@ rasops_vcons_erasecols(void *cookie, int
>   int i;
>  
>   for (i = 0; i < num; i++) {
> - scr->rs_bs[row * cols + col + i].uc = ' ';
> - scr->rs_bs[row * cols + col + i].attr = attr;
> + int off = row * cols + col + i;
> +
> + scr->rs_bs[off].uc = ' ';
> + scr->rs_bs[off].attr = attr;
>   }
>  
>   if (!scr->rs_visible)
> @@ -1626,8 +1628,10 @@ rasops_vcons_eraserows(void *cookie, int
>   int i;
>  
>   for (i = 0; i < num * cols; i++) {
> - scr->rs_bs[row * cols + i].uc = ' ';
> - scr->rs_bs[row * cols + i].attr = attr;
> + int off = row * cols + i;
> +
> + scr->rs_bs[off].uc = ' ';
> + scr->rs_bs[off].attr = attr;
>   }
>  
>   if (!scr->rs_visible)
> @@ -1695,8 +1699,10 @@ rasops_wronly_erasecols(void *cookie, in
>   int i;
>  
>   for (i = 0; i < num; i++) {
> - ri->ri_bs[row * cols + col + i].uc = ' ';
> - ri->ri_bs[row * cols + col + i].attr = attr;
> + int off = row * cols + col + i;
> +
> + ri->ri_bs[off].uc = ' ';
> + ri->ri_bs[off].attr = attr;
>   }
>  
>   return ri->ri_erasecols(ri, row, col, num, attr);
> @@ -1734,8 +1740,10 @@ rasops_wronly_eraserows(void *cookie, in
>   int i;
>  
>   for (i = 0; i < num * cols; i++) {
> - ri->ri_bs[row * cols + i].uc = ' ';
> - ri->ri_bs[row * cols + i].attr = attr;
> + int off = row * cols + i;
> +
> + ri->ri_bs[off].uc = ' ';
> + ri->ri_bs[off].attr = attr;
>   }
>  
>   return ri->ri_eraserows(ri, row, num, attr);
> 



rasops.c: avoid calculating offset several times

2016-09-26 Thread Frederic Cambus
Hi tech@,

Here is a diff to avoid calculating offset several times in rasops.c.
This was done for a few functions already, but not all of them.

Comments? OK?

Index: sys/dev/rasops/rasops.c
===
RCS file: /cvs/src/sys/dev/rasops/rasops.c,v
retrieving revision 1.42
diff -u -p -r1.42 rasops.c
--- sys/dev/rasops/rasops.c 7 Sep 2015 18:00:58 -   1.42
+++ sys/dev/rasops/rasops.c 21 Sep 2016 14:44:58 -
@@ -1577,8 +1577,10 @@ rasops_vcons_erasecols(void *cookie, int
int i;
 
for (i = 0; i < num; i++) {
-   scr->rs_bs[row * cols + col + i].uc = ' ';
-   scr->rs_bs[row * cols + col + i].attr = attr;
+   int off = row * cols + col + i;
+
+   scr->rs_bs[off].uc = ' ';
+   scr->rs_bs[off].attr = attr;
}
 
if (!scr->rs_visible)
@@ -1626,8 +1628,10 @@ rasops_vcons_eraserows(void *cookie, int
int i;
 
for (i = 0; i < num * cols; i++) {
-   scr->rs_bs[row * cols + i].uc = ' ';
-   scr->rs_bs[row * cols + i].attr = attr;
+   int off = row * cols + i;
+
+   scr->rs_bs[off].uc = ' ';
+   scr->rs_bs[off].attr = attr;
}
 
if (!scr->rs_visible)
@@ -1695,8 +1699,10 @@ rasops_wronly_erasecols(void *cookie, in
int i;
 
for (i = 0; i < num; i++) {
-   ri->ri_bs[row * cols + col + i].uc = ' ';
-   ri->ri_bs[row * cols + col + i].attr = attr;
+   int off = row * cols + col + i;
+
+   ri->ri_bs[off].uc = ' ';
+   ri->ri_bs[off].attr = attr;
}
 
return ri->ri_erasecols(ri, row, col, num, attr);
@@ -1734,8 +1740,10 @@ rasops_wronly_eraserows(void *cookie, in
int i;
 
for (i = 0; i < num * cols; i++) {
-   ri->ri_bs[row * cols + i].uc = ' ';
-   ri->ri_bs[row * cols + i].attr = attr;
+   int off = row * cols + i;
+
+   ri->ri_bs[off].uc = ' ';
+   ri->ri_bs[off].attr = attr;
}
 
return ri->ri_eraserows(ri, row, num, attr);