summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2024-02-26 23:47:45 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2024-03-14 17:49:37 +0900
commitc1279a3da53d2869181cbc232213213b8bd99db7 (patch)
tree0c8e242436f0bcd248779d03f0f4a3541485d5a9
parentfdf1fa5f5f85277c55854a96744973366f4bc4b5 (diff)
Extract `RHASH_IDENTHASH_P`
-rw-r--r--hash.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/hash.c b/hash.c
index 32b0b10e9c..2da4c2f8a7 100644
--- a/hash.c
+++ b/hash.c
@@ -394,6 +394,8 @@ const struct st_hash_type rb_hashtype_ident = {
rb_ident_hash,
};
+#define RHASH_IDENTHASH_P(hash) (RHASH_TYPE(hash) == &identhash)
+
typedef st_index_t st_hash_t;
/*
@@ -2956,7 +2958,7 @@ rb_hash_aset(VALUE hash, VALUE key, VALUE val)
rb_hash_modify(hash);
- if (RHASH_TYPE(hash) == &identhash || rb_obj_class(key) != rb_cString) {
+ if (RHASH_IDENTHASH_P(hash) || rb_obj_class(key) != rb_cString) {
RHASH_UPDATE_ITER(hash, iter_p, key, hash_aset, val);
}
else {
@@ -4162,7 +4164,7 @@ rb_hash_assoc(VALUE hash, VALUE key)
if (RHASH_EMPTY_P(hash)) return Qnil;
- if (RHASH_ST_TABLE_P(hash) && RHASH_ST_TABLE(hash)->type != &identhash) {
+ if (RHASH_ST_TABLE_P(hash) && !RHASH_IDENTHASH_P(hash)) {
VALUE value = Qundef;
st_table assoctable = *RHASH_ST_TABLE(hash);
assoctable.type = &(struct st_hash_type){
@@ -4439,7 +4441,7 @@ rb_hash_compare_by_id(VALUE hash)
VALUE
rb_hash_compare_by_id_p(VALUE hash)
{
- return RBOOL(RHASH_ST_TABLE_P(hash) && RHASH_ST_TABLE(hash)->type == &identhash);
+ return RBOOL(RHASH_IDENTHASH_P(hash));
}
VALUE