diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2023-06-15 09:19:48 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2023-06-15 09:19:48 +0200 |
commit | 3829d8b6758439251fc3e34dcedf5910d039b07d (patch) | |
tree | e7211316446e3916a7354ad26f378eefcf6f0d27 | |
parent | 2ff01bb699d80cb7d24a93e812cc91c54be5cc20 (diff) | |
download | busybox-w32-3829d8b6758439251fc3e34dcedf5910d039b07d.tar.gz busybox-w32-3829d8b6758439251fc3e34dcedf5910d039b07d.tar.bz2 busybox-w32-3829d8b6758439251fc3e34dcedf5910d039b07d.zip |
shell/math: simpler insertion of "fake" last RPAREN
Skip one pass through token table, since we know the result.
function old new delta
evaluate_string 1095 1097 +2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/math.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/shell/math.c b/shell/math.c index c1bf324f8..748c3b3ad 100644 --- a/shell/math.c +++ b/shell/math.c | |||
@@ -518,7 +518,7 @@ static const char op_tokens[] ALIGN1 = { | |||
518 | '(', 0, TOK_LPAREN, | 518 | '(', 0, TOK_LPAREN, |
519 | 0 | 519 | 0 |
520 | }; | 520 | }; |
521 | #define ptr_to_rparen (&op_tokens[sizeof(op_tokens)-7]) | 521 | #define END_POINTER (&op_tokens[sizeof(op_tokens)-1]) |
522 | 522 | ||
523 | #if ENABLE_FEATURE_SH_MATH_BASE | 523 | #if ENABLE_FEATURE_SH_MATH_BASE |
524 | static arith_t strto_arith_t(const char *nptr, char **endptr) | 524 | static arith_t strto_arith_t(const char *nptr, char **endptr) |
@@ -653,13 +653,13 @@ evaluate_string(arith_state_t *math_state, const char *expr) | |||
653 | * are to be applied in order. At the end, there should be a final | 653 | * are to be applied in order. At the end, there should be a final |
654 | * result on the integer stack */ | 654 | * result on the integer stack */ |
655 | 655 | ||
656 | if (expr != ptr_to_rparen + 1) { | 656 | if (expr != END_POINTER) { |
657 | /* If we haven't done so already, | 657 | /* If we haven't done so already, |
658 | * append a closing right paren | 658 | * append a closing right paren |
659 | * and let the loop process it */ | 659 | * and let the loop process it */ |
660 | expr = ptr_to_rparen; | 660 | expr = END_POINTER; |
661 | //bb_error_msg("expr=')'"); | 661 | op = TOK_RPAREN; |
662 | goto tok_find; | 662 | goto tok_found1; |
663 | } | 663 | } |
664 | /* At this point, we're done with the expression */ | 664 | /* At this point, we're done with the expression */ |
665 | if (numstackptr != numstack + 1) { | 665 | if (numstackptr != numstack + 1) { |
@@ -725,7 +725,7 @@ evaluate_string(arith_state_t *math_state, const char *expr) | |||
725 | } | 725 | } |
726 | } | 726 | } |
727 | } | 727 | } |
728 | tok_find: | 728 | |
729 | p = op_tokens; | 729 | p = op_tokens; |
730 | while (1) { | 730 | while (1) { |
731 | /* Compare expr to current op_tokens[] element */ | 731 | /* Compare expr to current op_tokens[] element */ |
@@ -792,7 +792,6 @@ evaluate_string(arith_state_t *math_state, const char *expr) | |||
792 | * "applied" in this way. | 792 | * "applied" in this way. |
793 | */ | 793 | */ |
794 | prec = PREC(op); | 794 | prec = PREC(op); |
795 | //bb_error_msg("prec:%02x", prec); | ||
796 | if ((prec > 0 && prec < UNARYPREC) || prec == SPEC_PREC) { | 795 | if ((prec > 0 && prec < UNARYPREC) || prec == SPEC_PREC) { |
797 | /* not left paren or unary */ | 796 | /* not left paren or unary */ |
798 | if (lasttok != TOK_NUM) { | 797 | if (lasttok != TOK_NUM) { |