mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 21:14:23 +02:00
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
53ad55e4ca
commit
8655d0735f
2 changed files with 30 additions and 3 deletions
|
@ -4768,8 +4768,28 @@ d_lite_initialize_copy(VALUE copy, VALUE date)
|
||||||
{
|
{
|
||||||
get_d2(copy, date);
|
get_d2(copy, date);
|
||||||
if (simple_dat_p(bdat)) {
|
if (simple_dat_p(bdat)) {
|
||||||
|
if (simple_dat_p(adat)) {
|
||||||
adat->s = bdat->s;
|
adat->s = bdat->s;
|
||||||
adat->s.flags &= ~COMPLEX_DAT;
|
}
|
||||||
|
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 {
|
else {
|
||||||
if (!complex_dat_p(adat))
|
if (!complex_dat_p(adat))
|
||||||
|
@ -4777,7 +4797,6 @@ d_lite_initialize_copy(VALUE copy, VALUE date)
|
||||||
"cannot load complex into simple");
|
"cannot load complex into simple");
|
||||||
|
|
||||||
adat->c = bdat->c;
|
adat->c = bdat->c;
|
||||||
adat->c.flags |= COMPLEX_DAT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return copy;
|
return copy;
|
||||||
|
|
|
@ -267,4 +267,12 @@ class TestDateNew < Test::Unit::TestCase
|
||||||
assert_in_delta(t, t2, t - z + 2)
|
assert_in_delta(t, t2, t - z + 2)
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue