From: Matthew Hamilton <M@tthamilton.com>
To: zsh-workers@zsh.org
Subject: PATCH: minor variable allocation change in add-zsh-hook
Date: Fri, 2 Oct 2015 17:06:21 -0400 [thread overview]
Message-ID: <560EF1CD.6060009@tthamilton.com> (raw)
The 'local usage' variable is allocated in main, outside of the if loop
that determines if it is going to print the usage information. This
means time is spent allocating that variable, when in most cases, it
will never be printed. It would be better to set it within the if loop,
or alternatively, not using a variable and simply output the usage text
as as literal string (as many other functions do).
A trace of the time being needlessly being spent allocating the variable
can be seen here: https://gist.github.com/Eriner/3192c9eb98fabdd70607
It's not that much time, but it adds up and is inefficient/unnecessary.
diff --git a/Functions/Misc/add-zsh-hook b/Functions/Misc/add-zsh-hook
index ee37d67..bccd115 100644
--- a/Functions/Misc/add-zsh-hook
+++ b/Functions/Misc/add-zsh-hook
@@ -19,7 +19,6 @@ hooktypes=(
chpwd precmd preexec periodic zshaddhistory zshexit
zsh_directory_name
)
-local usage="Usage: $0 hook function\nValid hooks are:\n $hooktypes"
local opt
local -a autoopts
@@ -58,6 +57,7 @@ if (( list )); then
typeset -mp "(${1:-${(@j:|:)hooktypes}})_functions"
return $?
elif (( help || $# != 2 || ${hooktypes[(I)$1]} == 0 )); then
+ local usage="Usage: $0 hook function\nValid hooks are:\n $hooktypes"
print -u$(( 2 - help )) $usage
return $(( 1 - help ))
fi
next reply other threads:[~2015-10-02 21:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-02 21:06 Matthew Hamilton [this message]
2015-10-02 21:38 ` Mikael Magnusson
[not found] ` <560EFAC3.2050806@tthamilton.com>
2015-10-02 22:03 ` Mikael Magnusson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=560EF1CD.6060009@tthamilton.com \
--to=m@tthamilton.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).