zsh-workers
 help / color / mirror / code / Atom feed
From: Tanaka Akira <akr@jaist.ac.jp>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: _regex_arguments use cache.
Date: 11 Sep 1999 17:51:42 +0900	[thread overview]
Message-ID: <rsqk8pxj0f5.fsf@crane.jaist.ac.jp> (raw)

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


                 reply	other threads:[~1999-09-11  8:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=rsqk8pxj0f5.fsf@crane.jaist.ac.jp \
    --to=akr@jaist.ac.jp \
    --cc=zsh-workers@sunsite.auc.dk \
    /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).