diff mbox series

var: move hashvar() calls into findvar()

Message ID 627a1f77.3CLq0J9mI6V6UePB%rmy@frippery.org (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series var: move hashvar() calls into findvar() | expand

Commit Message

Ron Yorston May 10, 2022, 8:16 a.m. UTC
The first argument to findvar() is always obtained by a call to
hashvar(), the return value of which is otherwise unused.

Signed-off-by: Ron Yorston <rmy@frippery.org>
---
 src/var.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

Comments

Herbert Xu April 5, 2024, 10:46 a.m. UTC | #1
On Tue, May 10, 2022 at 09:16:55AM +0100, Ron Yorston wrote:
> The first argument to findvar() is always obtained by a call to
> hashvar(), the return value of which is otherwise unused.
> 
> Signed-off-by: Ron Yorston <rmy@frippery.org>
> ---
>  src/var.c | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)

Nice work!

Patch applied.  Thanks.
diff mbox series

Patch

diff --git a/src/var.c b/src/var.c
index ef9c2bd..e301fe5 100644
--- a/src/var.c
+++ b/src/var.c
@@ -107,7 +107,7 @@  STATIC struct var *vartab[VTABSIZE];
 
 STATIC struct var **hashvar(const char *);
 STATIC int vpcmp(const void *, const void *);
-STATIC struct var **findvar(struct var **, const char *);
+STATIC struct var **findvar(const char *);
 
 /*
  * Initialize the varable symbol tables and import the environment
@@ -247,9 +247,8 @@  struct var *setvareq(char *s, int flags)
 {
 	struct var *vp, **vpp;
 
-	vpp = hashvar(s);
 	flags |= (VEXPORT & (((unsigned) (1 - aflag)) - 1));
-	vpp = findvar(vpp, s);
+	vpp = findvar(s);
 	vp = *vpp;
 	if (vp) {
 		if (vp->flags & VREADONLY) {
@@ -311,7 +310,7 @@  lookupvar(const char *name)
 {
 	struct var *v;
 
-	if ((v = *findvar(hashvar(name), name)) && !(v->flags & VUNSET)) {
+	if ((v = *findvar(name)) && !(v->flags & VUNSET)) {
 #ifdef WITH_LINENO
 		if (v == &vlineno && v->text == linenovar) {
 			fmtstr(linenovar+7, sizeof(linenovar)-7, "%d", lineno);
@@ -418,7 +417,7 @@  exportcmd(int argc, char **argv)
 			if ((p = strchr(name, '=')) != NULL) {
 				p++;
 			} else {
-				if ((vp = *findvar(hashvar(name), name))) {
+				if ((vp = *findvar(name))) {
 					vp->flags |= flag;
 					continue;
 				}
@@ -462,7 +461,6 @@  localcmd(int argc, char **argv)
 void mklocal(char *name, int flags)
 {
 	struct localvar *lvp;
-	struct var **vpp;
 	struct var *vp;
 
 	INTOFF;
@@ -475,8 +473,7 @@  void mklocal(char *name, int flags)
 	} else {
 		char *eq;
 
-		vpp = hashvar(name);
-		vp = *findvar(vpp, name);
+		vp = *findvar(name);
 		eq = strchr(name, '=');
 		if (vp == NULL) {
 			if (eq)
@@ -663,9 +660,11 @@  vpcmp(const void *a, const void *b)
 }
 
 STATIC struct var **
-findvar(struct var **vpp, const char *name)
+findvar(const char *name)
 {
-	for (; *vpp; vpp = &(*vpp)->next) {
+	struct var **vpp;
+
+	for (vpp = hashvar(name); *vpp; vpp = &(*vpp)->next) {
 		if (varequal((*vpp)->text, name)) {
 			break;
 		}