git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / 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
Message-ID: <xmqqo8ymenep.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20191011184123.17376-1-dev+git@drbeat.li>

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 index

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-11 18:24 [PATCH] " 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 publically 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

  List information: http://vger.kernel.org/majordomo-info.html

* 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

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox