From: gfx Date: Tue, 18 Aug 2009 06:41:04 +0000 (+0900) Subject: Make _compiled_type_constraint lazy X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7d95b328c1e36372dbb2d6a56c101a51170b72af;p=gitmo%2FMoose.git Make _compiled_type_constraint lazy --- diff --git a/Moose.xs b/Moose.xs index 8130da6..33a4c3c 100644 --- a/Moose.xs +++ b/Moose.xs @@ -144,7 +144,6 @@ moose_instantiate_xs_accessor(pTHX_ SV* const accessor, XSPROTO(accessor_impl), if(SvTRUEx(mop_call0_pvs(attr, "has_type_constraint"))){ SV* tc; - SV* tc_code; flags |= MAf_ATTR_HAS_TC; ENTER; @@ -153,9 +152,6 @@ moose_instantiate_xs_accessor(pTHX_ SV* const accessor, XSPROTO(accessor_impl), tc = mop_call0_pvs(attr, "type_constraint"); av_store(meta, MA_TC, newSVsv(tc)); - tc_code = mop_call0_pvs(tc, "_compiled_type_constraint"); - av_store(meta, MA_TC_CODE, newSVsv(tc_code)); - if(SvTRUEx(mop_call0_pvs(attr, "should_auto_deref"))){ flags |= MAf_ATTR_SHOULD_AUTO_DEREF; if( SvTRUEx(mop_call1_pvs(tc, "is_a_type_of", newSVpvs_flags("ArrayRef", SVs_TEMP))) ){ @@ -215,12 +211,20 @@ moose_instantiate_xs_accessor(pTHX_ SV* const accessor, XSPROTO(accessor_impl), static SV* moose_apply_tc(pTHX_ AV* const meta, SV* value, U16 const flags){ SV* const tc = MA_tc(meta); - SV* const tc_code = MA_tc_code(meta); + SV* tc_code; if(flags & MAf_ATTR_SHOULD_COERCE){ value = mop_call1_pvs(tc, "coerce", value); } + if(!SvOK(MA_tc_code(meta))){ + tc_code = mop_call0_pvs(tc, "_compiled_type_constraint"); + av_store(meta, MA_TC_CODE, newSVsv(tc_code)); + } + else{ + tc_code = MA_tc_code(meta); + } + /* TODO: implement build-in type constrains in XS */ { bool ok;