"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Christian Weisgerber <naddy@mips.inka.de>
Subject:
Re: diff: limit search effort for function prototypes
To:
gameoftrees@openbsd.org
Date:
Wed, 9 Dec 2020 22:45:52 +0100

Download raw body.

Thread
Stefan Sperling:

> > GNU diff caches the last function prototype and the line number
> > from which it started searching.
> 
> Yes, we could. This is a great idea. Implemented below. This approach
> is also much faster than my previous patch.
> 
> So with this diff we only search the 'left' version of the file for
> prototypes. But that's probably how other diff tools do it as well.

Yes, GNU diff does this as well.

> ok?

Basically, yes.

That's a malloc/free for each prototype.  Would a static buffer in
the state be better?

> --- lib/diff_output_unidiff.c
> +++ lib/diff_output_unidiff.c
>  	if (left_len == 1 && right_len == 1) {
>  		rc = fprintf(dest, "@@ -%d +%d @@%s%s\n",
>  			left_start, right_start,
> -			prototype ? " " : "",
> -			prototype ? : "");
> +			state->prototype ? " " : "",
> +			state->prototype ? : "");

That is not C.  I had to look it up: "x ? : y" is a GCC extension.
Something for a separate clean-up commit, I guess.

-- 
Christian "naddy" Weisgerber                          naddy@mips.inka.de