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);
return;
}
if (!hash_insert (visited, ss))
xalloc_die ();
hash_xinsert (visited, ss);
// if states are only referenced by the visited set,
// their contents should be freed as we only need
// 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);
return false;
}
if (!hash_insert (visited, sn))
xalloc_die ();
hash_xinsert (visited, sn);
gl_list_add_last (queue, sn);
return true;
}

View File

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

View File

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

View File

@@ -887,17 +887,16 @@ symbol_from_uniqstr (const uniqstr key, location loc)
symbol probe;
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. */
aver (!symbols_sorted);
entry = symbol_new (key, loc);
if (!hash_insert (symbol_table, entry))
xalloc_die ();
res = symbol_new (key, loc);
hash_xinsert (symbol_table, res);
}
return entry;
return res;
}
@@ -912,16 +911,15 @@ semantic_type_from_uniqstr (const uniqstr key, const location *loc)
semantic_type probe;
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. */
entry = semantic_type_new (key, loc);
if (!hash_insert (semantic_type_table, entry))
xalloc_die ();
res = semantic_type_new (key, loc);
hash_xinsert (semantic_type_table, res);
}
return entry;
return res;
}

View File

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