[Cl-darcs-cvs] r88 - cl-darcs/trunk
mhenoch at common-lisp.net
mhenoch at common-lisp.net
Thu Feb 15 04:00:30 UTC 2007
Author: mhenoch
Date: Wed Feb 14 23:00:30 2007
New Revision: 88
Modified:
cl-darcs/trunk/util.lisp
Log:
Combine regexps into one to reduce memory use.
Modified: cl-darcs/trunk/util.lisp
==============================================================================
--- cl-darcs/trunk/util.lisp (original)
+++ cl-darcs/trunk/util.lisp Wed Feb 14 23:00:30 2007
@@ -287,13 +287,23 @@
(defun matches-one-of (regexps string)
"Return true if some of REGEXPS match STRING.
Cache scanners for faster execution beyond first time."
- (dolist (regexp regexps)
- (let ((scanner (or
- (gethash regexp *scanner-cache*)
- (setf (gethash regexp *scanner-cache*)
- (cl-ppcre:create-scanner regexp)))))
- (when (cl-ppcre:scan scanner string)
- (return t)))))
+ ;; These scanners use _a lot_ of memory, so we build just one, and
+ ;; hope that the exact combination of regexps will be used often
+ ;; enough.
+ (setq regexps (sort (copy-seq regexps) #'string>))
+ (let* ((combined-regexp
+ (apply
+ #'concatenate 'string
+ (loop for regexp in regexps
+ for n upfrom 0
+ unless (zerop n) collect "|"
+ collect regexp)))
+ (scanner (or
+ (gethash combined-regexp *scanner-cache*)
+ (setf (gethash combined-regexp *scanner-cache*)
+ (cl-ppcre:create-scanner combined-regexp)))))
+ (when (cl-ppcre:scan scanner string)
+ t)))
(defun file-binary-p (repo filename)
"Return true if FILENAME names a binary file.
More information about the Cl-darcs-cvs
mailing list