summaryrefslogtreecommitdiff
path: root/lisp/play/cookie1.el
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1993-07-14 23:36:04 +0000
committerRoland McGrath <roland@gnu.org>1993-07-14 23:36:04 +0000
commit4054367c9e9ea0507f50db4874ee6f78f817a67e (patch)
tree6609f3aa9c485baa42c8a5885845062a9ec4fb08 /lisp/play/cookie1.el
parent1265394fdd21cb462e087c3cf6d671b072ab6f70 (diff)
downloademacs-4054367c9e9ea0507f50db4874ee6f78f817a67e.tar.gz
(cookie-cache): New defvar.
(cookie-snarf): Cache cookies in `cookie-cache', not in obarray (idiot). Also store the modtime and punt the cache when it changes.
Diffstat (limited to 'lisp/play/cookie1.el')
-rw-r--r--lisp/play/cookie1.el45
1 files changed, 28 insertions, 17 deletions
diff --git a/lisp/play/cookie1.el b/lisp/play/cookie1.el
index e07b08c32f3..aa767ed8f4e 100644
--- a/lisp/play/cookie1.el
+++ b/lisp/play/cookie1.el
@@ -60,6 +60,9 @@
(defconst cookie-delimiter "\n%%\n\\|\0"
"Delimiter used to separate cookie file entries.")
+(defvar cookie-cache (make-vector 511 0)
+ "Cache of cookie files that have already been snarfed.")
+
(defun cookie (phrase-file startmsg endmsg)
"Return a random phrase from PHRASE-FILE. When the phrase file
is read in, display STARTMSG at beginning of load, ENDMSG at end."
@@ -89,23 +92,31 @@ is read in, display STARTMSG at beginning of load, ENDMSG at end."
"Reads in the PHRASE-FILE, returns it as a vector of strings. Emit
STARTMSG and ENDMSG before and after. Caches the result; second and
subsequent calls on the same file won't go to disk."
- (if (boundp (intern phrase-file))
- (eval (intern phrase-file))
- (message startmsg)
- (save-excursion
- (let ((buf (generate-new-buffer "*cookie*"))
- (result nil))
- (set-buffer buf)
- (insert-file-contents (expand-file-name phrase-file))
- (re-search-forward cookie-delimiter)
- (while (progn (skip-chars-forward " \t\n\r\f") (not (eobp)))
- (let ((beg (point)))
- (re-search-forward cookie-delimiter)
- (setq result (cons (buffer-substring beg (1- (point)))
- result))))
- (kill-buffer buf)
- (message endmsg)
- (set (intern phrase-file) (apply 'vector result))))))
+ (let ((sym (intern-soft phrase-file cookie-cache)))
+ (and sym (not (equal (symbol-function sym)
+ (nth 5 (file-attributes phrase-file))))
+ (yes-or-no-p (concat phrase-file
+ " has changed. Read new contents? "))
+ (setq sym nil))
+ (if sym
+ (symbol-value sym)
+ (setq sym (intern phrase-file cookie-cache))
+ (message startmsg)
+ (save-excursion
+ (let ((buf (generate-new-buffer "*cookie*"))
+ (result nil))
+ (set-buffer buf)
+ (fset sym (nth 5 (file-attributes phrase-file)))
+ (insert-file-contents (expand-file-name phrase-file))
+ (re-search-forward cookie-delimiter)
+ (while (progn (skip-chars-forward " \t\n\r\f") (not (eobp)))
+ (let ((beg (point)))
+ (re-search-forward cookie-delimiter)
+ (setq result (cons (buffer-substring beg (1- (point)))
+ result))))
+ (kill-buffer buf)
+ (message endmsg)
+ (set sym (apply 'vector result)))))))
(defun pick-random (n)
"Returns a random number from 0 to N-1 inclusive."