X-Git-Url: http://cgit.sxemacs.org/?p=gnus;a=blobdiff_plain;f=lisp%2Fregistry.el;h=5a35e1f0e8d1ba697e0b93defa29fe15b79c7a38;hp=27133db168ff5c9cf2d2b2924c456f9de555cbf3;hb=2c102003004f4fa3dd5fe1f56c66936f386c4359;hpb=3db33f4ceedbdbba5d08e4f0698449fbca97a51e diff --git a/lisp/registry.el b/lisp/registry.el index 27133db16..5a35e1f0e 100644 --- a/lisp/registry.el +++ b/lisp/registry.el @@ -110,13 +110,19 @@ (defvar registry-db-version 0.2 "The current version of the registry format.") +(eval ` (defclass registry-db (eieio-persistent) ((version :initarg :version :initform nil :type (or null float) :documentation "The registry version.") (max-size :initarg :max-size - ;; :initform most-positive-fixnum ;; see below + ;; EIEIO's :initform is not 100% compatible with CLOS in + ;; that if the form is an atom, it assumes it's constant + ;; value rather than an expression, so in order to get the value + ;; of `most-positive-fixnum', we need to use an + ;; expression that's not just a symbol. + :initform ,(symbol-value 'most-positive-fixnum) :type integer :custom integer :documentation "The maximum number of registry entries.") @@ -141,8 +147,7 @@ (data :initarg :data :type hash-table :documentation "The data hashtable."))) -;; Do this separately, since defclass doesn't allow expressions in :initform. -(oset-default 'registry-db max-size most-positive-fixnum) +) (defmethod initialize-instance :BEFORE ((this registry-db) slots) "Check whether a registry object needs to be upgraded." @@ -200,8 +205,8 @@ When CREATE is not nil, create the secondary index hashtable if needed." (when create (puthash tracksym (make-hash-table :size 800 :rehash-size 2.0 :test 'equal) - (oref db :tracker)) - (gethash tracksym (oref db :tracker)))))) + (oref db tracker)) + (gethash tracksym (oref db tracker)))))) (defmethod registry-lookup-secondary-value ((db registry-db) tracksym val &optional set) @@ -237,9 +242,9 @@ When SET is not nil, set it for VAL (use t for an empty list)." (defmethod registry-search ((db registry-db) &rest spec) "Search for SPEC across the registry-db THIS. -For example calling with :member '(a 1 2) will match entry '((a 3 1)). +For example calling with :member \\='(a 1 2) will match entry \\='((a 3 1)). Calling with :all t (any non-nil value) will match all. -Calling with :regex '\(a \"h.llo\") will match entry '((a \"hullo\" \"bye\"). +Calling with :regex \\='\(a \"h.llo\") will match entry \\='((a \"hullo\" \"bye\"). The test order is to check :all first, then :member, then :regex." (when db (let ((all (plist-get spec :all)) @@ -297,7 +302,7 @@ This is the key count of the `data' slot." (defmethod registry-full ((db registry-db)) "Checks if registry-db THIS is full." (>= (registry-size db) - (oref db :max-size))) + (oref db max-size))) (defmethod registry-insert ((db registry-db) key entry) "Insert ENTRY under KEY into the registry-db THIS. @@ -335,7 +340,7 @@ Errors out if the key exists already." (when (and (< 0 expected) (= 0 (mod count 1000))) (message "reindexing: %d of %d (%.2f%%)" - count expected (/ (* 100 count) expected))) + count expected (/ (* 100.0 count) expected))) (dolist (val (cdr-safe (assq tr v))) (let* ((value-keys (registry-lookup-secondary-value db tr val))) (push key value-keys) @@ -356,11 +361,12 @@ from the front of the list are deleted first. Returns the number of deleted entries." (let ((size (registry-size db)) - (target-size (- (oref db :max-size) - (* (oref db :max-size) - (oref db :prune-factor)))) + (target-size + (floor (- (oref db max-size) + (* (oref db max-size) + (oref db prune-factor))))) candidates) - (if (> size target-size) + (if (registry-full db) (progn (setq candidates (registry-collect-prune-candidates @@ -374,7 +380,7 @@ Returns the number of deleted entries." Proposes only entries without the :precious keys, and attempts to return LIMIT such candidates. If SORTFUNC is provided, sort entries first and return candidates from beginning of list." - (let* ((precious (oref db :precious)) + (let* ((precious (oref db precious)) (precious-p (lambda (entry-key) (cdr (memq (car entry-key) precious)))) (data (oref db data)) @@ -386,7 +392,7 @@ entries first and return candidates from beginning of list." ;; list of entry keys. (when sortfunc (setq candidates (sort candidates sortfunc))) - (delq nil (cl-subseq (mapcar #'car candidates) 0 limit)))) + (cl-subseq (mapcar #'car candidates) 0 (min limit (length candidates))))) (provide 'registry) ;;; registry.el ends here