Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: minor variable allocation change in add-zsh-hook
- X-seq: zsh-workers 36751
- From: Matthew Hamilton <M@xxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: minor variable allocation change in add-zsh-hook
- Date: Fri, 2 Oct 2015 17:06:21 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=simple/simple; d=tthamilton.com; s=dkim; t=1443819983; bh=yRIpqAB/O/s7mQvbzhXVvWxKeWE7Jwp3WqwgXcFKrnM=; h=From:Subject:To:Date; b=EXrCETSHOWa2C9HoYhYZdT9h3O2GmtUh+75K+KQkdJvuP7vqHNQN9WhBsuQrL9R7g Zp3qIWtnq9uW+SzCGVecDv3f86hawQuuf31kNyxW7LVAO2OI7YFT7Y6Fh9oUqQfigv Apre02ARQxLBt9Vt07LJ6dOIddulDAOqhmHCI/3A=
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author