emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: master daea9b3 1/2: Read mailcaps again only when necessary


From: Stefan Monnier
Subject: Re: master daea9b3 1/2: Read mailcaps again only when necessary
Date: Mon, 01 Nov 2021 17:31:56 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Lars Ingebrigtsen [2021-11-01 20:04:33] wrote:
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> That's pretty close to my suggestion to pass the hash-table as a second
>> arg, yes.
>
> Sort of something like:
>
> (setq mailcap-data
>       (file-refresh-if-changed
>        (or mailcap-data (make-instance 'file-data-cache
>                                        :file "/etc/mailcap"
>                                        :refresher #'mailcap-parse-file))))
>
> and then the data would be in
>
> (slot-value mailcap-data 'data)

I don't see any need to bring in EIEIO into this (remember that EIEIO
objects and operations are slow).

I was thinking more along the lines of

    (defun file-contents-attributes (file)
      (let ((a (file-attributes file)))
        ;; Stamp out data that will never reflect a change in the file.
        (setf (file-attribute-access-time a) nil)
        (setf (file-attribute-link-number a) nil)
        a))

    (defun file-unchanged-p (file cache)
      (unless (file-name-absolute-p file) (setq file (expand-file-name file)))
      (let ((old (gethash (cons file 'file-contents-attributes) cache))
            (new (file-contents-attributes file)))
        (if (equal old new)
            t
          (puthash (cons file 'file-contents-attributes) new cache)
          nil)))

    (defun mailcap-parse-file (file &optional cache)
      (unless (file-name-absolute-p file) (setq file (expand-file-name file)))
      (or (and cache
               (file-unchanged-p file cache)
               (gethash (cons file 'mailcap-parse-file) cache))
          (let ((data <do the actual parsing>))
            (when cache
              (puthash (cons file 'mailcap-parse-file) data cache))
            data)))


-- Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]