aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-13 16:59:24 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-13 17:27:00 +0100
commit40534bb6e2910a931ae77f0275b048f62896e2a7 (patch)
treefb17fb66e8bc7a815749ff9f961c628eeba74d3c /miscutils
parent89e785af98acb71ae495c76e1f1cf4944431a3db (diff)
downloadbusybox-40534bb6e2910a931ae77f0275b048f62896e2a7.tar.gz
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.c24
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 {
# define G_exiting 0
#endif
#define IS_BC (ENABLE_BC && (!ENABLE_DC || applet_name[0] == 'b'))
+#define IS_DC (ENABLE_DC && (!ENABLE_BC || applet_name[0] != 'b'))
#if ENABLE_BC
@@ -7070,27 +7071,28 @@ static BC_STATUS zbc_vm_stdin(void)
str -= 1;
else if (buf.v[0] == G.sbgn)
str += 1;
- }
- else if (len > 1 || comment) {
+ } else {
size_t i;
for (i = 0; i < len; ++i) {
- bool notend = len > i + 1;
char c = string[i];
if (i - 1 > len || string[i - 1] != '\\') {
- if (G.sbgn == G.send)
- str ^= c == G.sbgn;
- else if (c == G.send)
- str -= 1;
- else if (c == G.sbgn)
- str += 1;
+ // checking applet type is cheaper than accessing sbgn/send
+ if (IS_DC) // dc: sbgn = send = '"'
+ str ^= (c == '"');
+ else { // bc: sbgn = '[', send = ']'
+ if (c == ']')
+ str -= 1;
+ else if (c == '[')
+ str += 1;
+ }
}
- if (c == '/' && notend && !comment && string[i + 1] == '*') {
+ if (c == '/' && !comment && string[i + 1] == '*') {
comment = true;
break;
}
- else if (c == '*' && notend && comment && string[i + 1] == '/')
+ else if (c == '*' && comment && string[i + 1] == '/')
comment = false;
}