Module Name: src
Committed By: rillig
Date: Sun Sep 13 08:11:40 UTC 2020
Modified Files:
src/usr.bin/make: var.c
Log Message:
make(1): inline call to strchr in ValidShortVarname
It's a pity that neither GCC 5 nor GCC 10 nor Clang 9 inline this code
themselves, even though it would be easy to do.
Clang 9 at least replaces strchr with memchr, but that is still too
complicated for a simple "is this character one of these" question.
For a repeated "if (varname != ...)" instead of the switch, GCC 10
generates really boring and inefficient code, even though it is easy to
see that the order of the comparisons doesn't matter.
To generate a diff of this commit:
cvs rdiff -u -r1.507 -r1.508 src/usr.bin/make/var.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.507 src/usr.bin/make/var.c:1.508
--- src/usr.bin/make/var.c:1.507 Sun Sep 13 07:42:20 2020
+++ src/usr.bin/make/var.c Sun Sep 13 08:11:40 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.507 2020/09/13 07:42:20 rillig Exp $ */
+/* $NetBSD: var.c,v 1.508 2020/09/13 08:11:40 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.507 2020/09/13 07:42:20 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.508 2020/09/13 08:11:40 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: var.c,v 1.507 2020/09/13 07:42:20 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.508 2020/09/13 08:11:40 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -3372,8 +3372,16 @@ ParseVarname(const char **pp, char start
static Boolean
ValidShortVarname(char varname, const char *start)
{
- if (varname != '\0' && strchr(")}:$", varname) == NULL)
- return TRUE;
+ switch (varname) {
+ case '\0':
+ case ')':
+ case '}':
+ case ':':
+ case '$':
+ break;
+ default:
+ return TRUE;
+ }
if (!DEBUG(LINT))
return FALSE;