From 2d3a6ba66db795f7bfef1e9afad910b83618d91d Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 9 Mar 2016 07:17:04 +0000 Subject: [PATCH] hash.c: COPY_DEFAULT * hash.c (COPY_DEFAULT): new macro to copy the default value/proc. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- hash.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/hash.c b/hash.c index 1cb9a898b1..5eebc285af 100644 --- a/hash.c +++ b/hash.c @@ -38,6 +38,16 @@ #define SET_PROC_DEFAULT(hash, proc) set_proc_default(hash, proc) +#define COPY_DEFAULT(hash, hash2) copy_default(RHASH(hash), RHASH(hash2)) + +static inline void +copy_default(struct RHash *hash, const struct RHash *hash2) +{ + hash->basic.flags &= ~HASH_PROC_DEFAULT; + hash->basic.flags |= hash2->basic.flags & HASH_PROC_DEFAULT; + RHASH_SET_IFNONE(hash, RHASH_IFNONE(hash2)); +} + static VALUE has_extra_methods(VALUE klass) { @@ -1583,9 +1593,7 @@ rb_hash_initialize_copy(VALUE hash, VALUE hash2) st_clear(ntbl); } - FL_UNSET_RAW(hash, HASH_PROC_DEFAULT); - FL_SET_RAW(hash, FL_TEST_RAW(hash2, HASH_PROC_DEFAULT)); - RHASH_SET_IFNONE(hash, RHASH_IFNONE(hash2)); + COPY_DEFAULT(hash, hash2); return hash; } @@ -1611,11 +1619,7 @@ rb_hash_replace(VALUE hash, VALUE hash2) if (hash == hash2) return hash; hash2 = to_hash(hash2); - RHASH_SET_IFNONE(hash, RHASH_IFNONE(hash2)); - if (FL_TEST(hash2, HASH_PROC_DEFAULT)) - FL_SET(hash, HASH_PROC_DEFAULT); - else - FL_UNSET(hash, HASH_PROC_DEFAULT); + COPY_DEFAULT(hash, hash2); table2 = RHASH(hash2)->ntbl;