All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Beat Bolli <dev+git@drbeat.li>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2] utf8: use ARRAY_SIZE() in git_wcwidth()
Date: Sat, 12 Oct 2019 10:57:18 +0900	[thread overview]
Message-ID: <xmqqo8ymenep.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20191011184123.17376-1-dev+git@drbeat.li> (Beat Bolli's message of "Fri, 11 Oct 2019 20:41:23 +0200")

Beat Bolli <dev+git@drbeat.li> writes:

> diff --git a/utf8.c b/utf8.c
> index 3b42fadffd..5c8f151f75 100644
> --- a/utf8.c
> +++ b/utf8.c
> @@ -95,13 +95,11 @@ static int git_wcwidth(ucs_char_t ch)
>  		return -1;
>  
>  	/* binary search in table of non-spacing characters */
> -	if (bisearch(ch, zero_width, sizeof(zero_width)
> -				/ sizeof(struct interval) - 1))
> +	if (bisearch(ch, zero_width, ARRAY_SIZE(zero_width) - 1))

I wondered if we want a wrapper similar to QSORT() macro so that we
do not have to repeat zero_width (and double_width below) like this,
but bisearch() itself is local to this file and there are only these
two callers, so it probably is not worth it.

The original is waiting for a bug when zero_width changes its type,
by not dividing with sizeof(*zero_width).  The use of ARRAY_SIZE()
is quite appropriate here.

Thanks.

>  		return 0;
>  
>  	/* binary search in table of double width characters */
> -	if (bisearch(ch, double_width, sizeof(double_width)
> -				/ sizeof(struct interval) - 1))
> +	if (bisearch(ch, double_width, ARRAY_SIZE(double_width) - 1))
>  		return 2;
>  
>  	return 1;

      reply	other threads:[~2019-10-12  1:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-11 18:24 [PATCH] utf8: use ARRAY_SIZE() in git_wcwidth() Beat Bolli
2019-10-11 18:41 ` [PATCH v2] " Beat Bolli
2019-10-12  1:57   ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqo8ymenep.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=dev+git@drbeat.li \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.