[PATCH] ash: move hashvar() calls into findvar()
Denys Vlasenko
vda.linux at googlemail.com
Sat Jul 13 23:13:24 UTC 2024
Applied, thank you
On Sat, Apr 6, 2024 at 10:50 AM Ron Yorston <rmy at pobox.com> wrote:
>
> 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 at pobox.com>
> ---
> shell/ash.c | 17 ++++++++---------
> 1 file changed, 8 insertions(+), 9 deletions(-)
>
> diff --git a/shell/ash.c b/shell/ash.c
> index 4ca4c6c56..8195bfca3 100644
> --- a/shell/ash.c
> +++ b/shell/ash.c
> @@ -2328,9 +2328,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;
> }
> @@ -2346,7 +2348,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
> /*
> @@ -2413,9 +2415,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) {
> @@ -9967,7 +9968,6 @@ static void
> mklocal(char *name, int flags)
> {
> struct localvar *lvp;
> - struct var **vpp;
> struct var *vp;
> char *eq = strchr(name, '=');
>
> @@ -9996,8 +9996,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)
> @@ -14138,7 +14137,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;
> --
> 2.44.0
>
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
More information about the busybox
mailing list