On 2/3/22 17:12, Jakub Jelinek wrote:
On Thu, Feb 03, 2022 at 04:40:25PM +0100, Martin Liška wrote:
--- a/fixincludes/fixinc.in
+++ b/fixincludes/fixinc.in
@@ -258,12 +258,23 @@ then echo "All directories (including links to
directories):"
echo $all_dirs
fi
-for file in $all_dirs; do
- rm -rf $LIB/$file
- if [ ! -d $LIB/$file ]
- then mkdir $LIB/$file
- fi
-done
+ARG_MAX=`getconf ARG_MAX 2>/dev/null`
+LENGTH=`expr length "$all_dirs" + 10`
+
+if test -n "$ARG_MAX" && test $LENGTH -lt $ARG_MAX
+then
+ cd $LIB
+ mkdir -p $all_dirs
+ cd ..
+else
+ for file in $all_dirs; do
+ rm -rf $LIB/$file
+ if [ ! -d $LIB/$file ]
+ then mkdir $LIB/$file
+ fi
+ done
+fi
Is getconf and expr length sufficiently portable?
Can't you use
echo "$all_dirs" | xargs mkdir -p
instead?
Oh, even better!
Ready to be installed?
Thanks,
Martin
Jakub
From 7f14710fff01aa0267020020d20014144939f038 Mon Sep 17 00:00:00 2001
From: Martin Liska <mli...@suse.cz>
Date: Thu, 3 Feb 2022 15:49:43 +0100
Subject: [PATCH] Speed up fixincludes.
In my case:
$ rm ./stmp-fixinc ; time make -j16
takes 17 seconds, where I can reduce it easily with the suggested
change. Then I get to 11.2 seconds.
The scripts searches ~2500 folders in my case with total 20K header
files.
fixincludes/ChangeLog:
* fixinc.in: Use mkdir -p rather that a loop.
---
fixincludes/fixinc.in | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/fixincludes/fixinc.in b/fixincludes/fixinc.in
index de5a37f6acc..0c3066452c6 100755
--- a/fixincludes/fixinc.in
+++ b/fixincludes/fixinc.in
@@ -258,12 +258,10 @@ then echo "All directories (including links to directories):"
echo $all_dirs
fi
-for file in $all_dirs; do
- rm -rf $LIB/$file
- if [ ! -d $LIB/$file ]
- then mkdir $LIB/$file
- fi
-done
+cd $LIB
+echo "$all_dirs" | xargs mkdir -p
+cd ..
+
mkdir $LIB/root
# # # # # # # # # # # # # # # # # # # # #
--
2.35.1