Re: [PATCH v4 2/3] json: Change `if (!strlen(str))` to `if (!str[0])`

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

 



On 5/12/22 10:43, Ammar Faizi wrote:
> No need to traverse the whole string. Using `!strlen(str)` as a
> *conditional expression* is effectively the same with `!str[0]`.
> 
> Reviewed-by: Niklas Cassel <niklas.cassel@xxxxxxx>
> Signed-off-by: Ammar Faizi <ammarfaizi2@xxxxxxxxxxx>
> ---
>  json.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/json.c b/json.c
> index cd3d5d74..8b650721 100644
> --- a/json.c
> +++ b/json.c
> @@ -56,7 +56,7 @@ static char *strdup_escape(const char *str)
>  	char *p, *ret;
>  	int escapes;
>  
> -	if (!strlen(str))
> +	if (!str[0])
>  		return NULL;

This seems like a useless optimization, strlen() should already be
doing this.

-- 
Jens Axboe




[Index of Archives]     [Linux Kernel]     [Linux SCSI]     [Linux IDE]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux