commit:     c0dc5a5644ad90915fbdeb0e2f4049f134d8ed57
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Thu Aug 11 00:37:58 2022 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Jun  7 22:54:11 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=c0dc5a56

ecompress: don't repeatedly open and close files during loops

It is inefficient to compose loops which - for each iteration - open a
file, write to it, then close it again. Instead, apply the offending
redirections to their associated compound commands (for/while).

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 bin/ecompress | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/bin/ecompress b/bin/ecompress
index 8a844c3b6e..233c9469d5 100755
--- a/bin/ecompress
+++ b/bin/ecompress
@@ -13,16 +13,19 @@ do_ignore() {
                if [[ -d ${ED%/}/${skip#/} ]]; then
                        skip_dirs+=( "${ED%/}/${skip#/}" )
                else
-                       rm -f -- "${ED%/}/${skip#/}.ecompress" || die
-                       printf '%s\n' "${EPREFIX}/${skip#/}" >> 
"${T}/.ecompress_skip_files" || die
+                       rm -f -- "${ED%/}/${skip#/}.ecompress" \
+                       && printf '%s\n' "${EPREFIX}/${skip#/}" \
+                       || ! break
                fi
-       done
+       done > "${T}/.ecompress_skip_files" || die
 
        if (( ${#skip_dirs[@]} )); then
                while IFS= read -rd '' skip; do
                        skip=${skip%.ecompress}
-                       printf '%s\n' "${skip#"${D%/}"}" >> 
"${T}/.ecompress_skip_files" || die
-               done < <(find "${skip_dirs[@]}" -name '*.ecompress' -print0 
-delete || die)
+                       printf '%s\n' "${skip#"${D%/}"}" || ! break
+               done \
+               < <(find "${skip_dirs[@]}" -name '*.ecompress' -print0 -delete 
|| die) \
+               >> "${T}/.ecompress_skip_files" || die
        fi
 
        if [[ -s ${T}/.ecompress_skip_files && -s 
${T}/.ecompress_had_precompressed ]]; then
@@ -70,12 +73,14 @@ do_queue() {
                                                        continue 2
                                                fi
                                        done
-                                       printf '%s\n' "${path#"${D%/}"}" >> 
"${T}"/.ecompress_had_precompressed || die
+                                       printf '%s\n' "${path#"${D%/}"}" || ! 
break
                                        ;;
                        esac
 
                        >> "${path}.ecompress" || die
-               done < <(find "${find_args[@]}" -print0 || die)
+               done \
+               < <(find "${find_args[@]}" -print0 || die) \
+               > "${T}"/.ecompress_had_precompressed || die
 
                if (( ${#collisions[@]} )); then
                        eqawarn "QA Notice: Colliding files found by ecompress:"

Reply via email to