date_core.c: typed data
* ext/date/date_core.c (d_lite_type): turn into typed data. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a05330f4b9
commit
e912c167d2
@ -286,20 +286,20 @@ union DateData {
|
|||||||
|
|
||||||
#define get_d1(x)\
|
#define get_d1(x)\
|
||||||
union DateData *dat;\
|
union DateData *dat;\
|
||||||
Data_Get_Struct(x, union DateData, dat);
|
TypedData_Get_Struct(x, union DateData, &d_lite_type, dat);
|
||||||
|
|
||||||
#define get_d1a(x)\
|
#define get_d1a(x)\
|
||||||
union DateData *adat;\
|
union DateData *adat;\
|
||||||
Data_Get_Struct(x, union DateData, adat);
|
TypedData_Get_Struct(x, union DateData, &d_lite_type, adat);
|
||||||
|
|
||||||
#define get_d1b(x)\
|
#define get_d1b(x)\
|
||||||
union DateData *bdat;\
|
union DateData *bdat;\
|
||||||
Data_Get_Struct(x, union DateData, bdat);
|
TypedData_Get_Struct(x, union DateData, &d_lite_type, bdat);
|
||||||
|
|
||||||
#define get_d2(x,y)\
|
#define get_d2(x,y)\
|
||||||
union DateData *adat, *bdat;\
|
union DateData *adat, *bdat;\
|
||||||
Data_Get_Struct(x, union DateData, adat);\
|
TypedData_Get_Struct(x, union DateData, &d_lite_type, adat);\
|
||||||
Data_Get_Struct(y, union DateData, bdat);
|
TypedData_Get_Struct(y, union DateData, &d_lite_type, bdat);
|
||||||
|
|
||||||
inline static VALUE
|
inline static VALUE
|
||||||
canon(VALUE x)
|
canon(VALUE x)
|
||||||
@ -2922,17 +2922,31 @@ date_s_gregorian_leap_p(VALUE klass, VALUE y)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
d_lite_gc_mark(union DateData *dat)
|
d_lite_gc_mark(void *ptr)
|
||||||
{
|
{
|
||||||
|
union DateData *dat = ptr;
|
||||||
if (simple_dat_p(dat))
|
if (simple_dat_p(dat))
|
||||||
rb_gc_mark(dat->s.nth);
|
rb_gc_mark(dat->s.nth);
|
||||||
else {
|
else {
|
||||||
rb_gc_mark(dat->c.nth);
|
rb_gc_mark(dat->c.nth);
|
||||||
rb_gc_mark(dat->c.sf);
|
rb_gc_mark(dat->c.sf);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t
|
||||||
|
d_lite_memsize(const void *ptr)
|
||||||
|
{
|
||||||
|
const union DateData *dat = ptr;
|
||||||
|
return complex_dat_p(dat) ? sizeof(struct ComplexDateData) : sizeof(struct SimpleDateData);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const rb_data_type_t d_lite_type = {
|
||||||
|
"Date",
|
||||||
|
{d_lite_gc_mark, RUBY_TYPED_DEFAULT_FREE, d_lite_memsize,},
|
||||||
|
NULL, NULL,
|
||||||
|
RUBY_TYPED_FREE_IMMEDIATELY,
|
||||||
|
};
|
||||||
|
|
||||||
inline static VALUE
|
inline static VALUE
|
||||||
d_simple_new_internal(VALUE klass,
|
d_simple_new_internal(VALUE klass,
|
||||||
VALUE nth, int jd,
|
VALUE nth, int jd,
|
||||||
@ -2943,8 +2957,8 @@ d_simple_new_internal(VALUE klass,
|
|||||||
struct SimpleDateData *dat;
|
struct SimpleDateData *dat;
|
||||||
VALUE obj;
|
VALUE obj;
|
||||||
|
|
||||||
obj = Data_Make_Struct(klass, struct SimpleDateData,
|
obj = TypedData_Make_Struct(klass, struct SimpleDateData,
|
||||||
d_lite_gc_mark, -1, dat);
|
&d_lite_type, dat);
|
||||||
set_to_simple(dat, nth, jd, sg, y, m, d, flags & ~COMPLEX_DAT);
|
set_to_simple(dat, nth, jd, sg, y, m, d, flags & ~COMPLEX_DAT);
|
||||||
|
|
||||||
assert(have_jd_p(dat) || have_civil_p(dat));
|
assert(have_jd_p(dat) || have_civil_p(dat));
|
||||||
@ -2964,8 +2978,8 @@ d_complex_new_internal(VALUE klass,
|
|||||||
struct ComplexDateData *dat;
|
struct ComplexDateData *dat;
|
||||||
VALUE obj;
|
VALUE obj;
|
||||||
|
|
||||||
obj = Data_Make_Struct(klass, struct ComplexDateData,
|
obj = TypedData_Make_Struct(klass, struct ComplexDateData,
|
||||||
d_lite_gc_mark, -1, dat);
|
&d_lite_type, dat);
|
||||||
set_to_complex(dat, nth, jd, df, sf, of, sg,
|
set_to_complex(dat, nth, jd, df, sf, of, sg,
|
||||||
y, m, d, h, min, s, flags | COMPLEX_DAT);
|
y, m, d, h, min, s, flags | COMPLEX_DAT);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user