diff options
author | Ron Yorston <rmy@pobox.com> | 2023-04-13 08:18:53 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-04-13 08:47:36 +0100 |
commit | 5b309426f3a2f4f9dfda29021e45a775a4995003 (patch) | |
tree | aaf18499d8f1afc8b7f320b11e0c4202b8f966ea | |
parent | 36450cffc837bf934f875643bf5faca69599d8fe (diff) | |
download | busybox-w32-tab_completion.tar.gz busybox-w32-tab_completion.tar.bz2 busybox-w32-tab_completion.zip |
hush: code shrinktab_completion
Handle both arrays of builtin as the same type.
function old new delta
ash_command_name - 154 +154
hush_command_name - 97 +97
complete_cmd_dir_file 876 880 +4
ash_builtin_name 17 - -17
hush_builtin_name 38 - -38
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 1/0 up/down: 255/-55) Total: 200 bytes
In the case where ash is disabled and hush is enabled but with support
for functions disabled this reduces the bloat from 31 to 6 bytes.
(GitHub issue #301)
Signed-off-by: Ron Yorston <rmy@pobox.com>
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | libbb/lineedit.c | 2 | ||||
-rw-r--r-- | shell/hush.c | 16 |
3 files changed, 9 insertions, 11 deletions
diff --git a/include/libbb.h b/include/libbb.h index 66781da4f..f4fc10325 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1925,9 +1925,9 @@ unsigned size_from_HISTFILESIZE(const char *hp) FAST_FUNC; | |||
1925 | # define MAX_HISTORY 0 | 1925 | # define MAX_HISTORY 0 |
1926 | # endif | 1926 | # endif |
1927 | typedef struct exe_state { | 1927 | typedef struct exe_state { |
1928 | int e_type; /* type of tab completion: builtin, alias, function */ | ||
1929 | int e_index; /* index of current table entry or hash bucket */ | 1928 | int e_index; /* index of current table entry or hash bucket */ |
1930 | # if ENABLE_SHELL_ASH || (ENABLE_SHELL_HUSH && ENABLE_HUSH_FUNCTIONS) | 1929 | # if ENABLE_SHELL_ASH || (ENABLE_SHELL_HUSH && ENABLE_HUSH_FUNCTIONS) |
1930 | int e_type; /* type of tab completion: builtin, alias, function */ | ||
1931 | void *e_ptr; /* current position in linked list */ | 1931 | void *e_ptr; /* current position in linked list */ |
1932 | # endif | 1932 | # endif |
1933 | } exe_state; | 1933 | } exe_state; |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 5daceff16..d3882b33f 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -878,7 +878,7 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type) | |||
878 | # if ENABLE_SHELL_ASH || (ENABLE_SHELL_HUSH && ENABLE_HUSH_FUNCTIONS) | 878 | # if ENABLE_SHELL_ASH || (ENABLE_SHELL_HUSH && ENABLE_HUSH_FUNCTIONS) |
879 | exe_state e = { 0, 0, NULL }; | 879 | exe_state e = { 0, 0, NULL }; |
880 | # else | 880 | # else |
881 | exe_state e = { 0, 0 }; | 881 | exe_state e = { 0 }; |
882 | # endif | 882 | # endif |
883 | for (;;) { | 883 | for (;;) { |
884 | const char *b = state->get_exe_name(&e); | 884 | const char *b = state->get_exe_name(&e); |
diff --git a/shell/hush.c b/shell/hush.c index 04633ab2d..12c32ce6e 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -8222,31 +8222,29 @@ static const struct built_in_command *find_builtin(const char *name) | |||
8222 | #if ENABLE_HUSH_JOB && ENABLE_FEATURE_TAB_COMPLETION | 8222 | #if ENABLE_HUSH_JOB && ENABLE_FEATURE_TAB_COMPLETION |
8223 | static const char * FAST_FUNC hush_command_name(exe_state *e) | 8223 | static const char * FAST_FUNC hush_command_name(exe_state *e) |
8224 | { | 8224 | { |
8225 | # if ENABLE_HUSH_FUNCTIONS | ||
8225 | switch (e->e_type) { | 8226 | switch (e->e_type) { |
8226 | case 0: | 8227 | case 0: |
8228 | # endif | ||
8227 | if (e->e_index < ARRAY_SIZE(bltins1)) | 8229 | if (e->e_index < ARRAY_SIZE(bltins1)) |
8228 | return bltins1[e->e_index++].b_cmd; | 8230 | return bltins1[e->e_index++].b_cmd; |
8229 | e->e_type++; | 8231 | if (e->e_index < ARRAY_SIZE(bltins1) + ARRAY_SIZE(bltins2)) |
8230 | e->e_index = 0; | 8232 | return bltins2[e->e_index++ - ARRAY_SIZE(bltins1)].b_cmd; |
8231 | /* e->e_ptr = NULL; */ | ||
8232 | /* fall through */ | ||
8233 | case 1: | ||
8234 | if (e->e_index < ARRAY_SIZE(bltins2)) | ||
8235 | return bltins2[e->e_index++].b_cmd; | ||
8236 | # if ENABLE_HUSH_FUNCTIONS | 8233 | # if ENABLE_HUSH_FUNCTIONS |
8234 | /* fall through */ | ||
8237 | e->e_type++; | 8235 | e->e_type++; |
8238 | /* e->e_index = 0; */ | 8236 | /* e->e_index = 0; */ |
8239 | e->e_ptr = G.top_func; | 8237 | e->e_ptr = G.top_func; |
8240 | /* fall through */ | 8238 | /* fall through */ |
8241 | case 2: | 8239 | case 1: |
8242 | if (e->e_ptr) { | 8240 | if (e->e_ptr) { |
8243 | struct function *funcp = (struct function *)e->e_ptr; | 8241 | struct function *funcp = (struct function *)e->e_ptr; |
8244 | e->e_ptr = funcp->next; | 8242 | e->e_ptr = funcp->next; |
8245 | return funcp->name; | 8243 | return funcp->name; |
8246 | } | 8244 | } |
8247 | # endif | ||
8248 | break; | 8245 | break; |
8249 | } | 8246 | } |
8247 | # endif | ||
8250 | return NULL; | 8248 | return NULL; |
8251 | } | 8249 | } |
8252 | #endif | 8250 | #endif |