diff options
author | Denys Vlasenko | 2023-06-29 11:01:50 +0200 |
---|---|---|
committer | Denys Vlasenko | 2023-06-29 11:01:50 +0200 |
commit | 6a0ba673820cb6880e2f93f739de7d16d45d2b26 (patch) | |
tree | a34deefba58982730214d3359475cf74186a7065 | |
parent | 800207b90a4f5f78cbe65a0f4b3ecd3b93abbd7d (diff) | |
download | busybox-6a0ba673820cb6880e2f93f739de7d16d45d2b26.zip busybox-6a0ba673820cb6880e2f93f739de7d16d45d2b26.tar.gz |
shell/math: code shrink
function old new delta
arith_apply 1023 996 -27
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/math.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/shell/math.c b/shell/math.c index e15b014..5b99670 100644 --- a/shell/math.c +++ b/shell/math.c @@ -313,8 +313,10 @@ arith_lookup_val(arith_state_t *math_state, const char *name, char *endname) } /* "Applying" a token means performing it on the top elements on the integer - * stack. For an unary operator it will only change the top element, but a - * binary operator will pop two arguments and push the result */ + * stack. For an unary operator it will only change the top element, + * a binary operator will pop two arguments and push the result, + * the ternary ?: op will pop three arguments and push the result. + */ static NOINLINE const char* arith_apply(arith_state_t *math_state, operator op, var_or_num_t *numstack, var_or_num_t **numstackptr) { @@ -337,9 +339,9 @@ arith_apply(arith_state_t *math_state, operator op, var_or_num_t *numstack, var_ return "malformed ?: operator"; if (expr1->val != 0) /* select expr2 or expr3 */ top_of_stack--; - expr1->val = top_of_stack->val; - expr1->var_name = NULL; - return NULL; + rez = top_of_stack->val; + top_of_stack = expr1; + goto ret_rez; } if (op == TOK_CONDITIONAL) /* Example: $((a ? b)) */ return "malformed ?: operator"; @@ -469,13 +471,13 @@ arith_apply(arith_state_t *math_state, operator op, var_or_num_t *numstack, var_ math_state->setvar(top_of_stack->var_name, buf); *e = c; } - /* After saving, make previous value for v++ or v-- */ - if (op == TOK_POST_INC) - rez--; - if (op == TOK_POST_DEC) - rez++; + /* VAR++ or VAR--? */ + if (PREC(op) == PREC_POST) { + /* Do not store new value to stack (keep old value) */ + goto ret_NULL; + } } - + ret_rez: top_of_stack->val = rez; ret_NULL: /* Erase var name, it is just a number now */ |