зеркало из https://github.com/github/ruby.git
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:
Родитель
53ad55e4ca
Коммит
8655d0735f
|
@ -4768,8 +4768,28 @@ d_lite_initialize_copy(VALUE copy, VALUE date)
|
|||
{
|
||||
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 date)
|
|||
"cannot load complex into simple");
|
||||
|
||||
adat->c = bdat->c;
|
||||
adat->c.flags |= COMPLEX_DAT;
|
||||
}
|
||||
}
|
||||
return copy;
|
||||
|
|
|
@ -267,4 +267,12 @@ class TestDateNew < Test::Unit::TestCase
|
|||
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче