shell/math: simplify handling of unary plus

function                                             old     new   delta
evaluate_string                                     1257    1271     +14
arith_apply                                          977     968      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-9)               Total: 5 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
master
Denys Vlasenko 2023-06-15 17:16:46 +02:00
parent 38f423cc9c
commit f8263528cd
1 changed files with 5 additions and 3 deletions

View File

@ -345,7 +345,7 @@ arith_apply(arith_state_t *math_state, operator op, var_or_num_t *numstack, var_
rez++; rez++;
else if (op == TOK_POST_DEC || op == TOK_PRE_DEC) else if (op == TOK_POST_DEC || op == TOK_PRE_DEC)
rez--; rez--;
else if (op != TOK_UPLUS) { else /*if (op != TOK_UPLUS) - always true, we drop TOK_UPLUS earlier */ {
/* Binary operators */ /* Binary operators */
arith_t right_side_val; arith_t right_side_val;
@ -770,8 +770,10 @@ evaluate_string(arith_state_t *math_state, const char *expr)
if (lasttok != TOK_NUM) { if (lasttok != TOK_NUM) {
switch (op) { switch (op) {
case TOK_ADD: case TOK_ADD:
op = TOK_UPLUS; //op = TOK_UPLUS;
break; //break;
/* Unary plus does nothing, do not even push it to opstack */
continue;
case TOK_SUB: case TOK_SUB:
op = TOK_UMINUS; op = TOK_UMINUS;
break; break;