summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip@tecnocode.co.uk>2022-12-19 09:24:30 +0000
committerPhilip Withnall <philip@tecnocode.co.uk>2022-12-19 09:24:30 +0000
commitba90e9ab2250fa894d4fc6e7784bb8e8572c264e (patch)
treec8d4b4e6f55ffa8b5f657ea064a1ffe3c153741a
parent3ec55201d052cc832023bc846459721c3a583f8b (diff)
parent8465c1a05593434aa24a8ab9a0e8e023ce3967d2 (diff)
downloadglib-ba90e9ab2250fa894d4fc6e7784bb8e8572c264e.tar.gz
Merge branch 'ghash-unsigned-nnodes' into 'main'
ghash: Use unsigned types for number of nodes and occupied ones See merge request GNOME/glib!3148
-rw-r--r--glib/ghash.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/glib/ghash.c b/glib/ghash.c
index 64edc0a34..132e3ac5e 100644
--- a/glib/ghash.c
+++ b/glib/ghash.c
@@ -260,8 +260,8 @@ struct _GHashTable
gsize size;
gint mod;
guint mask;
- gint nnodes;
- gint noccupied; /* nnodes + tombstones */
+ guint nnodes;
+ guint noccupied; /* nnodes + tombstones */
guint have_big_keys : 1;
guint have_big_values : 1;
@@ -548,6 +548,7 @@ g_hash_table_remove_node (GHashTable *hash_table,
g_hash_table_assign_key_or_value (hash_table->keys, i, hash_table->have_big_keys, NULL);
g_hash_table_assign_key_or_value (hash_table->values, i, hash_table->have_big_values, NULL);
+ g_assert (hash_table->nnodes > 0);
hash_table->nnodes--;
if (notify && hash_table->key_destroy_func)
@@ -909,8 +910,8 @@ g_hash_table_resize (GHashTable *hash_table)
static inline void
g_hash_table_maybe_resize (GHashTable *hash_table)
{
- gint noccupied = hash_table->noccupied;
- gint size = hash_table->size;
+ gsize noccupied = hash_table->noccupied;
+ gsize size = hash_table->size;
if ((size > hash_table->nnodes * 4 && size > 1 << HASH_TABLE_MIN_SHIFT) ||
(size <= noccupied + (noccupied / 16)))
@@ -2338,7 +2339,7 @@ g_hash_table_get_keys_as_array (GHashTable *hash_table,
if (HASH_IS_REAL (hash_table->hashes[i]))
result[j++] = g_hash_table_fetch_key_or_value (hash_table->keys, i, hash_table->have_big_keys);
}
- g_assert_cmpint (j, ==, hash_table->nnodes);
+ g_assert (j == hash_table->nnodes);
result[j] = NULL;
if (length)
@@ -2381,7 +2382,7 @@ g_hash_table_get_keys_as_ptr_array (GHashTable *hash_table)
hash_table->keys, i, hash_table->have_big_keys));
}
}
- g_assert (array->len == (guint) hash_table->nnodes);
+ g_assert (array->len == hash_table->nnodes);
return array;
}
@@ -2456,7 +2457,7 @@ g_hash_table_get_values_as_ptr_array (GHashTable *hash_table)
hash_table->values, i, hash_table->have_big_values));
}
}
- g_assert (array->len == (guint) hash_table->nnodes);
+ g_assert (array->len == hash_table->nnodes);
return array;
}