aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2023-06-29 11:01:50 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2023-06-29 11:01:50 +0200
commit6a0ba673820cb6880e2f93f739de7d16d45d2b26 (patch)
treea34deefba58982730214d3359475cf74186a7065
parent800207b90a4f5f78cbe65a0f4b3ecd3b93abbd7d (diff)
downloadbusybox-w32-6a0ba673820cb6880e2f93f739de7d16d45d2b26.tar.gz
busybox-w32-6a0ba673820cb6880e2f93f739de7d16d45d2b26.tar.bz2
busybox-w32-6a0ba673820cb6880e2f93f739de7d16d45d2b26.zip
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.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/shell/math.c b/shell/math.c
index e15b014aa..5b996703e 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)
313} 313}
314 314
315/* "Applying" a token means performing it on the top elements on the integer 315/* "Applying" a token means performing it on the top elements on the integer
316 * stack. For an unary operator it will only change the top element, but a 316 * stack. For an unary operator it will only change the top element,
317 * binary operator will pop two arguments and push the result */ 317 * a binary operator will pop two arguments and push the result,
318 * the ternary ?: op will pop three arguments and push the result.
319 */
318static NOINLINE const char* 320static NOINLINE const char*
319arith_apply(arith_state_t *math_state, operator op, var_or_num_t *numstack, var_or_num_t **numstackptr) 321arith_apply(arith_state_t *math_state, operator op, var_or_num_t *numstack, var_or_num_t **numstackptr)
320{ 322{
@@ -337,9 +339,9 @@ arith_apply(arith_state_t *math_state, operator op, var_or_num_t *numstack, var_
337 return "malformed ?: operator"; 339 return "malformed ?: operator";
338 if (expr1->val != 0) /* select expr2 or expr3 */ 340 if (expr1->val != 0) /* select expr2 or expr3 */
339 top_of_stack--; 341 top_of_stack--;
340 expr1->val = top_of_stack->val; 342 rez = top_of_stack->val;
341 expr1->var_name = NULL; 343 top_of_stack = expr1;
342 return NULL; 344 goto ret_rez;
343 } 345 }
344 if (op == TOK_CONDITIONAL) /* Example: $((a ? b)) */ 346 if (op == TOK_CONDITIONAL) /* Example: $((a ? b)) */
345 return "malformed ?: operator"; 347 return "malformed ?: operator";
@@ -469,13 +471,13 @@ arith_apply(arith_state_t *math_state, operator op, var_or_num_t *numstack, var_
469 math_state->setvar(top_of_stack->var_name, buf); 471 math_state->setvar(top_of_stack->var_name, buf);
470 *e = c; 472 *e = c;
471 } 473 }
472 /* After saving, make previous value for v++ or v-- */ 474 /* VAR++ or VAR--? */
473 if (op == TOK_POST_INC) 475 if (PREC(op) == PREC_POST) {
474 rez--; 476 /* Do not store new value to stack (keep old value) */
475 if (op == TOK_POST_DEC) 477 goto ret_NULL;
476 rez++; 478 }
477 } 479 }
478 480 ret_rez:
479 top_of_stack->val = rez; 481 top_of_stack->val = rez;
480 ret_NULL: 482 ret_NULL:
481 /* Erase var name, it is just a number now */ 483 /* Erase var name, it is just a number now */