[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master cc861fc528b: (struct composition): Remove dependency on hash-tabl
From: |
Stefan Monnier |
Subject: |
master cc861fc528b: (struct composition): Remove dependency on hash-table internals |
Date: |
Wed, 24 Jan 2024 08:16:57 -0500 (EST) |
branch: master
commit cc861fc528b49fc459bb9a1e5054f5fd82e1b689
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
(struct composition): Remove dependency on hash-table internals
`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.
---
src/alloc.c | 2 ++
src/charset.c | 3 +--
src/composite.c | 14 ++++++++++++--
src/composite.h | 8 ++++----
src/lisp.h | 1 +
src/pdumper.c | 5 -----
6 files changed, 20 insertions(+), 13 deletions(-)
diff --git a/src/alloc.c b/src/alloc.c
index 2a1690d2cff..ab31d21fb33 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -6594,6 +6594,8 @@ garbage_collect (void)
mark_terminals ();
mark_kboards ();
mark_threads ();
+ mark_charset ();
+ mark_composite ();
mark_profiler ();
#ifdef HAVE_PGTK
mark_pgtkterm ();
diff --git a/src/charset.c b/src/charset.c
index 9633ccaaef9..4bacc011e85 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -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);
}
-*/
void
diff --git a/src/composite.c b/src/composite.c
index 0b78a78fa79..111b1cea88b 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -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. */)
}
+/* 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)
{
diff --git a/src/composite.h b/src/composite.h
index 37f494d69e0..4b412cea696 100644
--- a/src/composite.h
+++ b/src/composite.h
@@ -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);
diff --git a/src/lisp.h b/src/lisp.h
index 82ce367392e..eb0ee51d9f9 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -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);
diff --git a/src/pdumper.c b/src/pdumper.c
index 7f1a78b4f2d..8907d25cc13 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -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;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master cc861fc528b: (struct composition): Remove dependency on hash-table internals,
Stefan Monnier <=