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 <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
master
Ron Yorston 2024-04-06 09:50:42 +01:00 committed by Denys Vlasenko
parent e4b5ccd13b
commit 371fe9f71d
1 changed files with 8 additions and 9 deletions
shell

View File

@ -2327,9 +2327,11 @@ initvar(void)
} }
static struct var ** 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) { if (varcmp((*vpp)->var_text, name) == 0) {
break; break;
} }
@ -2345,7 +2347,7 @@ lookupvar(const char *name)
{ {
struct var *v; struct var *v;
v = *findvar(hashvar(name), name); v = *findvar(name);
if (v) { if (v) {
#if ENABLE_ASH_RANDOM_SUPPORT || BASH_EPOCH_VARS #if ENABLE_ASH_RANDOM_SUPPORT || BASH_EPOCH_VARS
/* /*
@ -2412,9 +2414,8 @@ setvareq(char *s, int flags)
{ {
struct var *vp, **vpp; struct var *vp, **vpp;
vpp = hashvar(s);
flags |= (VEXPORT & (((unsigned) (1 - aflag)) - 1)); flags |= (VEXPORT & (((unsigned) (1 - aflag)) - 1));
vpp = findvar(vpp, s); vpp = findvar(s);
vp = *vpp; vp = *vpp;
if (vp) { if (vp) {
if ((vp->flags & (VREADONLY|VDYNAMIC)) == VREADONLY) { if ((vp->flags & (VREADONLY|VDYNAMIC)) == VREADONLY) {
@ -9978,7 +9979,6 @@ static void
mklocal(char *name, int flags) mklocal(char *name, int flags)
{ {
struct localvar *lvp; struct localvar *lvp;
struct var **vpp;
struct var *vp; struct var *vp;
char *eq = strchr(name, '='); char *eq = strchr(name, '=');
@ -10007,8 +10007,7 @@ mklocal(char *name, int flags)
lvp->text = memcpy(p, optlist, sizeof(optlist)); lvp->text = memcpy(p, optlist, sizeof(optlist));
vp = NULL; vp = NULL;
} else { } else {
vpp = hashvar(name); vp = *findvar(name);
vp = *findvar(vpp, name);
if (vp == NULL) { if (vp == NULL) {
/* variable did not exist yet */ /* variable did not exist yet */
if (eq) if (eq)
@ -14156,7 +14155,7 @@ exportcmd(int argc UNUSED_PARAM, char **argv)
if (p != NULL) { if (p != NULL) {
p++; p++;
} else { } else {
vp = *findvar(hashvar(name), name); vp = *findvar(name);
if (vp) { if (vp) {
vp->flags = ((vp->flags | flag) & flag_off); vp->flags = ((vp->flags | flag) & flag_off);
continue; continue;