From 07f0b758aeda96417145ef41dfab3b6362448d93 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerd=20M=C3=B6llmann?= Date: Wed, 19 Oct 2022 16:39:05 +0200 Subject: [PATCH] hash_remove_from_table returns bool * src/fns.c (hash_remove_from_table): Return true if something was deleted. * src/lisp.h: Change declaration. --- src/fns.c | 6 +++++- src/lisp.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/fns.c b/src/fns.c index b7cc976e786..ff9993c8fd2 100644 --- a/src/fns.c +++ b/src/fns.c @@ -4705,12 +4705,13 @@ hash_put (struct Lisp_Hash_Table *h, Lisp_Object key, Lisp_Object value, /* Remove the entry matching KEY from hash table H, if there is one. */ -void +bool hash_remove_from_table (struct Lisp_Hash_Table *h, Lisp_Object key) { Lisp_Object hash_code = h->test.hashfn (key, h); ptrdiff_t start_of_bucket = XUFIXNUM (hash_code) % ASIZE (h->index); ptrdiff_t prev = -1; + bool deleted = false; for (ptrdiff_t i = HASH_INDEX (h, start_of_bucket); 0 <= i; @@ -4736,11 +4737,14 @@ hash_remove_from_table (struct Lisp_Hash_Table *h, Lisp_Object key) h->next_free = i; h->count--; eassert (h->count >= 0); + deleted = true; break; } prev = i; } + + return deleted; } diff --git a/src/lisp.h b/src/lisp.h index e911e68e760..c35c600a539 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4123,7 +4123,7 @@ Lisp_Object make_hash_table (struct hash_table_test, EMACS_INT, float, float, ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object *); ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object, Lisp_Object); -void hash_remove_from_table (struct Lisp_Hash_Table *, Lisp_Object); +bool hash_remove_from_table (struct Lisp_Hash_Table *, Lisp_Object); extern struct hash_table_test const hashtest_eq, hashtest_eql, hashtest_equal; extern void validate_subarray (Lisp_Object, Lisp_Object, Lisp_Object, ptrdiff_t, ptrdiff_t *, ptrdiff_t *); -- 2.39.2