From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1837 invoked from network); 11 Sep 1999 08:51:55 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 11 Sep 1999 08:51:55 -0000 Received: (qmail 19060 invoked by alias); 11 Sep 1999 08:51:45 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7778 Received: (qmail 19052 invoked from network); 11 Sep 1999 08:51:44 -0000 To: zsh-workers@sunsite.auc.dk Subject: PATCH: _regex_arguments use cache. MIME-Version: 1.0 (generated by AKEMI 1.13.2 - =?ISO-2022-JP?B?Ig==?= =?ISO-2022-JP?B?GyRCQTA0Y0s8GyhCIg==?=) Content-Type: text/plain; charset=US-ASCII From: Tanaka Akira Date: 11 Sep 1999 17:51:42 +0900 Message-ID: User-Agent: Chao-gnus/6.12.5 AKEMI/1.13.2 (=?ISO-2022-JP?B?GyRCQTAbKEI=?= =?ISO-2022-JP?B?GyRCNGNLPBsoQg==?=) FLAM-DOODLE/1.12.6 (=?ISO-2022-JP?B?GyRCM3cbKEI=?= 10R4.0/5.0) Emacs/20.4 (sparc-sun-solaris2.6) MULE/4.0 (HANANOEN) I made _regex_arguments to cache generated state machines. Index: Completion/Base/_regex_arguments =================================================================== RCS file: /projects/zsh/zsh/Completion/Base/_regex_arguments,v retrieving revision 1.1.1.2 diff -u -F^( -r1.1.1.2 _regex_arguments --- _regex_arguments 1999/09/11 01:42:45 1.1.1.2 +++ _regex_arguments 1999/09/11 08:48:27 @@ -6,6 +6,13 @@ ## usage: _regex_arguments funcname regex +## configuration key used: + +# regex_arguments_path +# The path to a directory for caching. (default: ~/.zsh/regex_arguments) + +## + # _regex_arguments compiles `regex' and emit the result of the state # machine into the function `funcname'. `funcname' parses a command line # according to `regex' and evaluate appropriate actions in `regex'. Before @@ -395,32 +402,48 @@ typeset -A tbl cutoff pattern lookahead parse_action complete_action local regex index first last nullable local i state next - - funcname="$1" - shift - regex=("$@") - index=1 - tbl=() - pattern=() - lookahead=() - parse_action=() - complete_action=() - _ra_parse_alt - - if (( $? == 2 || index != $#regex + 1 )); then - if (( index != $#regex + 1 )); then - print "regex parse error at $index: $regex[index]" >&2 - else - print "regex parse error at $index (end)" >&2 + local cache_dir="${compconfig[regex_arguments_path]:-$HOME/.zsh/regex_arguments}" + local cache_file="$cache_dir/$1" + local cache_test + + if ! [[ -f "$cache_file" ]] || ! source "$cache_file" "$@"; then + cache_test='[[ $# -eq '$#' && "$*" = '"${*:q}"' ]]' + + funcname="$1" + shift + + regex=("$@") + index=1 + tbl=() + pattern=() + lookahead=() + parse_action=() + complete_action=() + _ra_parse_alt + + if (( $? == 2 || index != $#regex + 1 )); then + if (( index != $#regex + 1 )); then + print "regex parse error at $index: $regex[index]" >&2 + else + print "regex parse error at $index (end)" >&2 + fi + return 1 fi - return 1 - fi + + funcdef="$(_ra_gen_func)" - funcdef="$(_ra_gen_func)" + unfunction "$funcname" 2>/dev/null + eval "${(F)funcdef}" - unfunction "$funcname" 2>/dev/null - eval "${(F)funcdef}" + [[ -d "$cache_dir" && -w "$cache_dir" ]] && { + print -lr - \ + "if $cache_test; then" \ + "$funcdef" \ + 'true; else false; fi' > "${cache_file}.$HOST.$$" + mv "${cache_file}.$HOST.$$" "${cache_file}" + } + fi } _regex_arguments "$@" -- Tanaka Akira