On Thu, Jan 05, 2017 at 05:13:24PM +0800, Michael W. Bombardieri wrote:

> Hi,
> 
> Two loops in yacc/lalr.c can be converted into memcpy().
> I quickly tested this on i386 and amd64 against rcs/date.y
> and the output matched y.tab.c of unpatched yacc.

Some remarks: 

1. use of magic nunber

2. You are assuming the layout of edge and nedge is the same. That is
the case , but I had to go look at the declaration and initialization
to decide that.

3. Is there an upstream we might want to be in-sync with?

Al in all I am not convinced this is worth it.

        -Otto

> 
> - Michael
> 
> 
> Index: lalr.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/yacc/lalr.c,v
> retrieving revision 1.18
> diff -u -p -u -r1.18 lalr.c
> --- lalr.c    11 Dec 2015 20:25:47 -0000      1.18
> +++ lalr.c    5 Jan 2017 08:56:11 -0000
> @@ -324,8 +324,7 @@ initialize_F(void)
>                       if (nedges) {
>                               reads[i] = rp = NEW2(nedges + 1, short);
>  
> -                             for (j = 0; j < nedges; j++)
> -                                     rp[j] = edge[j];
> +                             memcpy(rp, edge, nedges * 2);
>  
>                               rp[nedges] = -1;
>                               nedges = 0;
> @@ -403,8 +402,7 @@ build_relations(void)
>  
>               if (nedges) {
>                       includes[i] = shortp = NEW2(nedges + 1, short);
> -                     for (j = 0; j < nedges; j++)
> -                             shortp[j] = edge[j];
> +                     memcpy(shortp, edge, nedges * 2);
>                       shortp[nedges] = -1;
>               }
>       }

Reply via email to