From 04b8036e32c42f70f316514fc3c71a79a8e51cd6 Mon Sep 17 00:00:00 2001 From: MilhouseVH Date: Wed, 29 May 2019 00:49:26 +0100 Subject: [PATCH] buildsystem: replace $(cat file) with faster alternative See: https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html " ... Bash performs the expansion by executing command in a subshell environment and replacing the command substitution with the standard output of the command, with any trailing newlines deleted. Embedded newlines are not deleted, but they may be removed during word splitting. The command substitution $(cat file) can be replaced by the equivalent but faster $(< file). " Testing indicates var=$(< file) is twice as fast as var=$(cat file). --- config/functions | 6 +++--- config/multithread | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/config/functions b/config/functions index af1020e884..2c5529b70f 100644 --- a/config/functions +++ b/config/functions @@ -1264,7 +1264,7 @@ pkg_lock() { # As we now have the lock, if .failed still exists then a previous process must have failed if [ -f "${THREAD_CONTROL}/locks/${pkg}.${task}.failed" ]; then - fail_seq="$(cat "${THREAD_CONTROL}/locks/${pkg}.${task}.failed")" + fail_seq="$(< "${THREAD_CONTROL}/locks/${pkg}.${task}.failed")" print_color CLR_ERROR "FAILURE: ${pkg}.${task}.failed exists, a previous dependency process has failed (seq: ${fail_seq})\n" if [ -d "${THREAD_CONTROL}/logs" ]; then cat <>"${THREAD_CONTROL}/status"; num=$((num + 1)); done - num=$(($(cat "${THREAD_CONTROL}/progress.prev") + 1)) + num=$(< "${THREAD_CONTROL}/progress.prev") projdevarch="${PROJECT}/" [ -n "${DEVICE}" ] && projdevarch+="${DEVICE}/" projdevarch+="${TARGET_ARCH}" TZ=UTC0 printf -v elapsed "%(%H:%M:%S)T" $(($(date +%s) - MTBUILDSTART)) - printf -v preamble "%s Dashboard (%s) - %d of %d jobs completed, %s elapsed" "${DISTRONAME}" "${projdevarch}" ${num} ${MTMAXJOBS} "${elapsed}" + printf -v preamble "%s Dashboard (%s) - %d of %d jobs completed, %s elapsed" "${DISTRONAME}" "${projdevarch}" $((num + 1)) ${MTMAXJOBS} "${elapsed}" printf -v preamble "%b%-105s %s" "\e[2J\e[0;0H" "${preamble//\//\\/}" "$(date "+%Y-%m-%d %H:%M:%S")" if [ "${DISABLE_COLORS}" != "yes" ]; then diff --git a/config/multithread b/config/multithread index cb96bfa574..902c6f5a83 100644 --- a/config/multithread +++ b/config/multithread @@ -107,8 +107,9 @@ package_worker() { ( flock --exclusive 95 [ ${result} -eq 0 ] && status="DONE" || status="FAIL" - num=$(($(cat "${THREAD_CONTROL}/progress") + 1)) + num=$(< "${THREAD_CONTROL}/progress") mv "${THREAD_CONTROL}/progress" "${THREAD_CONTROL}/progress.prev" + num=$((num + 1)) echo ${num} >"${THREAD_CONTROL}/progress" printf "[%0*d/%0*d] [%-4s] %-7s %s\n" ${#jobs} ${num} ${#jobs} ${jobs} "${status}" "${task}" "${pkgname}" >&2 ) 95>"${THREAD_CONTROL}/locks/.progress"