declare_block (Qentry);
Lisp_Object blocks = CALL1I (comp-func-blocks, func);
struct Lisp_Hash_Table *ht = XHASH_TABLE (blocks);
- for (ptrdiff_t i = 0; i < HASH_TABLE_SIZE (ht); i++)
+ DOHASH (ht, i)
{
Lisp_Object block_name = HASH_KEY (ht, i);
- if (!EQ (block_name, Qentry)
- && !hash_unused_entry_key_p (block_name))
+ if (!EQ (block_name, Qentry))
declare_block (block_name);
}
gcc_jit_lvalue_as_rvalue (comp.func_relocs));
- for (ptrdiff_t i = 0; i < HASH_TABLE_SIZE (ht); i++)
+ DOHASH (ht, i)
{
Lisp_Object block_name = HASH_KEY (ht, i);
- if (!hash_unused_entry_key_p (block_name))
+ Lisp_Object block = HASH_VALUE (ht, i);
+ Lisp_Object insns = CALL1I (comp-block-insns, block);
+ if (NILP (block) || NILP (insns))
+ xsignal1 (Qnative_ice,
+ build_string ("basic block is missing or empty"));
+
+ comp.block = retrive_block (block_name);
+ while (CONSP (insns))
{
- Lisp_Object block = HASH_VALUE (ht, i);
- Lisp_Object insns = CALL1I (comp-block-insns, block);
- if (NILP (block) || NILP (insns))
- xsignal1 (Qnative_ice,
- build_string ("basic block is missing or empty"));
-
- comp.block = retrive_block (block_name);
- while (CONSP (insns))
- {
- Lisp_Object insn = XCAR (insns);
- emit_limple_insn (insn);
- insns = XCDR (insns);
- }
+ Lisp_Object insn = XCAR (insns);
+ emit_limple_insn (insn);
+ insns = XCDR (insns);
}
}
const char *err = gcc_jit_context_get_first_error (comp.ctxt);
struct Lisp_Hash_Table *func_h =
XHASH_TABLE (CALL1I (comp-ctxt-funcs-h, Vcomp_ctxt));
- for (ptrdiff_t i = 0; i < HASH_TABLE_SIZE (func_h); i++)
- if (!hash_unused_entry_key_p (HASH_KEY (func_h, i)))
- declare_function (HASH_VALUE (func_h, i));
+ DOHASH (func_h, i) declare_function (HASH_VALUE (func_h, i));
/* Compile all functions. Can't be done before because the
relocation structs has to be already defined. */
- for (ptrdiff_t i = 0; i < HASH_TABLE_SIZE (func_h); i++)
- if (!hash_unused_entry_key_p (HASH_KEY (func_h, i)))
- compile_function (HASH_VALUE (func_h, i));
+ DOHASH (func_h, i) compile_function (HASH_VALUE (func_h, i));
/* Work around bug#46495 (GCC PR99126). */
#if defined (WIDE_EMACS_INT) \
{
struct Lisp_Hash_Table *h = XHASH_TABLE (gstring_hash_table);
- for (ptrdiff_t i = 0; i < HASH_TABLE_SIZE (h); ++i)
+ DOHASH (h, i)
{
Lisp_Object k = HASH_KEY (h, i);
+ Lisp_Object gstring = HASH_VALUE (h, i);
- if (!hash_unused_entry_key_p (k))
- {
- Lisp_Object gstring = HASH_VALUE (h, i);
-
- if (EQ (LGSTRING_FONT (gstring), font_object))
- hash_remove_from_table (h, k);
- }
+ if (EQ (LGSTRING_FONT (gstring), font_object))
+ hash_remove_from_table (h, k);
}
}
struct Lisp_Hash_Table *h = XHASH_TABLE (Vmodule_refs_hash);
/* Note that we can't use `hash_lookup' because V might be a local
reference that's identical to some global reference. */
- for (ptrdiff_t i = 0; i < HASH_TABLE_SIZE (h); ++i)
- {
- if (!hash_unused_entry_key_p (HASH_KEY (h, i))
- && &XMODULE_GLOBAL_REFERENCE (HASH_VALUE (h, i))->value == v)
- return true;
- }
+ DOHASH (h, i)
+ if (&XMODULE_GLOBAL_REFERENCE (HASH_VALUE (h, i))->value == v)
+ return true;
/* Only used for debugging, so we don't care about overflow, just
make sure the operation is defined. */
ckd_add (n, *n, h->count);
(Lisp_Object function, Lisp_Object table)
{
struct Lisp_Hash_Table *h = check_hash_table (table);
-
- for (ptrdiff_t i = 0; i < HASH_TABLE_SIZE (h); ++i)
- {
- Lisp_Object k = HASH_KEY (h, i);
- if (!hash_unused_entry_key_p (k))
- call2 (function, k, HASH_VALUE (h, i));
- }
-
+ DOHASH (h, i) call2 (function, HASH_KEY (h, i), HASH_VALUE (h, i));
return Qnil;
}
json = json_check (json_object ());
count = SPECPDL_INDEX ();
record_unwind_protect_ptr (json_release_object, json);
- for (ptrdiff_t i = 0; i < HASH_TABLE_SIZE (h); ++i)
+ DOHASH (h, i)
{
Lisp_Object key = HASH_KEY (h, i);
- if (!hash_unused_entry_key_p (key))
- {
- CHECK_STRING (key);
- Lisp_Object ekey = json_encode (key);
- /* We can't specify the length, so the string must be
- null-terminated. */
- check_string_without_embedded_nulls (ekey);
- const char *key_str = SSDATA (ekey);
- /* Reject duplicate keys. These are possible if the hash
- table test is not `equal'. */
- if (json_object_get (json, key_str) != NULL)
- wrong_type_argument (Qjson_value_p, lisp);
- int status
- = json_object_set_new (json, key_str,
- lisp_to_json (HASH_VALUE (h, i), conf));
- if (status == -1)
- {
- /* A failure can be caused either by an invalid key or
- by low memory. */
- json_check_utf8 (ekey);
- json_out_of_memory ();
- }
- }
- }
+ CHECK_STRING (key);
+ Lisp_Object ekey = json_encode (key);
+ /* We can't specify the length, so the string must be
+ null-terminated. */
+ check_string_without_embedded_nulls (ekey);
+ const char *key_str = SSDATA (ekey);
+ /* Reject duplicate keys. These are possible if the hash
+ table test is not `equal'. */
+ if (json_object_get (json, key_str) != NULL)
+ wrong_type_argument (Qjson_value_p, lisp);
+ int status
+ = json_object_set_new (json, key_str,
+ lisp_to_json (HASH_VALUE (h, i), conf));
+ if (status == -1)
+ {
+ /* A failure can be caused either by an invalid key or
+ by low memory. */
+ json_check_utf8 (ekey);
+ json_out_of_memory ();
+ }
+ }
}
else if (NILP (lisp))
return json_check (json_object ());
return h->test->hashfn (key, h);
}
+/* Hash table iteration construct (roughly an inlined maphash):
+ Iterate IDXVAR as index over valid entries of TABLE.
+ The body may remove the current entry or alter its value slot, but not
+ mutate TABLE in any other way. */
+#define DOHASH(TABLE, IDXVAR) \
+ for (ptrdiff_t IDXVAR = 0; IDXVAR < (TABLE)->table_size; IDXVAR++) \
+ if (!hash_unused_entry_key_p (HASH_KEY (TABLE, IDXVAR)))
+
void hash_table_thaw (Lisp_Object hash_table);
/* Default size for hash tables if not specified. */
goto found_matching_key;
}
else
- for (i = 0; i < HASH_TABLE_SIZE (h); ++i)
+ DOHASH (h, j)
{
+ i = j;
tem = HASH_KEY (h, i);
- if (hash_unused_entry_key_p (tem)) continue;
Lisp_Object strkey = (SYMBOLP (tem) ? Fsymbol_name (tem) : tem);
if (!STRINGP (strkey)) continue;
if (BASE_EQ (Fcompare_strings (string, Qnil, Qnil,
{ /* Remove unnecessary objects, which appear only once in OBJ;
that is, whose status is Qt. */
struct Lisp_Hash_Table *h = XHASH_TABLE (Vprint_number_table);
- ptrdiff_t i;
-
- for (i = 0; i < HASH_TABLE_SIZE (h); ++i)
- {
- Lisp_Object key = HASH_KEY (h, i);
- if (!hash_unused_entry_key_p (key)
- && EQ (HASH_VALUE (h, i), Qt))
- Fremhash (key, Vprint_number_table);
- }
+ DOHASH (h, i)
+ if (EQ (HASH_VALUE (h, i), Qt))
+ Fremhash (HASH_KEY (h, i), Vprint_number_table);
}
}