sys-kernel/linux-firmware: Speed up src_prepare code.
authorUlrich Müller <ulm@kph.uni-mainz.de>
Mon, 20 May 2019 08:53:39 +0000 (10:53 +0200)
committerUlrich Müller <ulm@gentoo.org>
Mon, 20 May 2019 21:31:15 +0000 (23:31 +0200)
Building the list of files to remove could take up to one minute
on recent hardware, because it used a quadratic algorithm in bash.
Call grep instead, which is way faster.

Acked-by: Chí-Thanh Christopher Nguyễn <chithanh@gentoo.org>
Closes: https://bugs.gentoo.org/686376
Package-Manager: Portage-2.3.66, Repoman-2.3.12
Signed-off-by: Ulrich Müller <ulm@gentoo.org>
sys-kernel/linux-firmware/linux-firmware-99999999.ebuild

index 398592afd42bf980b2777f17eedeb62315ae0e76..f439b40eab430654190d8c7d53c9febabad8ccff 100644 (file)
@@ -226,6 +226,7 @@ src_prepare() {
 
        # remove sources and documentation (wildcards are expanded)
        rm -r ${source_files[@]} || die
+       rm -rf .git
 
        if use !unknown-license; then
                # remove files in unknown_license
@@ -236,12 +237,11 @@ src_prepare() {
                # remove files _not_ in the free_software or unknown_license lists
                # everything else is confirmed (or assumed) to be redistributable
                # based on upstream acceptance policy
-               local file remove=()
-               while IFS= read -d "" -r file; do
-                       has "${file#./}" "${free_software[@]}" "${unknown_license[@]}" \
-                               || remove+=("${file}")
-               done < <(find * ! -type d -print0 || die)
-               printf "%s\0" "${remove[@]}" | xargs -0 rm || die
+               local IFS=$'\n'
+               find ! -type d -printf "%P\n" \
+                       | grep -Fvx -e "${free_software[*]}" -e "${unknown_license[*]}" \
+                       | xargs -d '\n' rm || die
+               IFS=$' \t\n'
        fi
 
        echo "# Remove files that shall not be installed from this list." > ${PN}.conf
@@ -250,23 +250,12 @@ src_prepare() {
        if use savedconfig; then
                restore_config ${PN}.conf
 
-               local file preserved_files=() remove=()
-
                ebegin "Removing all files not listed in config"
-               while IFS= read -r file; do
-                       # Ignore comments.
-                       if [[ ${file} != "#"* ]]; then
-                               preserved_files+=("${file}")
-                       fi
-               done < ${PN}.conf || die
-
-               while IFS= read -d "" -r file; do
-                       has "${file}" "${preserved_files[@]}" || remove+=("${file}")
-               done < <(find * ! -type d ! -name ${PN}.conf -print0 || die)
-               if [[ ${#remove[@]} -gt 0 ]]; then
-                       printf "%s\0" "${remove[@]}" | xargs -0 rm || die
-               fi
-               eend 0
+               find ! -type d ! -name ${PN}.conf -printf "%P\n" \
+                       | grep -Fvx -f <(grep -v '^#' ${PN}.conf \
+                               || die "grep failed, empty config file?") \
+                       | xargs -d '\n' --no-run-if-empty rm
+               eend $? || die
        fi
 
        # remove empty directories, bug #396073