diff options
| author | Stefan Monnier | 2024-01-24 08:16:11 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2024-01-24 08:16:41 -0500 |
| commit | cc861fc528b49fc459bb9a1e5054f5fd82e1b689 (patch) | |
| tree | 40f6b9e42f1d3cc9c9396051b3f84bfefb993ae3 /src | |
| parent | 3018c6e7ba5d35b756aea5eed7f3981548a597b4 (diff) | |
| download | emacs-cc861fc528b49fc459bb9a1e5054f5fd82e1b689.tar.gz emacs-cc861fc528b49fc459bb9a1e5054f5fd82e1b689.zip | |
(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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/alloc.c | 2 | ||||
| -rw-r--r-- | src/charset.c | 3 | ||||
| -rw-r--r-- | src/composite.c | 14 | ||||
| -rw-r--r-- | src/composite.h | 8 | ||||
| -rw-r--r-- | src/lisp.h | 1 | ||||
| -rw-r--r-- | 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) | |||
| 6594 | mark_terminals (); | 6594 | mark_terminals (); |
| 6595 | mark_kboards (); | 6595 | mark_kboards (); |
| 6596 | mark_threads (); | 6596 | mark_threads (); |
| 6597 | mark_charset (); | ||
| 6598 | mark_composite (); | ||
| 6597 | mark_profiler (); | 6599 | mark_profiler (); |
| 6598 | #ifdef HAVE_PGTK | 6600 | #ifdef HAVE_PGTK |
| 6599 | mark_pgtkterm (); | 6601 | 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'. */) | |||
| 2271 | } | 2271 | } |
| 2272 | 2272 | ||
| 2273 | /* Not strictly necessary, because all charset attributes are also | 2273 | /* Not strictly necessary, because all charset attributes are also |
| 2274 | reachable from `Vcharset_hash_table`. | 2274 | reachable from `Vcharset_hash_table`. */ |
| 2275 | void | 2275 | void |
| 2276 | mark_charset (void) | 2276 | mark_charset (void) |
| 2277 | { | 2277 | { |
| 2278 | for (int i = 0; i < charset_table_used; i++) | 2278 | for (int i = 0; i < charset_table_used; i++) |
| 2279 | mark_object (charset_table[i].attributes); | 2279 | mark_object (charset_table[i].attributes); |
| 2280 | } | 2280 | } |
| 2281 | */ | ||
| 2282 | 2281 | ||
| 2283 | 2282 | ||
| 2284 | void | 2283 | 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, | |||
| 321 | cmp = xmalloc (sizeof *cmp); | 321 | cmp = xmalloc (sizeof *cmp); |
| 322 | 322 | ||
| 323 | cmp->method = method; | 323 | cmp->method = method; |
| 324 | cmp->hash_index = hash_index; | 324 | cmp->key = key; |
| 325 | cmp->glyph_len = glyph_len; | 325 | cmp->glyph_len = glyph_len; |
| 326 | cmp->offsets = xnmalloc (glyph_len, 2 * sizeof *cmp->offsets); | 326 | cmp->offsets = xnmalloc (glyph_len, 2 * sizeof *cmp->offsets); |
| 327 | cmp->font = NULL; | 327 | cmp->font = NULL; |
| @@ -673,7 +673,7 @@ Lisp_Object | |||
| 673 | composition_gstring_from_id (ptrdiff_t id) | 673 | composition_gstring_from_id (ptrdiff_t id) |
| 674 | { | 674 | { |
| 675 | struct Lisp_Hash_Table *h = XHASH_TABLE (gstring_hash_table); | 675 | struct Lisp_Hash_Table *h = XHASH_TABLE (gstring_hash_table); |
| 676 | 676 | /* FIXME: The stability of this value depends on the hash table internals! */ | |
| 677 | return HASH_VALUE (h, id); | 677 | return HASH_VALUE (h, id); |
| 678 | } | 678 | } |
| 679 | 679 | ||
| @@ -2148,6 +2148,16 @@ of the way buffer text is examined for matching one of the rules. */) | |||
| 2148 | } | 2148 | } |
| 2149 | 2149 | ||
| 2150 | 2150 | ||
| 2151 | /* Not strictly necessary, because all those "keys" are also | ||
| 2152 | reachable from `composition_hash_table`. */ | ||
| 2153 | void | ||
| 2154 | mark_composite (void) | ||
| 2155 | { | ||
| 2156 | for (int i = 0; i < n_compositions; i++) | ||
| 2157 | mark_object (composition_table[i]->key); | ||
| 2158 | } | ||
| 2159 | |||
| 2160 | |||
| 2151 | void | 2161 | void |
| 2152 | syms_of_composite (void) | 2162 | syms_of_composite (void) |
| 2153 | { | 2163 | { |
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) | |||
| 84 | ? XCDR (XCDR (XCDR (prop))) \ | 84 | ? XCDR (XCDR (XCDR (prop))) \ |
| 85 | : CONSP (prop) ? XCDR (prop) : Qnil) | 85 | : CONSP (prop) ? XCDR (prop) : Qnil) |
| 86 | 86 | ||
| 87 | #define COMPOSITION_KEY(cmp) \ | 87 | #define COMPOSITION_KEY(cmp) (cmp)->key |
| 88 | HASH_KEY (XHASH_TABLE (composition_hash_table), (cmp)->hash_index) | ||
| 89 | 88 | ||
| 90 | /* Return the Nth glyph of composition specified by CMP. CMP is a | 89 | /* Return the Nth glyph of composition specified by CMP. CMP is a |
| 91 | pointer to `struct composition'. */ | 90 | pointer to `struct composition'. */ |
| @@ -163,8 +162,8 @@ struct composition { | |||
| 163 | /* Method of the composition. */ | 162 | /* Method of the composition. */ |
| 164 | enum composition_method method; | 163 | enum composition_method method; |
| 165 | 164 | ||
| 166 | /* Index to the composition hash table. */ | 165 | /* The key under which it's found in the composition hash table. */ |
| 167 | ptrdiff_t hash_index; | 166 | Lisp_Object key; |
| 168 | 167 | ||
| 169 | /* For which font we have calculated the remaining members. The | 168 | /* For which font we have calculated the remaining members. The |
| 170 | actual type is device dependent. */ | 169 | actual type is device dependent. */ |
| @@ -200,6 +199,7 @@ extern bool find_composition (ptrdiff_t, ptrdiff_t, ptrdiff_t *, ptrdiff_t *, | |||
| 200 | extern void update_compositions (ptrdiff_t, ptrdiff_t, int); | 199 | extern void update_compositions (ptrdiff_t, ptrdiff_t, int); |
| 201 | extern void make_composition_value_copy (Lisp_Object); | 200 | extern void make_composition_value_copy (Lisp_Object); |
| 202 | extern void syms_of_composite (void); | 201 | extern void syms_of_composite (void); |
| 202 | extern void mark_composite (void); | ||
| 203 | extern void compose_text (ptrdiff_t, ptrdiff_t, Lisp_Object, Lisp_Object, | 203 | extern void compose_text (ptrdiff_t, ptrdiff_t, Lisp_Object, Lisp_Object, |
| 204 | Lisp_Object); | 204 | Lisp_Object); |
| 205 | 205 | ||
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); | |||
| 4073 | extern void syms_of_character (void); | 4073 | extern void syms_of_character (void); |
| 4074 | 4074 | ||
| 4075 | /* Defined in charset.c. */ | 4075 | /* Defined in charset.c. */ |
| 4076 | extern void mark_charset (void); | ||
| 4076 | extern void init_charset (void); | 4077 | extern void init_charset (void); |
| 4077 | extern void init_charset_once (void); | 4078 | extern void init_charset_once (void); |
| 4078 | extern void syms_of_charset (void); | 4079 | 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) | |||
| 2650 | * sizeof *key_and_value); | 2650 | * sizeof *key_and_value); |
| 2651 | ptrdiff_t n = 0; | 2651 | ptrdiff_t n = 0; |
| 2652 | 2652 | ||
| 2653 | /* Make sure key_and_value ends up in the same order; the `hash_index` | ||
| 2654 | field of `struct composition` relies on it by expecting hash table | ||
| 2655 | indices to stay constant across the dump. | ||
| 2656 | FIXME: Remove such dependency on hash table internals (there might | ||
| 2657 | be another one in `composition_gstring_from_id`). */ | ||
| 2658 | DOHASH (h, k, v) | 2653 | DOHASH (h, k, v) |
| 2659 | { | 2654 | { |
| 2660 | key_and_value[n++] = k; | 2655 | key_and_value[n++] = k; |