Hello, I was benchmarking toysh against shells like dash and bash by calling 
the [ command
1,000,000 times, assuming it was a builtin on toysh.

dash and bash can do this in less than 10 seconds, while toysh takes 16.5 
_minutes_. After 
some fiddling with strace, I noticed it was forking off the [ command...
which is declared with TOYFLAG_MAYFORK (to prevent this exact issue)

The problem is in scripts/single.sh, which while building the toysh searches 
for MAYFORK in command declarations
to declare as dependencies... but only ones declared with the NEWTOY() macro,
which [ (aka USE_TEST_GLUE) isn't (The only OLDTOY() with TOYFLAG_MAYFORK too).

This patch fixes that, so that [ is automatically available as a buitin while 
building a single command
binary of the shell.

Also, at least on arch linux, egrep has been replaced by a shell script that 
warns the user that
egrep is deprecated, then calls grep -E. To get rid of these warnings, I 
replaced egrep with grep -E in this patch

-   Oliver Webb <[email protected]>
From 9e452abfc2ec820c5d4bf45782a42763eaa242ef Mon Sep 17 00:00:00 2001
From: Oliver Webb <[email protected]>
Date: Sat, 10 Feb 2024 20:51:59 -0600
Subject: [PATCH] replace egrep with grep -E to shut up arch linux, Scan
 OLDTOY's for MAYFORK too so that [ can be a builtin

---
 scripts/make.sh   | 4 ++--
 scripts/single.sh | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/scripts/make.sh b/scripts/make.sh
index a1968aa9..406d059e 100755
--- a/scripts/make.sh
+++ b/scripts/make.sh
@@ -91,7 +91,7 @@ mkdir -p "$UNSTRIPPED"  "$(dirname $OUTNAME)" || exit 1
 
 [ -n "$V" ] && echo -e "\nWhich C files to build..."
 TOYFILES="$($SED -n 's/^CONFIG_\([^=]*\)=.*/\1/p' "$KCONFIG_CONFIG" | xargs | tr ' [A-Z]' '|[a-z]')"
-TOYFILES="main.c $(egrep -l "TOY[(]($TOYFILES)[ ,]" toys/*/*.c | xargs)"
+TOYFILES="main.c $(grep -E -l "TOY[(]($TOYFILES)[ ,]" toys/*/*.c | xargs)"
 
 if [ "${TOYFILES/pending//}" != "$TOYFILES" ]
 then
@@ -133,7 +133,7 @@ fi
 
 # Does .config need dependency recalculation because toolchain changed?
 A="$($SED -n '/^config .*$/h;s/default \(.\)/\1/;T;H;g;s/config \([^\n]*\)[^yn]*\(.\)/\1=\2/p' "$GENDIR"/Config.probed | sort)"
-B="$(egrep "^CONFIG_($(echo "$A" | sed 's/=[yn]//' | xargs | tr ' ' '|'))=" "$KCONFIG_CONFIG" | $SED 's/^CONFIG_//' | sort)"
+B="$(grep -E "^CONFIG_($(echo "$A" | sed 's/=[yn]//' | xargs | tr ' ' '|'))=" "$KCONFIG_CONFIG" | $SED 's/^CONFIG_//' | sort)"
 A="$(echo "$A" | grep -v =n)"
 [ "$A" != "$B" ] &&
   { echo -e "\nWarning: Config.probed changed, run 'make oldconfig'" >&2; }
diff --git a/scripts/single.sh b/scripts/single.sh
index f4f28be9..3b0af013 100755
--- a/scripts/single.sh
+++ b/scripts/single.sh
@@ -25,7 +25,7 @@ KCONFIG_CONFIG=.singleconfig
 for i in "$@"
 do
   echo -n "$i:"
-  TOYFILE="$(egrep -l "TOY[(]($i)[ ,]" toys/*/*.c)"
+  TOYFILE="$(grep -E -l "TOY[(]($i)[ ,]" toys/*/*.c)"
 
   if [ -z "$TOYFILE" ]
   then
@@ -38,7 +38,7 @@ do
   unset DEPENDS MPDEL
   if [ "$i" == sh ]
   then
-    DEPENDS="$($SED -n 's/USE_\([^(]*\)(NEWTOY([^,]*,.*TOYFLAG_MAYFORK.*/\1/p' toys/*/*.c)"
+    DEPENDS="$($SED -n 's/USE_\([^(]*\)(...TOY([^,]*,.*TOYFLAG_MAYFORK.*/\1/p' toys/*/*.c)"
   else
     MPDEL='s/CONFIG_TOYBOX=y/# CONFIG_TOYBOX is not set/;t'
   fi
-- 
2.43.0

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to