Use shell builtins instead of calling wc/awk/sed. (Fewer forks in build loop.) accepted/tizen/unified/20190704.040502 submit/tizen/20190703.090540
authorRob Landley <rob@landley.net>
Wed, 2 Mar 2016 05:39:27 +0000 (23:39 -0600)
committerSemun Lee <semun.lee@samsung.com>
Wed, 3 Jul 2019 09:02:23 +0000 (18:02 +0900)
Based on suggestions from Nicholas Boichat.

scripts/make.sh

index 6c03b80..cd9c8b8 100755 (executable)
@@ -235,6 +235,7 @@ fi
 PENDING=
 LFILES=
 DONE=0
+COUNT=0
 for i in $FILES
 do
   # build each generated/obj/*.o file in parallel
@@ -246,16 +247,18 @@ do
   [ "$OUT" -nt "$i" ] && continue
   do_loudly $BUILD -c $i -o $OUT &
   PENDING="$PENDING $!"
+  COUNT=$(($COUNT+1))
 
   # ratelimit to $CPUS many parallel jobs, detecting errors
 
-  while true
+  for j in $PENDING
   do
-    [ $(echo "$PENDING" | wc -w) -lt "$CPUS" ] && break;
+    [ "$COUNT" -lt "$CPUS" ] && break;
 
-    wait $(echo "$PENDING" | awk '{print $1}')
+    wait $j
     DONE=$(($DONE+$?))
-    PENDING="$(echo "$PENDING" | sed 's/^ *[0-9]*//')"
+    COUNT=$(($COUNT-1))
+    PENDING="${PENDING## $j}"
   done
   [ $DONE -ne 0 ] && break
 done