bc: shrink zbc_vm_stdin()

function                                             old     new   delta
bc_vm_run                                            592     534     -58

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2018-12-13 16:59:24 +01:00
parent 89e785af98
commit 40534bb6e2

View File

@ -758,6 +758,7 @@ struct globals {
# define G_exiting 0 # define G_exiting 0
#endif #endif
#define IS_BC (ENABLE_BC && (!ENABLE_DC || applet_name[0] == 'b')) #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 #if ENABLE_BC
@ -7070,27 +7071,28 @@ static BC_STATUS zbc_vm_stdin(void)
str -= 1; str -= 1;
else if (buf.v[0] == G.sbgn) else if (buf.v[0] == G.sbgn)
str += 1; str += 1;
} } else {
else if (len > 1 || comment) {
size_t i; size_t i;
for (i = 0; i < len; ++i) { for (i = 0; i < len; ++i) {
bool notend = len > i + 1;
char c = string[i]; char c = string[i];
if (i - 1 > len || string[i - 1] != '\\') { if (i - 1 > len || string[i - 1] != '\\') {
if (G.sbgn == G.send) // checking applet type is cheaper than accessing sbgn/send
str ^= c == G.sbgn; if (IS_DC) // dc: sbgn = send = '"'
else if (c == G.send) str ^= (c == '"');
str -= 1; else { // bc: sbgn = '[', send = ']'
else if (c == G.sbgn) if (c == ']')
str += 1; str -= 1;
else if (c == '[')
str += 1;
}
} }
if (c == '/' && notend && !comment && string[i + 1] == '*') { if (c == '/' && !comment && string[i + 1] == '*') {
comment = true; comment = true;
break; break;
} }
else if (c == '*' && notend && comment && string[i + 1] == '/') else if (c == '*' && comment && string[i + 1] == '/')
comment = false; comment = false;
} }