ruby-changes:41987
From: nobu <ko1@a...>
Date: Wed, 9 Mar 2016 16:34:51 +0900 (JST)
Subject: [ruby-changes:41987] nobu:r54059 (trunk): hash.c: COPY_DEFAULT
nobu 2016-03-09 16:17:04 +0900 (Wed, 09 Mar 2016) New Revision: 54059 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54059 Log: hash.c: COPY_DEFAULT * hash.c (COPY_DEFAULT): new macro to copy the default value/proc. Modified files: trunk/hash.c Index: hash.c =================================================================== --- hash.c (revision 54058) +++ hash.c (revision 54059) @@ -38,6 +38,16 @@ https://github.com/ruby/ruby/blob/trunk/hash.c#L38 #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, VALU https://github.com/ruby/ruby/blob/trunk/hash.c#L1593 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) https://github.com/ruby/ruby/blob/trunk/hash.c#L1619 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; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/