emacs-devel
[Top][All Lists]
Advanced

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

multi-eq hash tables


From: Stefan Monnier
Subject: multi-eq hash tables
Date: Tue, 03 May 2022 14:12:40 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

> -(defconst tool-bar-keymap-cache (make-hash-table))
> +(defconst tool-bar-keymap-cache (make-hash-table :test #'equal))
> +
> +(defun tool-bar--cache-key ()
> +  (cons (frame-terminal) (sxhash-eq tool-bar-map)))

I've seen such needs in the past.
Maybe we should introduce something like:

    (define-hash-table-test shallow-equal
      (lambda (x1 x2) (while (and (consp x1) (consp x2) (eql (car x1) (car x2)))
                        (setq x1 (cdr x1)) (setq x2 (cdr x2)))
                      (equal x1 x2)))
      ...)

and we could even improve the weakness support so that `key` used with
such a hashtable would mean that as soon as one of the values in the
key's list can be GC'd then the entry is removed.

This way we could have our hash table such that entries are flushed by
the GC when a terminal disappears or when one of the tool-bar-map
objects dies (instead of the current code which prevents us from GC'ing
the terminal objects and the old tool bar maps).


        Stefan




reply via email to

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