From 371fe9f71d445d18be28c82a2a6d82115c8af19d Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 6 Apr 2024 09:50:42 +0100 Subject: ash: move hashvar() calls into findvar() dash has accepted a patch to remove the first argument of findvar(). It's commit e85e972 (var: move hashvar() calls into findvar()). Apply the same change to BusyBox ash. function old new delta findvar 35 40 +5 mklocal 268 261 -7 exportcmd 164 157 -7 setvareq 319 310 -9 lookupvar 150 141 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/4 up/down: 5/-32) Total: -27 bytes Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- shell/ash.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index 9da3e956a..bbd730770 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -2327,9 +2327,11 @@ initvar(void) } 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 (varcmp((*vpp)->var_text, name) == 0) { break; } @@ -2345,7 +2347,7 @@ lookupvar(const char *name) { struct var *v; - v = *findvar(hashvar(name), name); + v = *findvar(name); if (v) { #if ENABLE_ASH_RANDOM_SUPPORT || BASH_EPOCH_VARS /* @@ -2412,9 +2414,8 @@ 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|VDYNAMIC)) == VREADONLY) { @@ -9978,7 +9979,6 @@ static void mklocal(char *name, int flags) { struct localvar *lvp; - struct var **vpp; struct var *vp; char *eq = strchr(name, '='); @@ -10007,8 +10007,7 @@ mklocal(char *name, int flags) lvp->text = memcpy(p, optlist, sizeof(optlist)); vp = NULL; } else { - vpp = hashvar(name); - vp = *findvar(vpp, name); + vp = *findvar(name); if (vp == NULL) { /* variable did not exist yet */ if (eq) @@ -14156,7 +14155,7 @@ exportcmd(int argc UNUSED_PARAM, char **argv) if (p != NULL) { p++; } else { - vp = *findvar(hashvar(name), name); + vp = *findvar(name); if (vp) { vp->flags = ((vp->flags | flag) & flag_off); continue; -- cgit v1.2.3-55-g6feb