summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-17 07:52:47 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-17 07:52:47 +0000
commit367fdd1aee07bd856612e9d796f301e1f1d5a30b (patch)
treed18b8196f349c180c8a8fc13519391a33b88d50f /hash.c
parent07298ea2094bca6f847e7b0c82e3c7059ff745e3 (diff)
reset bound if the size is 0.
* hash.c (RHASH_AR_TABLE_SIZE_DEC): generally, we need to check all entries to calculate exact "bound" in ar_table, but if size == 0, we can clear bound because there are no active entries. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66843 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/hash.c b/hash.c
index dd94ffd4a5..3dd2777cd1 100644
--- a/hash.c
+++ b/hash.c
@@ -554,11 +554,21 @@ hash_ar_table_set(VALUE hash, ar_table *ar)
} while (0)
#define RHASH_AR_TABLE_SIZE_INC(h) HASH_AR_TABLE_SIZE_ADD(h, 1)
-#define RHASH_AR_TABLE_SIZE_DEC(h) do { \
- HASH_ASSERT(RHASH_AR_TABLE_P(h)); \
- RHASH_AR_TABLE_SIZE_SET((h), RHASH_AR_TABLE_SIZE(h) - 1); \
- hash_verify(h); \
-} while (0)
+
+static inline void
+RHASH_AR_TABLE_SIZE_DEC(VALUE h) {
+ HASH_ASSERT(RHASH_AR_TABLE_P(h));
+ int new_size = RHASH_AR_TABLE_SIZE(h) - 1;
+
+ if (new_size != 0) {
+ RHASH_AR_TABLE_SIZE_SET(h, new_size);
+ }
+ else {
+ RHASH_AR_TABLE_SIZE_SET(h, 0);
+ RHASH_AR_TABLE_BOUND_SET(h, 0);
+ }
+ hash_verify(h);
+}
#define RHASH_AR_TABLE_CLEAR(h) do { \
RBASIC(h)->flags &= ~RHASH_AR_TABLE_SIZE_MASK; \