aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-12-21 21:36:58 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-12-21 21:36:58 +0100
commit00eb23b47aa79461b913b320eba3c95b90e6eec4 (patch)
treeebeb54dcc6eb977247f5088be9cffc4deaea27e9 /miscutils
parente4202df0918e13130bb511a4ce372cbbe089068d (diff)
downloadbusybox-00eb23b47aa79461b913b320eba3c95b90e6eec4.tar.gz
bc: do not allocate line editing state until needed
function old new delta xc_read_line 324 353 +29 free_line_input_t 34 39 +5 xc_vm_init 656 640 -16 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 34/-16) Total: 18 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/bc.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index f339b895c..1227e2d13 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -2545,6 +2545,8 @@ static void xc_read_line(BcVec *vec, FILE *fp)
# if ENABLE_FEATURE_EDITING
if (G_ttyin && fp == stdin) {
int n, i;
+ if (!G.line_input_state)
+ G.line_input_state = new_line_input_t(DO_HISTORY);
# define line_buf bb_common_bufsiz1
n = read_line_input(G.line_input_state, "", line_buf, COMMON_BUFSIZE);
if (n <= 0) { // read errors or EOF, or ^D, or ^C
@@ -6872,22 +6874,6 @@ static BC_STATUS zxc_program_exec(void)
}
#define zxc_program_exec(...) (zxc_program_exec(__VA_ARGS__) COMMA_SUCCESS)
-static unsigned xc_vm_envLen(const char *var)
-{
- char *lenv;
- unsigned len;
-
- lenv = getenv(var);
- len = BC_NUM_PRINT_WIDTH;
- if (!lenv) return len;
-
- len = bb_strtou(lenv, NULL, 10) - 1;
- if (errno || len < 2 || len >= INT_MAX)
- len = BC_NUM_PRINT_WIDTH;
-
- return len;
-}
-
static BC_STATUS zxc_vm_process(const char *text)
{
BcStatus s;
@@ -7377,12 +7363,25 @@ static void xc_program_init(void)
bc_char_vec_init(&G.input_buffer);
}
+static unsigned xc_vm_envLen(const char *var)
+{
+ char *lenv;
+ unsigned len;
+
+ lenv = getenv(var);
+ len = BC_NUM_PRINT_WIDTH;
+ if (!lenv) return len;
+
+ len = bb_strtou(lenv, NULL, 10) - 1;
+ if (errno || len < 2 || len >= INT_MAX)
+ len = BC_NUM_PRINT_WIDTH;
+
+ return len;
+}
+
static int xc_vm_init(const char *env_len)
{
G.prog.len = xc_vm_envLen(env_len);
-#if ENABLE_FEATURE_EDITING
- G.line_input_state = new_line_input_t(DO_HISTORY);
-#endif
bc_vec_init(&G.files, sizeof(char *), NULL);
xc_program_init();