registry.el (registry-db): Temporary fix old Emacsen compilation
[gnus] / lisp / registry.el
index 45bfa07..ef076a5 100644 (file)
 (defvar registry-db-version 0.2
   "The current version of the registry format.")
 
+(eval (backquote
 (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.")
    (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."
 (defmethod registry-lookup ((db registry-db) keys)
   "Search for KEYS in the registry-db THIS.
 Returns an alist of the key followed by the entry in a list, not a cons cell."
-  (let ((data (oref db :data)))
+  (let ((data (oref db data)))
     (delq nil
          (mapcar
           (lambda (k)
@@ -184,7 +189,7 @@ Returns an alist of the key followed by the entry in a list, not a cons cell."
 (defmethod registry-lookup-breaks-before-lexbind ((db registry-db) keys)
   "Search for KEYS in the registry-db THIS.
 Returns an alist of the key followed by the entry in a list, not a cons cell."
-  (let ((data (oref db :data)))
+  (let ((data (oref db data)))
     (delq nil
          (loop for key in keys
                when (gethash key data)
@@ -245,7 +250,7 @@ The test order is to check :all first, then :member, then :regex."
     (let ((all (plist-get spec :all))
          (member (plist-get spec :member))
          (regex (plist-get spec :regex)))
-      (loop for k being the hash-keys of (oref db :data)
+      (loop for k being the hash-keys of (oref db data)
            using (hash-values v)
            when (or
                  ;; :all non-nil returns all
@@ -261,10 +266,10 @@ The test order is to check :all first, then :member, then :regex."
 If KEYS is nil, use SPEC to do a search.
 Updates the secondary ('tracked') indices as well.
 With assert non-nil, errors out if the key does not exist already."
-  (let* ((data (oref db :data))
+  (let* ((data (oref db data))
         (keys (or keys
                   (apply 'registry-search db spec)))
-        (tracked (oref db :tracked)))
+        (tracked (oref db tracked)))
 
     (dolist (key keys)
       (let ((entry (gethash key data)))
@@ -291,8 +296,8 @@ With assert non-nil, errors out if the key does not exist already."
 
 (defmethod registry-size ((db registry-db))
   "Returns the size of the registry-db object THIS.
-This is the key count of the :data slot."
-  (hash-table-count (oref db :data)))
+This is the key count of the `data' slot."
+  (hash-table-count (oref db data)))
 
 (defmethod registry-full ((db registry-db))
   "Checks if registry-db THIS is full."
@@ -304,7 +309,7 @@ This is the key count of the :data slot."
 Updates the secondary ('tracked') indices as well.
 Errors out if the key exists already."
 
-  (assert (not (gethash key (oref db :data))) nil
+  (assert (not (gethash key (oref db data))) nil
          "Key already exists in database")
 
   (assert (not (registry-full db))
@@ -312,10 +317,10 @@ Errors out if the key exists already."
          "registry max-size limit reached")
 
   ;; store the entry
-  (puthash key entry (oref db :data))
+  (puthash key entry (oref db data))
 
   ;; store the secondary indices
-  (dolist (tr (oref db :tracked))
+  (dolist (tr (oref db tracked))
     ;; for every value in the entry under that key...
     (dolist (val (cdr-safe (assq tr entry)))
       (let* ((value-keys (registry-lookup-secondary-value db tr val)))
@@ -326,8 +331,8 @@ Errors out if the key exists already."
 (defmethod registry-reindex ((db registry-db))
   "Rebuild the secondary indices of registry-db THIS."
   (let ((count 0)
-       (expected (* (length (oref db :tracked)) (registry-size db))))
-    (dolist (tr (oref db :tracked))
+       (expected (* (length (oref db tracked)) (registry-size db))))
+    (dolist (tr (oref db tracked))
       (let (values)
        (maphash
         (lambda (key v)
@@ -340,7 +345,7 @@ Errors out if the key exists already."
             (let* ((value-keys (registry-lookup-secondary-value db tr val)))
               (push key value-keys)
               (registry-lookup-secondary-value db tr val value-keys))))
-        (oref db :data))))))
+        (oref db data))))))
 
 (defmethod registry-prune ((db registry-db) &optional sortfunc)
   "Prunes the registry-db object DB.
@@ -377,7 +382,7 @@ entries first and return candidates from beginning of list."
   (let* ((precious (oref db :precious))
         (precious-p (lambda (entry-key)
                       (cdr (memq (car entry-key) precious))))
-        (data (oref db :data))
+        (data (oref db data))
         (candidates (cl-loop for k being the hash-keys of data
                              using (hash-values v)
                              when (notany precious-p v)