[COGITO PATCH] Optimized print_help()

From: Pavel Roskin <proski@gnu.org>
Date: 2005-06-15 09:26:16
Hello!

print_help() in cg-Xlib should not be calling "which" 3 times.  It's an
external command.  The patch caches the result in a local variable.

Signed-off-by: Pavel Roskin <proski@gnu.org>

diff --git a/cg-Xlib b/cg-Xlib
--- a/cg-Xlib
+++ b/cg-Xlib
@@ -130,10 +130,11 @@ update_index () {
 
 
 print_help () {
-	which "cg-$1" >/dev/null 2>&1 || exit 1
-	sed -n '/^USAGE=/,0s/.*"\(.*\)"/Usage: \1/p' < $(which cg-$1) 
+	local toolpath=$(which cg-$1 2>/dev/null)
+	[ -z "$toolpath" ] && exit 1
+	sed -n '/^USAGE=/,0s/.*"\(.*\)"/Usage: \1/p' < $toolpath
 	echo
-	cat $(which cg-$1) | sed -n '3,/^$/s/^# *//p'
+	cat $toolpath | sed -n '3,/^$/s/^# *//p'
 	exit
 }
 

-- 
Regards,
Pavel Roskin

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Wed Jun 15 09:27:05 2005

This archive was generated by hypermail 2.1.8 : 2005-06-15 09:27:06 EST