From: Fuji, Goro Date: Mon, 6 Dec 2010 04:00:17 +0000 (+0900) Subject: Encourage function inlining X-Git-Tag: 0.89~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=53142eda803bb80d2a4edb8b8c264a40390abf4b;p=gitmo%2FMouse.git Encourage function inlining --- diff --git a/xs-src/MouseAccessor.xs b/xs-src/MouseAccessor.xs index cf40488..998849a 100644 --- a/xs-src/MouseAccessor.xs +++ b/xs-src/MouseAccessor.xs @@ -14,6 +14,79 @@ static MGVTBL mouse_accessor_vtbl; /* MAGIC identity */ #define dMOUSE_self SV* const self = mouse_accessor_get_self(aTHX_ ax, items, cv) +/* simple instance slot accessor (or Mouse::Meta::Instance) */ + +SV* +mouse_instance_create(pTHX_ HV* const stash) { + SV* instance; + assert(stash); + assert(SvTYPE(stash) == SVt_PVHV); + instance = sv_bless( newRV_noinc((SV*)newHV()), stash ); + return sv_2mortal(instance); +} + +SV* +mouse_instance_clone(pTHX_ SV* const instance) { + SV* proto; + CHECK_INSTANCE(instance); + assert(SvOBJECT(SvRV(instance))); + + proto = newRV_noinc((SV*)newHVhv((HV*)SvRV(instance))); + sv_bless(proto, SvSTASH(SvRV(instance))); + return sv_2mortal(proto); +} + +bool +mouse_instance_has_slot(pTHX_ SV* const instance, SV* const slot) { + assert(slot); + CHECK_INSTANCE(instance); + return hv_exists_ent((HV*)SvRV(instance), slot, 0U); +} + +SV* +mouse_instance_get_slot(pTHX_ SV* const instance, SV* const slot) { + HE* he; + assert(slot); + CHECK_INSTANCE(instance); + he = hv_fetch_ent((HV*)SvRV(instance), slot, FALSE, 0U); + return he ? HeVAL(he) : NULL; +} + +SV* +mouse_instance_set_slot(pTHX_ SV* const instance, SV* const slot, SV* const value) { + HE* he; + SV* sv; + assert(slot); + assert(value); + CHECK_INSTANCE(instance); + he = hv_fetch_ent((HV*)SvRV(instance), slot, TRUE, 0U); + sv = HeVAL(he); + sv_setsv(sv, value); + SvSETMAGIC(sv); + return sv; +} + +SV* +mouse_instance_delete_slot(pTHX_ SV* const instance, SV* const slot) { + assert(instance); + assert(slot); + CHECK_INSTANCE(instance); + return hv_delete_ent((HV*)SvRV(instance), slot, 0, 0U); +} + +void +mouse_instance_weaken_slot(pTHX_ SV* const instance, SV* const slot) { + HE* he; + assert(slot); + CHECK_INSTANCE(instance); + he = hv_fetch_ent((HV*)SvRV(instance), slot, FALSE, 0U); + if(he){ + sv_rvweaken(HeVAL(he)); + } +} + +/* utilities */ + STATIC_INLINE SV* mouse_accessor_get_self(pTHX_ I32 const ax, I32 const items, CV* const cv) { if(items < 1){ @@ -112,7 +185,7 @@ mouse_push_value(pTHX_ SV* const value, U16 const flags) { } } -static void +STATIC_INLINE void mouse_attr_get(pTHX_ SV* const self, MAGIC* const mg){ U16 const flags = MOUSE_mg_flags(mg); SV* value; @@ -393,76 +466,6 @@ XS(XS_Mouse_inheritable_class_accessor) { XSRETURN(1); } -/* simple instance slot accessor (or Mouse::Meta::Instance) */ - -SV* -mouse_instance_create(pTHX_ HV* const stash) { - SV* instance; - assert(stash); - assert(SvTYPE(stash) == SVt_PVHV); - instance = sv_bless( newRV_noinc((SV*)newHV()), stash ); - return sv_2mortal(instance); -} - -SV* -mouse_instance_clone(pTHX_ SV* const instance) { - SV* proto; - CHECK_INSTANCE(instance); - assert(SvOBJECT(SvRV(instance))); - - proto = newRV_noinc((SV*)newHVhv((HV*)SvRV(instance))); - sv_bless(proto, SvSTASH(SvRV(instance))); - return sv_2mortal(proto); -} - -bool -mouse_instance_has_slot(pTHX_ SV* const instance, SV* const slot) { - assert(slot); - CHECK_INSTANCE(instance); - return hv_exists_ent((HV*)SvRV(instance), slot, 0U); -} - -SV* -mouse_instance_get_slot(pTHX_ SV* const instance, SV* const slot) { - HE* he; - assert(slot); - CHECK_INSTANCE(instance); - he = hv_fetch_ent((HV*)SvRV(instance), slot, FALSE, 0U); - return he ? HeVAL(he) : NULL; -} - -SV* -mouse_instance_set_slot(pTHX_ SV* const instance, SV* const slot, SV* const value) { - HE* he; - SV* sv; - assert(slot); - assert(value); - CHECK_INSTANCE(instance); - he = hv_fetch_ent((HV*)SvRV(instance), slot, TRUE, 0U); - sv = HeVAL(he); - sv_setsv(sv, value); - SvSETMAGIC(sv); - return sv; -} - -SV* -mouse_instance_delete_slot(pTHX_ SV* const instance, SV* const slot) { - assert(instance); - assert(slot); - CHECK_INSTANCE(instance); - return hv_delete_ent((HV*)SvRV(instance), slot, 0, 0U); -} - -void -mouse_instance_weaken_slot(pTHX_ SV* const instance, SV* const slot) { - HE* he; - assert(slot); - CHECK_INSTANCE(instance); - he = hv_fetch_ent((HV*)SvRV(instance), slot, FALSE, 0U); - if(he){ - sv_rvweaken(HeVAL(he)); - } -} MODULE = Mouse::Meta::Method::Accessor::XS PACKAGE = Mouse::Meta::Method::Accessor::XS