summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2010-09-13 01:09:11 +0200
committerDenys Vlasenko2010-09-13 01:09:11 +0200
commit51850c818cf909cde0e07091a8015532cc645b7a (patch)
tree2f7da57ee250bb92d2a57ed6ff38fc3ca5fc7436
parentb771c654cab511b172484479cafd006d52588103 (diff)
downloadbusybox-51850c818cf909cde0e07091a8015532cc645b7a.zip
busybox-51850c818cf909cde0e07091a8015532cc645b7a.tar.gz
shell: small code shrink
function old new delta arith 680 675 -5 Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r--shell/math.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/shell/math.c b/shell/math.c
index 2f09339..c698a44 100644
--- a/shell/math.c
+++ b/shell/math.c
@@ -635,28 +635,29 @@ arith(const char *expr, int *perrcode, a_e_h_t *math_hooks)
goto err;
}
while (stackptr != stack) {
+ operator prev_op = *--stackptr;
if (op == TOK_RPAREN) {
/* The algorithm employed here is simple: while we don't
* hit an open paren nor the bottom of the stack, pop
* tokens and apply them */
- if (stackptr[-1] == TOK_LPAREN) {
- --stackptr;
+ if (prev_op == TOK_LPAREN) {
/* Any operator directly after a */
lasttok = TOK_NUM;
/* close paren should consider itself binary */
goto next;
}
} else {
- operator prev_prec = PREC(stackptr[-1]);
+ operator prev_prec = PREC(prev_op);
convert_prec_is_assign(prec);
convert_prec_is_assign(prev_prec);
- if (prev_prec < prec)
- break;
- /* check right assoc */
- if (prev_prec == prec && is_right_associativity(prec))
+ if (prev_prec < prec
+ || (prev_prec == prec && is_right_associativity(prec))
+ ) {
+ stackptr++;
break;
+ }
}
- errcode = arith_apply(*--stackptr, numstack, &numstackptr, math_hooks);
+ errcode = arith_apply(prev_op, numstack, &numstackptr, math_hooks);
if (errcode)
goto ret;
}