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

Commit

Permalink
7.5.4 : minor performance optimisations
Browse files Browse the repository at this point in the history
Signed-off-by: Ari Archer <[email protected]>
  • Loading branch information
Ari Archer committed Mar 17, 2023
1 parent 130b775 commit 4ff4603
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 26 deletions.
2 changes: 1 addition & 1 deletion baz
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[ "$BAZ_DEBUG" ] && set -x

export BAZ_VERSION='7.5.3'
export BAZ_VERSION='7.5.4'
export BAZ_DIR="$HOME/.local/share/baz"
export BAZ_CONFDIR="$HOME/.config/baz"
export BAZ_CONF="$BAZ_CONFDIR/config.env"
Expand Down
1 change: 1 addition & 0 deletions loader/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ static char *read_line(const char *path) {

buf[rb - (buf[rb - 1] == '\n')] = '\0';
close(fd);

return buf;
}
#endif /* FILE_IMPL */
Expand Down
22 changes: 6 additions & 16 deletions loader/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,30 @@ static unsigned char debug_load;
#define PATH_MAX 4096
#endif

static File f = {0}, *pf = &f;

typedef struct {
void (*stage)(char *, const size_t, DIR *, struct dirent *);
const char *path;
} stage_t;

static void
load_envs(char *path, const size_t base, DIR *dp, struct dirent *ep) {
mks(File, f);

log("loading environment variables");

nputs("export");

while ((ep = readdir_visible(dp))) {
pathcat(ep->d_name);
alloc_file(path, pf);

escape_quotes(&f);
alloc_file(path, pf);
escape_quotes(pf);

printf(" %s=\"%s\"", ep->d_name, f.content);
path[base] = '\0';
}

pnl();
free_file(pf);
}

static void
Expand All @@ -73,8 +72,6 @@ load_cmds(char *path, const size_t base, DIR *dp, struct dirent *ep) {

static void
load_functions(char *path, const size_t base, DIR *dp, struct dirent *ep) {
mks(File, f);

log("loading functions");

while ((ep = readdir_visible(dp))) {
Expand All @@ -85,14 +82,10 @@ load_functions(char *path, const size_t base, DIR *dp, struct dirent *ep) {

path[base] = '\0';
}

free_file(pf);
}

static void
load_aliases(char *path, const size_t base, DIR *dp, struct dirent *ep) {
mks(File, f);

log("loading aliases");

nputs("alias");
Expand All @@ -108,13 +101,10 @@ load_aliases(char *path, const size_t base, DIR *dp, struct dirent *ep) {
}

pnl();
free_file(pf);
}

static void
load_runners(char *path, const size_t base, DIR *dp, struct dirent *ep) {
mks(File, f);

log("running runners");

while ((ep = readdir_visible(dp))) {
Expand All @@ -124,8 +114,6 @@ load_runners(char *path, const size_t base, DIR *dp, struct dirent *ep) {
puts(f.content);
path[base] = '\0';
}

free_file(pf);
}

static void
Expand Down Expand Up @@ -234,5 +222,7 @@ int main(int argc, char **argv) {

puts("export PATH"); /* finish off commands, export path */

free_file(pf);

return 0;
}
4 changes: 2 additions & 2 deletions loader/loader.sht
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export BAZ_LOADER_VERSION='#{BAZ_VER}'

baz_load_plugin_low() {
. "$1/baz.env"
eval "$(:BAZ_LOADER_CMD "$1/$BAZP_SRC")"
eval "$(':BAZ_LOADER_CMD' "$1/$BAZP_SRC")"
}

baz_loader() {
Expand All @@ -16,7 +16,7 @@ baz_loader() {
[ -f "$p/baz.env" ] && [ ! -e "$p/disabled" ] && . "$p/baz.env" && d+=("$p/$BAZP_SRC")
done

[ "$BAZP_SRC" ] && eval "$(:BAZ_LOADER_CMD "${d[@]}")"
[ "$BAZP_SRC" ] && eval "$(':BAZ_LOADER_CMD' "${d[@]}")"

#{BAZ_NOP}
}
Expand Down
6 changes: 1 addition & 5 deletions loader/macros.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#ifndef _MACROS_H
#define _MACROS_H
#include "config.h"
#define DP(name) DIR_SEP name DIR_SEP
#ifdef LOGGING
#define log(msg) \
Expand All @@ -10,10 +9,7 @@
#define log(msg)
#endif /* LOGGING */
#define nputs(s) fputs(s, stdout)
#define mks(sname, var) \
sname var = {0}; \
sname *p##var = &var
#define pnl() putchar(newline)
#define pnl() putchar(newline)
#if defined(BSD) || defined(__bsd__) || defined(__BSD__) || \
defined(__FreeBSD__) || defined(__OpenBSD__) || defined(FreeBSD) || \
defined(OpenBSD)
Expand Down
3 changes: 1 addition & 2 deletions loader/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ static void escape_quotes(File *);
#ifdef SHELL_IMPL
static void escape_quotes(File *file) {
char *new_content, *old_ptr, *new_ptr;
file->content_size = file->content_size * 2;

new_content = malloc(file->content_size);
new_content = malloc((file->content_size *= 2));
old_ptr = file->content, new_ptr = new_content;

while (*old_ptr) {
Expand Down

0 comments on commit 4ff4603

Please sign in to comment.