summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2019-08-01 05:59:04 +0900
committerKoichi Sasada <ko1@atdot.net>2019-08-01 05:59:04 +0900
commit117241b3c73f8f7f1bcfee34e9d627c41bb19cc9 (patch)
tree3f2b85d0ef6a04faabb1500454fc8562c52ec414
parentbd1052d55da94b5503ff00c10e1cdcc04a6f9608 (diff)
downloadruby-117241b3c73f8f7f1bcfee34e9d627c41bb19cc9.tar.gz
make inline functions from macros.
-rw-r--r--hash.c61
1 files changed, 36 insertions, 25 deletions
diff --git a/hash.c b/hash.c
index f1bb3dfbdb..1b74b0854e 100644
--- a/hash.c
+++ b/hash.c
@@ -409,14 +409,14 @@ ar_set_entry(VALUE hash, unsigned int index, st_data_t key, st_data_t val, st_ha
}
#define RHASH_AR_TABLE_SIZE(h) (HASH_ASSERT(RHASH_AR_TABLE_P(h)), \
- RHASH_AR_TABLE_SIZE_RAW(h))
+ RHASH_AR_TABLE_SIZE_RAW(h))
#define RHASH_AR_TABLE_BOUND_RAW(h) \
((unsigned int)((RBASIC(h)->flags >> RHASH_AR_TABLE_BOUND_SHIFT) & \
(RHASH_AR_TABLE_BOUND_MASK >> RHASH_AR_TABLE_BOUND_SHIFT)))
#define RHASH_AR_TABLE_BOUND(h) (HASH_ASSERT(RHASH_AR_TABLE_P(h)), \
- RHASH_AR_TABLE_BOUND_RAW(h))
+ RHASH_AR_TABLE_BOUND_RAW(h))
#define RHASH_ST_TABLE_SET(h, s) rb_hash_st_table_set(h, s)
#define RHASH_TYPE(hash) (RHASH_AR_TABLE_P(hash) ? &objhash : RHASH_ST_TABLE(hash)->type)
@@ -563,26 +563,35 @@ hash_ar_table_set(VALUE hash, ar_table *ar)
#define RHASH_SET_ST_FLAG(h) FL_SET_RAW(h, RHASH_ST_TABLE_FLAG)
#define RHASH_UNSET_ST_FLAG(h) FL_UNSET_RAW(h, RHASH_ST_TABLE_FLAG)
-#define RHASH_AR_TABLE_BOUND_SET(h, n) do { \
- st_index_t tmp_n = (n); \
- HASH_ASSERT(RHASH_AR_TABLE_P(h)); \
- HASH_ASSERT(tmp_n <= RHASH_AR_TABLE_MAX_BOUND); \
- RBASIC(h)->flags &= ~RHASH_AR_TABLE_BOUND_MASK; \
- RBASIC(h)->flags |= (tmp_n) << RHASH_AR_TABLE_BOUND_SHIFT; \
-} while (0)
+static inline void
+RHASH_AR_TABLE_BOUND_SET(VALUE h, st_index_t n)
+{
+ HASH_ASSERT(RHASH_AR_TABLE_P(h));
+ HASH_ASSERT(n <= RHASH_AR_TABLE_MAX_BOUND);
-#define RHASH_AR_TABLE_SIZE_SET(h, n) do { \
- st_index_t tmp_n = n; \
- HASH_ASSERT(RHASH_AR_TABLE_P(h)); \
- RBASIC(h)->flags &= ~RHASH_AR_TABLE_SIZE_MASK; \
- RBASIC(h)->flags |= (tmp_n) << RHASH_AR_TABLE_SIZE_SHIFT; \
-} while (0)
+ RBASIC(h)->flags &= ~RHASH_AR_TABLE_BOUND_MASK;
+ RBASIC(h)->flags |= n << RHASH_AR_TABLE_BOUND_SHIFT;
+}
-#define HASH_AR_TABLE_SIZE_ADD(h, n) do { \
- HASH_ASSERT(RHASH_AR_TABLE_P(h)); \
- RHASH_AR_TABLE_SIZE_SET((h), RHASH_AR_TABLE_SIZE(h)+(n)); \
- hash_verify(h); \
-} while (0)
+static inline void
+RHASH_AR_TABLE_SIZE_SET(VALUE h, st_index_t n)
+{
+ HASH_ASSERT(RHASH_AR_TABLE_P(h));
+ HASH_ASSERT(n <= RHASH_AR_TABLE_MAX_SIZE);
+
+ RBASIC(h)->flags &= ~RHASH_AR_TABLE_SIZE_MASK;
+ RBASIC(h)->flags |= n << RHASH_AR_TABLE_SIZE_SHIFT;
+}
+
+static inline void
+HASH_AR_TABLE_SIZE_ADD(VALUE h, st_index_t n)
+{
+ HASH_ASSERT(RHASH_AR_TABLE_P(h));
+
+ RHASH_AR_TABLE_SIZE_SET(h, RHASH_AR_TABLE_SIZE(h) + n);
+
+ hash_verify(h);
+}
#define RHASH_AR_TABLE_SIZE_INC(h) HASH_AR_TABLE_SIZE_ADD(h, 1)
@@ -602,12 +611,14 @@ RHASH_AR_TABLE_SIZE_DEC(VALUE h)
hash_verify(h);
}
-#define RHASH_AR_TABLE_CLEAR(h) do { \
- RBASIC(h)->flags &= ~RHASH_AR_TABLE_SIZE_MASK; \
- RBASIC(h)->flags &= ~RHASH_AR_TABLE_BOUND_MASK; \
- hash_ar_table_set(hash, NULL); \
-} while (0)
+static inline void
+RHASH_AR_TABLE_CLEAR(VALUE h)
+{
+ RBASIC(h)->flags &= ~RHASH_AR_TABLE_SIZE_MASK;
+ RBASIC(h)->flags &= ~RHASH_AR_TABLE_BOUND_MASK;
+ hash_ar_table_set(h, NULL);
+}
static ar_table*
ar_alloc_table(VALUE hash)