From ae3e71cb84a538bad400ecca881be4ef5add5f33 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Fri, 27 Dec 2019 09:51:02 -0500 Subject: [PATCH] Don't create function digest files At least until Zsh version 5.7.1, no performance improvement is observed out of using those. In some cases, the performance is even worsened, like when using autoload -w functions_digest.zwc instead of autoload func_name1 func_name2 ... --- src/stage2/50_zimfw_clean_compiled.zsh.erb | 17 ++------- src/stage2/50_zimfw_clean_dumpfile.zsh.erb | 2 +- src/templates/login_init.zsh.erb | 22 ++++------- src/zimfw.zsh.erb | 5 ++- zimfw.zsh | 43 +++++++--------------- 5 files changed, 28 insertions(+), 61 deletions(-) diff --git a/src/stage2/50_zimfw_clean_compiled.zsh.erb b/src/stage2/50_zimfw_clean_compiled.zsh.erb index a711ac3..eae355e 100644 --- a/src/stage2/50_zimfw_clean_compiled.zsh.erb +++ b/src/stage2/50_zimfw_clean_compiled.zsh.erb @@ -1,17 +1,8 @@ _zimfw_clean_compiled() { - local zopt_find zopt_rm zdir - if (( ! _zquiet )); then - zopt_find='-print' - zopt_rm='-v' - fi - for zdir in ${fpath}; do - [[ ${zdir} == (.|..) || ${zdir} == (.|..)/* ]] && continue - if [[ -w ${zdir:h} ]]; then - command rm -f ${zopt_rm} ${zdir}.zwc{,.old} || return 1 - fi - done - command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -delete ${zopt_find} || return 1 - command rm -f ${zopt_rm} <%= home %>/.zshrc.zwc{,.old} || return 1 + local zopt + (( ! _zquiet )) && zopt='-v' + command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -exec rm -f ${zopt} {} \; || return 1 + command rm -f ${zopt} <%= home %>/<%= startup_files_glob %>.zwc(|.old)(N) || return 1 if (( ! _zquiet )); then print -P '<%= done %>Done with clean-compiled. Run %Bzimfw compile%b to re-compile.' fi diff --git a/src/stage2/50_zimfw_clean_dumpfile.zsh.erb b/src/stage2/50_zimfw_clean_dumpfile.zsh.erb index 4f7efa6..8cd2e0f 100644 --- a/src/stage2/50_zimfw_clean_dumpfile.zsh.erb +++ b/src/stage2/50_zimfw_clean_dumpfile.zsh.erb @@ -2,7 +2,7 @@ _zimfw_clean_dumpfile() { local zdumpfile zopt zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=<%= home %>/.zcompdump (( ! _zquiet )) && zopt='-v' - command rm -f ${zopt} ${zdumpfile}{,.zwc{,.old}} || return 1 + command rm -f ${zopt} ${zdumpfile}(|.zwc(|.old)) || return 1 if (( ! _zquiet )); then print -P '<%= done %>Done with clean-dumpfile. Restart your terminal to dump an updated configuration.' fi diff --git a/src/templates/login_init.zsh.erb b/src/templates/login_init.zsh.erb index 30f43a9..3076a44 100644 --- a/src/templates/login_init.zsh.erb +++ b/src/templates/login_init.zsh.erb @@ -1,7 +1,7 @@ () { setopt LOCAL_OPTIONS CASE_GLOB EXTENDED_GLOB - autoload -U zrecompile - local zdumpfile zdir zfile + autoload -Uz zrecompile + local zdumpfile zfile # Compile the completion cache; significant speedup zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=<%= home %>/.zcompdump @@ -9,21 +9,13 @@ zrecompile -p ${1} ${zdumpfile} || return 1 fi - # Compile .zshrc - zrecompile -p ${1} <%= home %>/.zshrc || return 1 - - # Compile autoloaded functions, taken from zrecompile doc in zshcontrib(1) - for zdir in ${fpath}; do - [[ ${zdir} == (.|..) || ${zdir} == (.|..)/* ]] && continue - zfile=(${zdir}/^(*.*)(N-.)) - if [[ -w ${zdir:h} && -n ${zfile} ]]; then - zfile=(${${(M)zfile%/*/*}#/}) - (builtin cd -q ${zdir:h} && zrecompile -p ${1} ${zdir:t}.zwc ${zfile}) || return 1 - fi + # Compile Zsh startup files + for zfile in ${1} <%= home %>/<%= startup_files_glob %>(N-.); do + zrecompile -p ${1} ${zfile} || return 1 done - # Compile scripts - for zfile in ${ZIM_HOME}/(^*test*/)#*.zsh{,-theme}(N-.); do + # Compile Zim scripts + for zfile in ${ZIM_HOME}/(^*test*/)#*.zsh(|-theme)(N-.); do zrecompile -p ${1} ${zfile} || return 1 done diff --git a/src/zimfw.zsh.erb b/src/zimfw.zsh.erb index 3314711..5061aca 100644 --- a/src/zimfw.zsh.erb +++ b/src/zimfw.zsh.erb @@ -1,11 +1,12 @@ <% class Zim - attr_reader :home, :min_zsh_version, :script_filename, :version, :ellipsis, :okay, :error, :done, :failed + attr_reader :home, :min_zsh_version, :script_filename, :startup_files_glob, :version, :ellipsis, :okay, :error, :done, :failed def initialize @home = "${ZDOTDIR:-${HOME}}" @min_zsh_version = "5.2" @script_filename = "zimfw.zsh" + @startup_files_glob = ".z(shenv|shrc|login|logout)" @version = "1.0.0-SNAPSHOT" @ellipsis = " ..." @okay = "%F{green})%f " @@ -23,7 +24,7 @@ class Zim end def render_escaped(filename) - render(filename).gsub(/(\$[^']|"|`)/, "\\\\\\1") + render(filename).gsub(/(?=\$[^']|"|`)/, "\\\\") end def render_commented(filename) diff --git a/zimfw.zsh b/zimfw.zsh index 752d031..b69f5d8 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -67,8 +67,8 @@ _zimfw_build_login_init() { _zimfw_mv =( print -Rn "() { setopt LOCAL_OPTIONS CASE_GLOB EXTENDED_GLOB - autoload -U zrecompile - local zdumpfile zdir zfile + autoload -Uz zrecompile + local zdumpfile zfile # Compile the completion cache; significant speedup zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=\${ZDOTDIR:-\${HOME}}/.zcompdump @@ -76,21 +76,13 @@ _zimfw_build_login_init() { zrecompile -p \${1} \${zdumpfile} || return 1 fi - # Compile .zshrc - zrecompile -p \${1} \${ZDOTDIR:-\${HOME}}/.zshrc || return 1 - - # Compile autoloaded functions, taken from zrecompile doc in zshcontrib(1) - for zdir in \${fpath}; do - [[ \${zdir} == (.|..) || \${zdir} == (.|..)/* ]] && continue - zfile=(\${zdir}/^(*.*)(N-.)) - if [[ -w \${zdir:h} && -n \${zfile} ]]; then - zfile=(\${\${(M)zfile%/*/*}#/}) - (builtin cd -q \${zdir:h} && zrecompile -p \${1} \${zdir:t}.zwc \${zfile}) || return 1 - fi + # Compile Zsh startup files + for zfile in \${1} \${ZDOTDIR:-\${HOME}}/.z(shenv|shrc|login|logout)(N-.); do + zrecompile -p \${1} \${zfile} || return 1 done - # Compile scripts - for zfile in \${ZIM_HOME}/(^*test*/)#*.zsh{,-theme}(N-.); do + # Compile Zim scripts + for zfile in \${ZIM_HOME}/(^*test*/)#*.zsh(|-theme)(N-.); do zrecompile -p \${1} \${zfile} || return 1 done @@ -247,19 +239,10 @@ _zimfw_source_zimrc() { } _zimfw_clean_compiled() { - local zopt_find zopt_rm zdir - if (( ! _zquiet )); then - zopt_find='-print' - zopt_rm='-v' - fi - for zdir in ${fpath}; do - [[ ${zdir} == (.|..) || ${zdir} == (.|..)/* ]] && continue - if [[ -w ${zdir:h} ]]; then - command rm -f ${zopt_rm} ${zdir}.zwc{,.old} || return 1 - fi - done - command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -delete ${zopt_find} || return 1 - command rm -f ${zopt_rm} ${ZDOTDIR:-${HOME}}/.zshrc.zwc{,.old} || return 1 + local zopt + (( ! _zquiet )) && zopt='-v' + command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -exec rm -f ${zopt} {} \; || return 1 + command rm -f ${zopt} ${ZDOTDIR:-${HOME}}/.z(shenv|shrc|login|logout).zwc(|.old)(N) || return 1 if (( ! _zquiet )); then print -P 'Done with clean-compiled. Run %Bzimfw compile%b to re-compile.' fi @@ -269,7 +252,7 @@ _zimfw_clean_dumpfile() { local zdumpfile zopt zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=${ZDOTDIR:-${HOME}}/.zcompdump (( ! _zquiet )) && zopt='-v' - command rm -f ${zopt} ${zdumpfile}{,.zwc{,.old}} || return 1 + command rm -f ${zopt} ${zdumpfile}(|.zwc(|.old)) || return 1 if (( ! _zquiet )); then print -P 'Done with clean-dumpfile. Restart your terminal to dump an updated configuration.' fi @@ -280,7 +263,7 @@ _zimfw_compile() { } _zimfw_info() { - print 'Zim version: 1.0.0-SNAPSHOT (previous commit is 86f177a)' + print 'Zim version: 1.0.0-SNAPSHOT (previous commit is 94526d6)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a)