summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2023-04-01 22:36:30 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2023-04-01 22:52:08 +0200
commitfd5fb2d2b59640910addf5c946a39d4cc5c09003 (patch)
tree91e31dd01ed21f2ff31cf6e35d70322eac6d3bc4
parent1409432d072e62c3838ef2e86b0d97637201dbd5 (diff)
downloadbusybox-fd5fb2d2b59640910addf5c946a39d4cc5c09003.tar.gz
hush: speed up "big heredoc" code
function old new delta hush_main 1810 1815 +5 .rodata 102723 102721 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 5/-2) Total: 3 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/hush.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/shell/hush.c b/shell/hush.c
index e42de8762..170edf415 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -10260,6 +10260,20 @@ int hush_main(int argc, char **argv)
INIT_G();
if (EXIT_SUCCESS != 0) /* if EXIT_SUCCESS == 0, it is already done */
G.last_exitcode = EXIT_SUCCESS;
+#if !BB_MMU
+ /* "Big heredoc" support via "sh -< STRING" invocation.
+ * Check it first (do not bother to run the usual init code,
+ * it is not needed for this case).
+ */
+ if (argv[1]
+ && argv[1][0] == '-' && argv[1][1] == '<' /*&& !argv[1][2]*/
+ /*&& argv[2] && !argv[3] - we don't check some conditions */
+ ) {
+ full_write1_str(argv[2]);
+ _exit(0);
+ }
+ G.argv0_for_re_execing = argv[0];
+#endif
#if ENABLE_HUSH_TRAP
# if ENABLE_HUSH_FUNCTIONS
G.return_exitcode = -1;
@@ -10270,9 +10284,6 @@ int hush_main(int argc, char **argv)
#if ENABLE_HUSH_FAST
G.count_SIGCHLD++; /* ensure it is != G.handled_SIGCHLD */
#endif
-#if !BB_MMU
- G.argv0_for_re_execing = argv[0];
-#endif
cached_getpid = getpid(); /* for tcsetpgrp() during init */
G.root_pid = cached_getpid; /* for $PID (NOMMU can override via -$HEXPID:HEXPPID:...) */
@@ -10388,7 +10399,7 @@ int hush_main(int argc, char **argv)
int opt = getopt(argc, argv, "+" /* stop at 1st non-option */
"cexinsl"
#if !BB_MMU
- "<:$:R:V:"
+ "$:R:V:"
# if ENABLE_HUSH_FUNCTIONS
"F:"
# endif
@@ -10438,9 +10449,6 @@ int hush_main(int argc, char **argv)
flags |= OPT_login;
break;
#if !BB_MMU
- case '<': /* "big heredoc" support */
- full_write1_str(optarg);
- _exit(0);
case '$': {
unsigned long long empty_trap_mask;