[git commit] hush: speed up "big heredoc" code

Denys Vlasenko vda.linux at googlemail.com
Sat Apr 1 20:52:08 UTC 2023


commit: https://git.busybox.net/busybox/commit/?id=fd5fb2d2b59640910addf5c946a39d4cc5c09003
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

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 at googlemail.com>
---
 shell/hush.c | 22 +++++++++++++++-------
 1 file 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;
 


More information about the busybox-cvs mailing list