From 4f821681676010a75b9c56086fc2dd2825fc10c6 Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Thu, 28 Jul 2011 17:00:56 -0400 Subject: [PATCH] Compile files into a pre-parsed form for faster sourcing. --- .gitignore | 6 ++---- oh-my-zsh.zsh | 26 ++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 31cc75cb..5d74a078 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ -locals.zsh -log/.zsh_history -projects.zsh -cache +*.zwc +*.zwc.old diff --git a/oh-my-zsh.zsh b/oh-my-zsh.zsh index 12c3d483..f063a1db 100644 --- a/oh-my-zsh.zsh +++ b/oh-my-zsh.zsh @@ -26,8 +26,26 @@ done # Load and run the prompt theming system. autoload -Uz promptinit && promptinit -i -# Compile zcompdump, if modified, to increase startup speed. -if [[ "$HOME/.zcompdump" -nt "$HOME/.zcompdump.zwc" ]] || [[ ! -e "$HOME/.zcompdump.zwc" ]]; then - zcompile "$HOME/.zcompdump" -fi +# Load the automatic recompiler. +autoload -Uz zrecompile + +# Compile files. +for zsh_file in $HOME/.z{login,logout,profile,shenv,shrc,compdump}(N) $OMZ/*.zsh(N); do + zrecompile -q -p -U -z "$zsh_file" +done + +# Compile function directories. +for (( i=1; i <= $#fpath; i++ )); do + function_dir="$fpath[i]" + [[ "$function_dir" == (.|..) ]] \ + || [[ "$function_dir" == (.|..)/* ]] \ + || [[ ! -w "$function_dir:h" ]] && continue + function_files=($function_dir/^*(\.(rej|orig)|~|\#)(N-.)) + [[ -n "$function_files" ]] \ + && function_files=(${${(M)function_files%/*/*}#/}) \ + && ( cd "$function_dir:h" && zrecompile -q -p -U -z "${function_dir:t}.zwc" "$function_files[@]" ) \ + && fpath[i]="$fpath[i].zwc" +done +unset function_dir +unset function_files