[git commit] shell/math: simpler insertion of "fake" last RPAREN
Denys Vlasenko
vda.linux at googlemail.com
Thu Jun 15 07:19:48 UTC 2023
commit: https://git.busybox.net/busybox/commit/?id=3829d8b6758439251fc3e34dcedf5910d039b07d
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
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 at googlemail.com>
---
shell/math.c | 13 ++++++-------
1 file 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 = {
'(', 0, TOK_LPAREN,
0
};
-#define ptr_to_rparen (&op_tokens[sizeof(op_tokens)-7])
+#define END_POINTER (&op_tokens[sizeof(op_tokens)-1])
#if ENABLE_FEATURE_SH_MATH_BASE
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)
* are to be applied in order. At the end, there should be a final
* result on the integer stack */
- if (expr != ptr_to_rparen + 1) {
+ if (expr != END_POINTER) {
/* If we haven't done so already,
* append a closing right paren
* and let the loop process it */
- expr = ptr_to_rparen;
-//bb_error_msg("expr=')'");
- goto tok_find;
+ expr = END_POINTER;
+ op = TOK_RPAREN;
+ goto tok_found1;
}
/* At this point, we're done with the expression */
if (numstackptr != numstack + 1) {
@@ -725,7 +725,7 @@ evaluate_string(arith_state_t *math_state, const char *expr)
}
}
}
- tok_find:
+
p = op_tokens;
while (1) {
/* Compare expr to current op_tokens[] element */
@@ -792,7 +792,6 @@ evaluate_string(arith_state_t *math_state, const char *expr)
* "applied" in this way.
*/
prec = PREC(op);
-//bb_error_msg("prec:%02x", prec);
if ((prec > 0 && prec < UNARYPREC) || prec == SPEC_PREC) {
/* not left paren or unary */
if (lasttok != TOK_NUM) {
More information about the busybox-cvs
mailing list