aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStefan Monnier2024-01-23 22:30:13 -0500
committerStefan Monnier2024-01-23 22:30:13 -0500
commit33b8d5b6c5a22bab069cdac4bddda932b3d18b13 (patch)
tree9ebfcc61c0fb90681b89857a34a843591a6327ad /src
parent13c7249105ec0d1a070c6d4e9f73f3c21d905bc8 (diff)
downloademacs-33b8d5b6c5a22bab069cdac4bddda932b3d18b13.tar.gz
emacs-33b8d5b6c5a22bab069cdac4bddda932b3d18b13.zip
(struct charset): Remove dependency on hash-table internals
`struct charset` 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 value stored at that location in the hash-table, which saves us an indirection while at it. * src/charset.h (struct charset): Replace `hash_index` field with `attributes` field. (CHARSET_ATTRIBUTES): Simplify accordingly. (CHARSET_HASH_INDEX): Delete unused macro. * src/charset.c (Fdefine_charset_internal): * src/pdumper.c (dump_charset): Adjust accordingly. (dump_charset_table): Set the referrer since that's needed while dumping Lisp_Object fields.
Diffstat (limited to 'src')
-rw-r--r--src/charset.c25
-rw-r--r--src/charset.h7
-rw-r--r--src/pdumper.c13
3 files changed, 29 insertions, 16 deletions
diff --git a/src/charset.c b/src/charset.c
index f562af90cb2..9633ccaaef9 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -1108,18 +1108,18 @@ usage: (define-charset-internal ...) */)
1108 ASET (attrs, charset_plist, args[charset_arg_plist]); 1108 ASET (attrs, charset_plist, args[charset_arg_plist]);
1109 1109
1110 hash_hash_t hash_code; 1110 hash_hash_t hash_code;
1111 charset.hash_index = hash_lookup_get_hash (hash_table, args[charset_arg_name], 1111 ptrdiff_t hash_index
1112 &hash_code); 1112 = hash_lookup_get_hash (hash_table, args[charset_arg_name],
1113 if (charset.hash_index >= 0) 1113 &hash_code);
1114 if (hash_index >= 0)
1114 { 1115 {
1115 new_definition_p = 0; 1116 new_definition_p = false;
1116 id = XFIXNAT (CHARSET_SYMBOL_ID (args[charset_arg_name])); 1117 id = XFIXNAT (CHARSET_SYMBOL_ID (args[charset_arg_name]));
1117 set_hash_value_slot (hash_table, charset.hash_index, attrs); 1118 set_hash_value_slot (hash_table, hash_index, attrs);
1118 } 1119 }
1119 else 1120 else
1120 { 1121 {
1121 charset.hash_index = hash_put (hash_table, args[charset_arg_name], attrs, 1122 hash_put (hash_table, args[charset_arg_name], attrs, hash_code);
1122 hash_code);
1123 if (charset_table_used == charset_table_size) 1123 if (charset_table_used == charset_table_size)
1124 { 1124 {
1125 /* Ensure that charset IDs fit into 'int' as well as into the 1125 /* Ensure that charset IDs fit into 'int' as well as into the
@@ -1150,6 +1150,7 @@ usage: (define-charset-internal ...) */)
1150 1150
1151 ASET (attrs, charset_id, make_fixnum (id)); 1151 ASET (attrs, charset_id, make_fixnum (id));
1152 charset.id = id; 1152 charset.id = id;
1153 charset.attributes = attrs;
1153 charset_table[id] = charset; 1154 charset_table[id] = charset;
1154 1155
1155 if (charset.method == CHARSET_METHOD_MAP) 1156 if (charset.method == CHARSET_METHOD_MAP)
@@ -2269,6 +2270,16 @@ See also `charset-priority-list' and `set-charset-priority'. */)
2269 return charsets; 2270 return charsets;
2270} 2271}
2271 2272
2273/* Not strictly necessary, because all charset attributes are also
2274 reachable from `Vcharset_hash_table`.
2275void
2276mark_charset (void)
2277{
2278 for (int i = 0; i < charset_table_used; i++)
2279 mark_object (charset_table[i].attributes);
2280}
2281*/
2282
2272 2283
2273void 2284void
2274init_charset (void) 2285init_charset (void)
diff --git a/src/charset.h b/src/charset.h
index ba83cd5ccb2..1edb4a248ac 100644
--- a/src/charset.h
+++ b/src/charset.h
@@ -150,8 +150,7 @@ struct charset
150 /* Index to charset_table. */ 150 /* Index to charset_table. */
151 int id; 151 int id;
152 152
153 /* Index to Vcharset_hash_table. */ 153 Lisp_Object attributes;
154 ptrdiff_t hash_index;
155 154
156 /* Dimension of the charset: 1, 2, 3, or 4. */ 155 /* Dimension of the charset: 1, 2, 3, or 4. */
157 int dimension; 156 int dimension;
@@ -289,11 +288,9 @@ extern int emacs_mule_charset[256];
289 hash_lookup (XHASH_TABLE (Vcharset_hash_table), symbol) 288 hash_lookup (XHASH_TABLE (Vcharset_hash_table), symbol)
290 289
291/* Return the attribute vector of CHARSET. */ 290/* Return the attribute vector of CHARSET. */
292#define CHARSET_ATTRIBUTES(charset) \ 291#define CHARSET_ATTRIBUTES(charset) (charset)->attributes
293 HASH_VALUE (XHASH_TABLE (Vcharset_hash_table), (charset)->hash_index)
294 292
295#define CHARSET_ID(charset) ((charset)->id) 293#define CHARSET_ID(charset) ((charset)->id)
296#define CHARSET_HASH_INDEX(charset) ((charset)->hash_index)
297#define CHARSET_DIMENSION(charset) ((charset)->dimension) 294#define CHARSET_DIMENSION(charset) ((charset)->dimension)
298#define CHARSET_CODE_SPACE(charset) ((charset)->code_space) 295#define CHARSET_CODE_SPACE(charset) ((charset)->code_space)
299#define CHARSET_CODE_LINEAR_P(charset) ((charset)->code_linear_p) 296#define CHARSET_CODE_LINEAR_P(charset) ((charset)->code_linear_p)
diff --git a/src/pdumper.c b/src/pdumper.c
index bff11ada02c..9c9a1ff382c 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -2650,9 +2650,11 @@ 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; charset.c 2653 /* Make sure key_and_value ends up in the same order; the `hash_index`
2654 relies on it by expecting hash table indices to stay constant 2654 field of `struct composition` relies on it by expecting hash table
2655 across the dump. */ 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`). */
2656 DOHASH (h, i) 2658 DOHASH (h, i)
2657 { 2659 {
2658 key_and_value[n++] = HASH_KEY (h, i); 2660 key_and_value[n++] = HASH_KEY (h, i);
@@ -3224,7 +3226,7 @@ dump_charset (struct dump_context *ctx, int cs_i)
3224 struct charset out; 3226 struct charset out;
3225 dump_object_start (ctx, &out, sizeof (out)); 3227 dump_object_start (ctx, &out, sizeof (out));
3226 DUMP_FIELD_COPY (&out, cs, id); 3228 DUMP_FIELD_COPY (&out, cs, id);
3227 DUMP_FIELD_COPY (&out, cs, hash_index); 3229 dump_field_lv (ctx, &out, cs, &cs->attributes, WEIGHT_NORMAL);
3228 DUMP_FIELD_COPY (&out, cs, dimension); 3230 DUMP_FIELD_COPY (&out, cs, dimension);
3229 memcpy (out.code_space, &cs->code_space, sizeof (cs->code_space)); 3231 memcpy (out.code_space, &cs->code_space, sizeof (cs->code_space));
3230 if (cs_i < charset_table_used && cs->code_space_mask) 3232 if (cs_i < charset_table_used && cs->code_space_mask)
@@ -3262,12 +3264,15 @@ dump_charset_table (struct dump_context *ctx)
3262 ctx->flags.pack_objects = true; 3264 ctx->flags.pack_objects = true;
3263 dump_align_output (ctx, DUMP_ALIGNMENT); 3265 dump_align_output (ctx, DUMP_ALIGNMENT);
3264 dump_off offset = ctx->offset; 3266 dump_off offset = ctx->offset;
3267 if (dump_set_referrer (ctx))
3268 ctx->current_referrer = build_string ("charset_table");
3265 /* We are dumping the entire table, not just the used slots, because 3269 /* We are dumping the entire table, not just the used slots, because
3266 otherwise when we restore from the pdump file, the actual size of 3270 otherwise when we restore from the pdump file, the actual size of
3267 the table will be smaller than charset_table_size, and we will 3271 the table will be smaller than charset_table_size, and we will
3268 crash if/when a new charset is defined. */ 3272 crash if/when a new charset is defined. */
3269 for (int i = 0; i < charset_table_size; ++i) 3273 for (int i = 0; i < charset_table_size; ++i)
3270 dump_charset (ctx, i); 3274 dump_charset (ctx, i);
3275 dump_clear_referrer (ctx);
3271 dump_emacs_reloc_to_dump_ptr_raw (ctx, &charset_table, offset); 3276 dump_emacs_reloc_to_dump_ptr_raw (ctx, &charset_table, offset);
3272 ctx->flags = old_flags; 3277 ctx->flags = old_flags;
3273 return offset; 3278 return offset;