Skip to content

Commit

Permalink
perf(zwc): spaceship::precompile compiles sources to zwc
Browse files Browse the repository at this point in the history
  • Loading branch information
denysdovhan committed Aug 29, 2022
1 parent 8a54cb3 commit 58758e7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
3 changes: 2 additions & 1 deletion lib/core.zsh
Expand Up @@ -18,7 +18,8 @@ spaceship::core::load_sections() {
# Custom section is declared, nothing else to do
continue
elif [[ -f "$SPACESHIP_ROOT/sections/$section.zsh" ]]; then
source "$SPACESHIP_ROOT/sections/$section.zsh"
builtin source "$SPACESHIP_ROOT/sections/$section.zsh"
spaceship::precompile "$SPACESHIP_ROOT/sections/$section.zsh"
else
# section is not found!
spaceship::core::skip_section "$section"
Expand Down
13 changes: 13 additions & 0 deletions lib/utils.zsh
Expand Up @@ -18,6 +18,19 @@ spaceship::defined() {
typeset -f + "$1" &> /dev/null
}

# Precompile zsh file to ZWC (zsh word code)
# USAGE:
# spaceship::precomile <file>
spaceship::precompile() {
spaceship::exists zcompile || return 1

local file="$1"

if [[ ! $file.zwc -nt $file && -w "$(dirname $1)" ]]; then
zcompile -R -- $file.zwc $file
fi
}

# Check if the current directory is in a Git repository.
# USAGE:
# spaceship::is_git
Expand Down
38 changes: 15 additions & 23 deletions spaceship.zsh
Expand Up @@ -128,29 +128,21 @@ fi
# Spaceship utils/hooks/etc
# ------------------------------------------------------------------------------

# Load utils
source "$SPACESHIP_ROOT/lib/utils.zsh"

# Load cache
source "$SPACESHIP_ROOT/lib/cache.zsh"

# Load hooks
source "$SPACESHIP_ROOT/lib/hooks.zsh"

# Load section utils
source "$SPACESHIP_ROOT/lib/section.zsh"

# Load prompt renderer
source "$SPACESHIP_ROOT/lib/core.zsh"

# Load functions for composing prompts
source "$SPACESHIP_ROOT/lib/prompts.zsh"

# Load command line interface
source "$SPACESHIP_ROOT/lib/cli.zsh"

# Load testkit
source "$SPACESHIP_ROOT/lib/testkit.zsh"
readonly SPACESHIP_LIBS=(
"lib/utils.zsh" # General porpuse utils
"lib/cache.zsh" # Cache utils
"lib/hooks.zsh" # Zsh hooks
"lib/section.zsh" # Section utils
"lib/core.zsh" # Core functions for loading and rendering
"lib/prompts.zsh" # Composing prompt variables
"lib/cli.zsh" # CLI interface
"lib/testkit.zsh" # Testing utils
)

for lib in "${SPACESHIP_LIBS[@]}"; do
builtin source "$SPACESHIP_ROOT/$lib"
spaceship::precompile "$SPACESHIP_ROOT/$lib"
done

# ------------------------------------------------------------------------------
# BACKWARD COMPATIBILITY WARNINGS
Expand Down

0 comments on commit 58758e7

Please sign in to comment.