style: use hash_xinsert

* gnulib: Update to get hash_xinsert.
Use it where appropriate.
This commit is contained in:
Akim Demaille
2020-05-17 12:00:02 +02:00
parent ac3b6c18a5
commit 4590071287
8 changed files with 22 additions and 34 deletions

2
gnulib

Submodule gnulib updated: c8b9cf33a9...6f3f39926b

View File

@@ -680,8 +680,7 @@ ssb_append (search_state *ss)
search_state_free (ss); search_state_free (ss);
return; return;
} }
if (!hash_insert (visited, ss)) hash_xinsert (visited, ss);
xalloc_die ();
// if states are only referenced by the visited set, // if states are only referenced by the visited set,
// their contents should be freed as we only need // their contents should be freed as we only need
// the metadata necessary to compute a hash. // the metadata necessary to compute a hash.

View File

@@ -91,8 +91,7 @@ append_lssi (lssi *sn, Hash_table *visited, gl_list_t queue)
lssi_free (sn); lssi_free (sn);
return false; return false;
} }
if (!hash_insert (visited, sn)) hash_xinsert (visited, sn);
xalloc_die ();
gl_list_add_last (queue, sn); gl_list_add_last (queue, sn);
return true; return true;
} }

View File

@@ -107,8 +107,7 @@ muscle_entry_new (char const *key)
res->key = key; res->key = key;
res->value = NULL; res->value = NULL;
res->storage = NULL; res->storage = NULL;
if (!hash_insert (muscle_table, res)) hash_xinsert (muscle_table, res);
xalloc_die ();
return res; return res;
} }

View File

@@ -82,8 +82,7 @@ hash_pair_insert (Hash_table *tab, int key, bitset val)
hash_pair *hp = xmalloc (sizeof (hash_pair)); hash_pair *hp = xmalloc (sizeof (hash_pair));
hp->key = key; hp->key = key;
hp->l = val; hp->l = val;
if (!hash_insert (tab, hp)) hash_xinsert (tab, hp);
xalloc_die ();
} }
static void static void
@@ -211,8 +210,7 @@ init_trans (void)
(Hash_comparator) state_sym_comparator, NULL); (Hash_comparator) state_sym_comparator, NULL);
for (int j = 0; j < t->num; ++j) for (int j = 0; j < t->num; ++j)
if (!TRANSITION_IS_DISABLED (t, j)) if (!TRANSITION_IS_DISABLED (t, j))
if (!hash_insert (transition_set, t->states[j])) hash_xinsert (transition_set, t->states[j]);
xalloc_die ();
for (int j = state_item_map[i]; j < state_item_map[i + 1]; ++j) for (int j = state_item_map[i]; j < state_item_map[i + 1]; ++j)
{ {
item_number *item = state_items[j].item; item_number *item = state_items[j].item;
@@ -298,11 +296,10 @@ init_prods (void)
hash_pair *prod_hp = xmalloc (sizeof (hash_pair)); hash_pair *prod_hp = xmalloc (sizeof (hash_pair));
prod_hp->key = j; prod_hp->key = j;
prod_hp->l = copy; prod_hp->l = copy;
//update prods // update prods.
if (!hash_insert (si_prods, prod_hp)) hash_xinsert (si_prods, prod_hp);
xalloc_die ();
//update revs // update revs.
bitset_iterator biter; bitset_iterator biter;
state_item_number prod; state_item_number prod;
BITSET_FOR_EACH (biter, copy, prod, 0) BITSET_FOR_EACH (biter, copy, prod, 0)

View File

@@ -385,8 +385,7 @@ state_hash_free (void)
void void
state_hash_insert (state *s) state_hash_insert (state *s)
{ {
if (!hash_insert (state_table, s)) hash_xinsert (state_table, s);
xalloc_die ();
} }

View File

@@ -887,17 +887,16 @@ symbol_from_uniqstr (const uniqstr key, location loc)
symbol probe; symbol probe;
probe.tag = key; probe.tag = key;
symbol *entry = hash_lookup (symbol_table, &probe); symbol *res = hash_lookup (symbol_table, &probe);
if (!entry) if (!res)
{ {
/* First insertion in the hash. */ /* First insertion in the hash. */
aver (!symbols_sorted); aver (!symbols_sorted);
entry = symbol_new (key, loc); res = symbol_new (key, loc);
if (!hash_insert (symbol_table, entry)) hash_xinsert (symbol_table, res);
xalloc_die ();
} }
return entry; return res;
} }
@@ -912,16 +911,15 @@ semantic_type_from_uniqstr (const uniqstr key, const location *loc)
semantic_type probe; semantic_type probe;
probe.tag = key; probe.tag = key;
semantic_type *entry = hash_lookup (semantic_type_table, &probe); semantic_type *res = hash_lookup (semantic_type_table, &probe);
if (!entry) if (!res)
{ {
/* First insertion in the hash. */ /* First insertion in the hash. */
entry = semantic_type_new (key, loc); res = semantic_type_new (key, loc);
if (!hash_insert (semantic_type_table, entry)) hash_xinsert (semantic_type_table, res);
xalloc_die ();
} }
return entry; return res;
} }

View File

@@ -50,8 +50,7 @@ uniqstr_new (char const *str)
{ {
/* First insertion in the hash. */ /* First insertion in the hash. */
res = xstrdup (str); res = xstrdup (str);
if (!hash_insert (uniqstrs_table, res)) hash_xinsert (uniqstrs_table, res);
xalloc_die ();
} }
return res; return res;
} }
@@ -81,9 +80,7 @@ uniqstr_concat (int nargs, ...)
va_end (args); va_end (args);
*p = '\0'; *p = '\0';
uniqstr res = hash_insert (uniqstrs_table, str); uniqstr res = hash_xinsert (uniqstrs_table, str);
if (!res)
xalloc_die ();
if (res != str) if (res != str)
free (str); free (str);
return res; return res;