Browse Source

less subshells improve speed

main
pvincent 2 weeks ago
parent
commit
d548396419
  1. 23
      poc

23
poc

@ -3,7 +3,7 @@
# constants
MIAOU_BASH_ERROR=$(mktemp -t "$(basename "$0").XXXXXXXX" --tmpdir="/run/user/$(id -u)")
MIAOU_BASH_ERROR=$(mktemp -t "$(basename "$0").XXXXXXXX" --tmpdir="/run/user/$UID")
MIAOU_DEBUG=${MIAOU_DEBUG:-false}
declare -A ANSI
@ -49,14 +49,21 @@ function is_true {
# example: alias toto="bash -c \"[[ \\\$MIAOU_DEBUG == 'true' ]] && echo yes \\\$* || echo nope\""
function miaou_debug {
if is_true "${MIAOU_DEBUG}"; then
local compute_hierarchy=true
[[ ! -v miaou_debug_hierarchy ]] && miaou_debug_hierarchy=0
local i message="$*" padding=''
regex='^</' # starts with </
[[ $miaou_debug_hierarchy -gt 0 ]] && [[ "${message}" =~ $regex ]] && ((--miaou_debug_hierarchy))
for i in $(seq 1 "$miaou_debug_hierarchy"); do padding+=' '; done
[[ $miaou_debug_hierarchy -gt 0 ]] &&
[[ "${message}" =~ $regex ]] &&
((--miaou_debug_hierarchy)) &&
compute_hierarchy=false
for ((i = 0; i < miaou_debug_hierarchy; i++)); do padding+=' '; done
>&4 builtin echo -e "\e[90m <== DEBUG ==> ${padding}\e[33m${message}\e[0m"
regex='^<[^/].*[^/]>$' # markup starting
[[ "${message}" =~ $regex ]] && ((++miaou_debug_hierarchy)) || true
regex='[^/]>$' # does NOT end with />
is_true $compute_hierarchy &&
[[ "${message}" =~ $regex ]] &&
((++miaou_debug_hierarchy)) ||
true
fi
}
@ -199,7 +206,7 @@ function dump_failure {
length_box=$((${#failure_type} + ${#failure_code} + (2 * 2) + 2))
[[ -v failure_payload ]] && length_box=$((length_box + ${#failure_payload} + (2 * 2) + 1))
echo -n '╔'
for i in $(seq 1 $length_box); do echo -n '═'; done
for ((i = 0; i < length_box; i++)); do echo -n '═'; done
echo '╗'
echo -n "║ $failure_type "
[[ -v failure_payload ]] && echo -n ' ' && tty_ansi BG_WHITE FG_BLACK && echo -n " $failure_payload " && tty_ansi RESET
@ -208,9 +215,9 @@ function dump_failure {
tty_ansi FG_MAGENTA
echo "║"
echo -n '╚'
for i in $(seq 1 4); do echo -n '═'; done
for ((i = 0; i < 4; i++)); do echo -n '═'; done
echo -n '╦'
for i in $(seq $((i + 2)) $length_box); do echo -n '═'; done
for ((i = 5; i < length_box; i++)); do echo -n '═'; done
echo '╝'
echo " ║"
tty_ansi RESET

Loading…
Cancel
Save