git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] quote: use isalnum() to check for alphanumeric characters
@ 2020-02-22 18:51 René Scharfe
  2020-02-23  9:13 ` Martin Ågren
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2020-02-22 18:51 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano

isalnum(c) is equivalent to isalpha(c) || isdigit(c), so use the
former instead.  The result is shorter, simpler and slightly more
efficient.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 quote.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/quote.c b/quote.c
index 24a58ba454..bcc0dbc50d 100644
--- a/quote.c
+++ b/quote.c
@@ -55,7 +55,7 @@ void sq_quote_buf_pretty(struct strbuf *dst, const char *src)
 	}

 	for (p = src; *p; p++) {
-		if (!isalpha(*p) && !isdigit(*p) && !strchr(ok_punct, *p)) {
+		if (!isalnum(*p) && !strchr(ok_punct, *p)) {
 			sq_quote_buf(dst, src);
 			return;
 		}
--
2.25.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] quote: use isalnum() to check for alphanumeric characters
  2020-02-22 18:51 [PATCH] quote: use isalnum() to check for alphanumeric characters René Scharfe
@ 2020-02-23  9:13 ` Martin Ågren
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Ågren @ 2020-02-23  9:13 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git Mailing List, Junio C Hamano

On Sat, 22 Feb 2020 at 19:53, René Scharfe <l.s.r@web.de> wrote:
>
> isalnum(c) is equivalent to isalpha(c) || isdigit(c), so use the
> former instead.  The result is shorter, simpler and slightly more
> efficient.

From git-compat-util.h I can see that the claim about equivalence is
correct. And the efficiency claim, too. And agreed on "shorter and
simpler".

> --- a/quote.c
> +++ b/quote.c
> @@ -55,7 +55,7 @@ void sq_quote_buf_pretty(struct strbuf *dst, const char *src)
>         }
>
>         for (p = src; *p; p++) {
> -               if (!isalpha(*p) && !isdigit(*p) && !strchr(ok_punct, *p)) {
> +               if (!isalnum(*p) && !strchr(ok_punct, *p)) {

I failed to identify any similar constructs. Looks good to me.

Martin

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-02-23  9:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-22 18:51 [PATCH] quote: use isalnum() to check for alphanumeric characters René Scharfe
2020-02-23  9:13 ` Martin Ågren

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).