diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-13 16:59:24 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-13 17:27:00 +0100 |
| commit | 40534bb6e2910a931ae77f0275b048f62896e2a7 (patch) | |
| tree | fb17fb66e8bc7a815749ff9f961c628eeba74d3c /miscutils | |
| parent | 89e785af98acb71ae495c76e1f1cf4944431a3db (diff) | |
| download | busybox-w32-40534bb6e2910a931ae77f0275b048f62896e2a7.tar.gz busybox-w32-40534bb6e2910a931ae77f0275b048f62896e2a7.tar.bz2 busybox-w32-40534bb6e2910a931ae77f0275b048f62896e2a7.zip | |
bc: shrink zbc_vm_stdin()
function old new delta
bc_vm_run 592 534 -58
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/bc.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 47acd7fc3..7ab320a4d 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
| @@ -758,6 +758,7 @@ struct globals { | |||
| 758 | # define G_exiting 0 | 758 | # define G_exiting 0 |
| 759 | #endif | 759 | #endif |
| 760 | #define IS_BC (ENABLE_BC && (!ENABLE_DC || applet_name[0] == 'b')) | 760 | #define IS_BC (ENABLE_BC && (!ENABLE_DC || applet_name[0] == 'b')) |
| 761 | #define IS_DC (ENABLE_DC && (!ENABLE_BC || applet_name[0] != 'b')) | ||
| 761 | 762 | ||
| 762 | #if ENABLE_BC | 763 | #if ENABLE_BC |
| 763 | 764 | ||
| @@ -7070,27 +7071,28 @@ static BC_STATUS zbc_vm_stdin(void) | |||
| 7070 | str -= 1; | 7071 | str -= 1; |
| 7071 | else if (buf.v[0] == G.sbgn) | 7072 | else if (buf.v[0] == G.sbgn) |
| 7072 | str += 1; | 7073 | str += 1; |
| 7073 | } | 7074 | } else { |
| 7074 | else if (len > 1 || comment) { | ||
| 7075 | size_t i; | 7075 | size_t i; |
| 7076 | for (i = 0; i < len; ++i) { | 7076 | for (i = 0; i < len; ++i) { |
| 7077 | bool notend = len > i + 1; | ||
| 7078 | char c = string[i]; | 7077 | char c = string[i]; |
| 7079 | 7078 | ||
| 7080 | if (i - 1 > len || string[i - 1] != '\\') { | 7079 | if (i - 1 > len || string[i - 1] != '\\') { |
| 7081 | if (G.sbgn == G.send) | 7080 | // checking applet type is cheaper than accessing sbgn/send |
| 7082 | str ^= c == G.sbgn; | 7081 | if (IS_DC) // dc: sbgn = send = '"' |
| 7083 | else if (c == G.send) | 7082 | str ^= (c == '"'); |
| 7084 | str -= 1; | 7083 | else { // bc: sbgn = '[', send = ']' |
| 7085 | else if (c == G.sbgn) | 7084 | if (c == ']') |
| 7086 | str += 1; | 7085 | str -= 1; |
| 7086 | else if (c == '[') | ||
| 7087 | str += 1; | ||
| 7088 | } | ||
| 7087 | } | 7089 | } |
| 7088 | 7090 | ||
| 7089 | if (c == '/' && notend && !comment && string[i + 1] == '*') { | 7091 | if (c == '/' && !comment && string[i + 1] == '*') { |
| 7090 | comment = true; | 7092 | comment = true; |
| 7091 | break; | 7093 | break; |
| 7092 | } | 7094 | } |
| 7093 | else if (c == '*' && notend && comment && string[i + 1] == '/') | 7095 | else if (c == '*' && comment && string[i + 1] == '/') |
| 7094 | comment = false; | 7096 | comment = false; |
| 7095 | } | 7097 | } |
| 7096 | 7098 | ||
