Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
2.8.0: Improve performance, write baz-cat in C and corectness fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Ari Archer <[email protected]>
  • Loading branch information
Ari Archer committed Oct 22, 2022
1 parent afdd49d commit 02d3bd9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 47 deletions.
23 changes: 14 additions & 9 deletions baz
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[ "$BAZ_DEBUG" ] && set -x

export BAZ_VERSION='2.7.0'
export BAZ_VERSION='2.8.0'
export BAZ_DIR="$HOME/.local/share/baz"
export BAZ_CONFDIR="$HOME/.config/baz"
export BAZ_CONF="$BAZ_CONFDIR/config.env"
Expand All @@ -27,6 +27,7 @@ export BAZ_LOADER_TEMPLATE="$BAZP_INITDIR/loader.sht"

entry() { printf " + %-35s%s\n" "$1" "$2"; }
log() { [ "$BAZP_NO_LOG" = true ] || ${2:-echo} " * $1"; }
elog() { log "$1" >&2; }
eecho() { [ "$BAZP_NO_LOG" = true ] || echo "$1" >&2; }
unexpand_path() { echo "${1/"$HOME"/"${2:-~}"}"; }
baz_git_clone() { git clone --quiet --recursive -- "$1" "$2"; }
Expand Down Expand Up @@ -89,7 +90,7 @@ use() {
}

error() {
log "Error: $1" >&2
elog "Error: $1"
exit 1
}

Expand Down Expand Up @@ -435,7 +436,7 @@ bazp_install_gits() {
baz_help() {
[ "$BAZP_NO_LOG" = true ] && return

log "Help for baz v$BAZ_VERSION"
elog "Help for baz v$BAZ_VERSION"

{
log 'Subcommands:'
Expand Down Expand Up @@ -671,7 +672,7 @@ baz_list() {
{
while read -r dir; do
_plugent="$(get_base "$dir")"
[ -f "$dir/disabled" ] && _plugent+=' [DISABLED]' >&2
[ -f "$dir/disabled" ] && _plugent+=' [DISABLED]'

log "$_plugent"
done <<<"$(find "${BAZ_PLUGDIR:?}" -maxdepth 1 -not -path "${BAZ_PLUGDIR:?}" -type d)"
Expand Down Expand Up @@ -771,17 +772,17 @@ main() {
if [ -f "$BAZ_CONF" ]; then
. "$BAZ_CONF"
else
log 'Warning: no config found'
elog 'Warning: no config found'
fi

if [ "$BAZ_LOADER_VERSION" ] && [ "$BAZ_LOADER_VERSION" != "$BAZ_VERSION" ]; then
log "Baz loader version ($BAZ_LOADER_VERSION) does not match current version ($BAZ_VERSION)"
elog "Baz loader version ($BAZ_LOADER_VERSION) does not match current version ($BAZ_VERSION)"
fi

BAZP_NO_LOG=true bazp_reset_env

case "$1" in
help) baz_help ;;
case "${1//[[:space:]]/}" in
help) baz_help 2>&1 ;;
setup) baz_setup ;;
unsetup) baz_unsetup ;;
install) baz_install "$2" "${@:3}" ;;
Expand All @@ -793,8 +794,12 @@ main() {
version) echo "v$BAZ_VERSION" ;;
disable) baz_disable "${@:2}" ;;
enable) baz_enable "${@:2}" ;;
'')
baz_help
exit 2
;;
*)
log "Error: subcommand '$1' is not valid"
elog "Error: subcommand '$1' is not valid"
baz_help 2>&1 | indent >&2
exit 1
;;
Expand Down
32 changes: 32 additions & 0 deletions baz-cat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <stdio.h>

/*
* Improved performance, C89 compatible cat(1) for `baz` usage,
* this will read input and then print it
*/

int main(void) {
static char c;

/*
* This is kind of an implementation of puts lol,
* it doesn't really slow down the program, but
* I have to read it char-by-char to support
* unicode
*/
while ((c = getchar()) != EOF)
putchar(c);

#ifdef MANUAL_FLUSH
/*
* Enable this with -DMANUAL_FLUSH if you want
* to manually flush stdout on call, although
* C already has auto flushing to cover most
* cases and this just slows the program down
*/

fflush(stdout);
#endif

return 0;
}
33 changes: 0 additions & 33 deletions baz-cat.cc

This file was deleted.

9 changes: 5 additions & 4 deletions loader.sht
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ __baz_sanitize() {
# the diff is around 104ms

set -- "${1%"${1##*[!/]}"}"
local base="${1##*/}"
local tmp="${base//[[:space:]\"\'~!#\\$%^&*\/()=]/}"

local tmp="${1##*/}"
tmp="${tmp//[[:space:]\"\'~!#\\$%^&*\/()=]/}"

echo "${tmp//../}"
}
Expand Down Expand Up @@ -99,8 +100,8 @@ __baz_load_functions() {

__baz_vecho "Loading function '$_func_name'"
eval "function $_func_name() {
$(<"$_baz_func")
}"
$(<"$_baz_func")
}"
done
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/baz-cat-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -xe

main() {
${CXX:-clang++} $CXXFLAGS -flto -Ofast -ffunction-sections -fdata-sections -s -std=c++98 -Wall -Wextra -Wpedantic -Wshadow -Werror -pedantic -march=native -pipe -o baz-cat baz-cat.cc
${CC:-clang} $CFLAGS -flto -Ofast -ffunction-sections -fdata-sections -s -std=c89 -Wall -Wextra -Wpedantic -Wshadow -Werror -pedantic -march=native -pipe -o baz-cat baz-cat.c
${STRIP:-strip} --strip-all --remove-section=.note --remove-section=.gnu.version --remove-section=.comment --strip-debug --strip-unneeded baz-cat
}

Expand Down

0 comments on commit 02d3bd9

Please sign in to comment.