]> git.eshelyaron.com Git - emacs.git/commitdiff
(struct composition): Remove dependency on hash-table internals
authorStefan Monnier <monnier@iro.umontreal.ca>
Wed, 24 Jan 2024 13:16:11 +0000 (08:16 -0500)
committerEshel Yaron <me@eshelyaron.com>
Wed, 24 Jan 2024 18:31:54 +0000 (19:31 +0100)
`struct composition` kept an index into the internal `key_and_value` array
of hash tables, which only worked because of details of how
hash-tables are handled.  Replace it with a reference to the
key stored at that location in the hash-table, which saves us an
indirection while at it.

* src/composite.h (struct composition): Replace `hash_index` with
the actual `key`.
(COMPOSITION_KEY): Simplify accordingly.
(mark_composite): Declare.
* src/composite.c (get_composition_id): Adjust accordingly.
(mark_composite): New function.

* src/charset.c (mark_charset): Uncomment.
* src/lisp.h (mark_charset): Declare.
* src/alloc.c (garbage_collect): Call `mark_charset` and `mark_composite`.
* src/pdumper.c (hash_table_contents): Remove invalid comment, since
compositions aren't dumped.

(cherry picked from commit cc861fc528b49fc459bb9a1e5054f5fd82e1b689)

src/alloc.c
src/charset.c
src/composite.c
src/composite.h
src/lisp.h
src/pdumper.c

index 2a1690d2cffeae94f8a986b3d70f28bb90e59922..ab31d21fb33783f3ea3ed16ffd1514fa7d2d3a70 100644 (file)
@@ -6594,6 +6594,8 @@ garbage_collect (void)
   mark_terminals ();
   mark_kboards ();
   mark_threads ();
+  mark_charset ();
+  mark_composite ();
   mark_profiler ();
 #ifdef HAVE_PGTK
   mark_pgtkterm ();
index 9633ccaaef900f173b73d634cefbe3be22ec556e..4bacc011e85def295af8f37a4fcc4df2f22f81df 100644 (file)
@@ -2271,14 +2271,13 @@ See also `charset-priority-list' and `set-charset-priority'.  */)
 }
 
 /* Not strictly necessary, because all charset attributes are also
-   reachable from `Vcharset_hash_table`.
+   reachable from `Vcharset_hash_table`.  */
 void
 mark_charset (void)
 {
   for (int i = 0; i < charset_table_used; i++)
     mark_object (charset_table[i].attributes);
 }
-*/
 
 \f
 void
index 0b78a78fa79d637f02257a1bef03077c5eac70da..111b1cea88b8a9ca5595f3331c029dd06356c3e2 100644 (file)
@@ -321,7 +321,7 @@ get_composition_id (ptrdiff_t charpos, ptrdiff_t bytepos, ptrdiff_t nchars,
   cmp = xmalloc (sizeof *cmp);
 
   cmp->method = method;
-  cmp->hash_index = hash_index;
+  cmp->key = key;
   cmp->glyph_len = glyph_len;
   cmp->offsets = xnmalloc (glyph_len, 2 * sizeof *cmp->offsets);
   cmp->font = NULL;
@@ -673,7 +673,7 @@ Lisp_Object
 composition_gstring_from_id (ptrdiff_t id)
 {
   struct Lisp_Hash_Table *h = XHASH_TABLE (gstring_hash_table);
-
+  /* FIXME: The stability of this value depends on the hash table internals!  */
   return HASH_VALUE (h, id);
 }
 
@@ -2148,6 +2148,16 @@ of the way buffer text is examined for matching one of the rules.  */)
 }
 
 \f
+/* Not strictly necessary, because all those "keys" are also
+   reachable from `composition_hash_table`.  */
+void
+mark_composite (void)
+{
+  for (int i = 0; i < n_compositions; i++)
+    mark_object (composition_table[i]->key);
+}
+
+
 void
 syms_of_composite (void)
 {
index 37f494d69e0ffb69fb4a53905551a56c03120196..4b412cea696934c88cc12c12f9c23955fac3de30 100644 (file)
@@ -84,8 +84,7 @@ composition_registered_p (Lisp_Object prop)
    ? XCDR (XCDR (XCDR (prop)))                 \
    : CONSP (prop) ? XCDR (prop) : Qnil)
 
-#define COMPOSITION_KEY(cmp)                                           \
-  HASH_KEY (XHASH_TABLE (composition_hash_table), (cmp)->hash_index)
+#define COMPOSITION_KEY(cmp) (cmp)->key
 
 /* Return the Nth glyph of composition specified by CMP.  CMP is a
    pointer to `struct composition'.  */
@@ -163,8 +162,8 @@ struct composition {
   /* Method of the composition.  */
   enum composition_method method;
 
-  /* Index to the composition hash table.  */
-  ptrdiff_t hash_index;
+  /* The key under which it's found in the composition hash table.  */
+  Lisp_Object key;
 
   /* For which font we have calculated the remaining members.  The
      actual type is device dependent.  */
@@ -200,6 +199,7 @@ extern bool find_composition (ptrdiff_t, ptrdiff_t, ptrdiff_t *, ptrdiff_t *,
 extern void update_compositions (ptrdiff_t, ptrdiff_t, int);
 extern void make_composition_value_copy (Lisp_Object);
 extern void syms_of_composite (void);
+extern void mark_composite (void);
 extern void compose_text (ptrdiff_t, ptrdiff_t, Lisp_Object, Lisp_Object,
                           Lisp_Object);
 
index 82ce367392e6c0a714e4e9d4a6de9405981815d6..eb0ee51d9f9feb4dd4c2f72d70fc76a818028c3d 100644 (file)
@@ -4073,6 +4073,7 @@ extern ptrdiff_t multibyte_chars_in_text (const unsigned char *, ptrdiff_t);
 extern void syms_of_character (void);
 
 /* Defined in charset.c.  */
+extern void mark_charset (void);
 extern void init_charset (void);
 extern void init_charset_once (void);
 extern void syms_of_charset (void);
index 7f1a78b4f2d79b70acf921f16f4a6c26c6897689..8907d25cc137a023cf902afb5b3fe35c9cb27f9d 100644 (file)
@@ -2650,11 +2650,6 @@ hash_table_contents (struct Lisp_Hash_Table *h)
                                                       * sizeof *key_and_value);
   ptrdiff_t n = 0;
 
-  /* Make sure key_and_value ends up in the same order; the `hash_index`
-     field of `struct composition` relies on it by expecting hash table
-     indices to stay constant across the dump.
-     FIXME: Remove such dependency on hash table internals (there might
-     be another one in `composition_gstring_from_id`).  */
   DOHASH (h, k, v)
     {
       key_and_value[n++] = k;