ruby-changes:53481
From: nobu <ko1@a...>
Date: Tue, 13 Nov 2018 13:29:35 +0900 (JST)
Subject: [ruby-changes:53481] nobu:r65697 (trunk): date_core.c: keep COMPLEX_DAT bit
nobu 2018-11-13 13:29:30 +0900 (Tue, 13 Nov 2018) New Revision: 65697 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65697 Log: date_core.c: keep COMPLEX_DAT bit * ext/date/date_core.c (d_lite_initialize_copy): do not change COMPLEX_DAT bit, as the structure does not change. initialize member-wise instead. Modified files: trunk/ext/date/date_core.c trunk/test/date/test_date_new.rb Index: ext/date/date_core.c =================================================================== --- ext/date/date_core.c (revision 65696) +++ ext/date/date_core.c (revision 65697) @@ -4768,8 +4768,28 @@ d_lite_initialize_copy(VALUE copy, VALUE https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L4768 { get_d2(copy, date); if (simple_dat_p(bdat)) { - adat->s = bdat->s; - adat->s.flags &= ~COMPLEX_DAT; + if (simple_dat_p(adat)) { + adat->s = bdat->s; + } + else { + adat->c.flags = bdat->s.flags | COMPLEX_DAT; + adat->c.nth = bdat->s.nth; + adat->c.jd = bdat->s.jd; + adat->c.df = 0; + adat->c.sf = INT2FIX(0); + adat->c.of = 0; + adat->c.sg = bdat->s.sg; + adat->c.year = bdat->s.year; +#ifndef USE_PACK + adat->c.mon = bdat->s.mon; + adat->c.mday = bdat->s.mday; + adat->c.hour = bdat->s.hour; + adat->c.min = bdat->s.min; + adat->c.sec = bdat->s.sec; +#else + adat->c.pc = bdat->s.pc; +#endif + } } else { if (!complex_dat_p(adat)) @@ -4777,7 +4797,6 @@ d_lite_initialize_copy(VALUE copy, VALUE https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L4797 "cannot load complex into simple"); adat->c = bdat->c; - adat->c.flags |= COMPLEX_DAT; } } return copy; Index: test/date/test_date_new.rb =================================================================== --- test/date/test_date_new.rb (revision 65696) +++ test/date/test_date_new.rb (revision 65697) @@ -267,4 +267,12 @@ class TestDateNew < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/date/test_date_new.rb#L267 assert_in_delta(t, t2, t - z + 2) end + def test_memsize + require 'objspace' + t = DateTime.now + size = ObjectSpace.memsize_of(t) + t.__send__(:initialize_copy, Date.today) + assert_instance_of(DateTime, t) + assert_equal(size, ObjectSpace.memsize_of(t), "not reallocated but memsize changed") + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/