Re: [PATCH] Simplify the code and avoid an attribution.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Nov 21, 2007 at 11:00:02PM -0200, André Goddard Rosa wrote:
> --- a/config.c
> +++ b/config.c
> @@ -447,15 +447,16 @@ int git_config_from_file(config_fn_t fn, const
> char *filename)
>  	int ret;
>  	FILE *f = fopen(filename, "r");
> 
> -	ret = -1;
> -	if (f) {
> -		config_file = f;
> -		config_file_name = filename;
> -		config_linenr = 1;
> -		ret = git_parse_file(fn);
> -		fclose(f);
> -		config_file_name = NULL;
> -	}
> +	if (!f)
> +		return -1;
> +
> +	config_file = f;
> +	config_file_name = filename;
> +	config_linenr = 1;
> +	ret = git_parse_file(fn);
> +	fclose(f);
> +	config_file_name = NULL;
> +
>  	return ret;
>  }

Actually, since it is more likely that the file has been opened, the
original code is more optimal because it doesn't generate a jump in most
cases. And if you're worried about the ret variable, don't worry, it's
most likely stripped out by the compiler optimizations.

> -	if (f == NULL)
> +	if (!f)

> -	if ((f = fopen(filename, "rb")) == NULL)
> +	if (!(f = fopen(filename, "rb")))

It's a matter of taste

Mike

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux