From: Fuji, Goro Date: Wed, 29 Sep 2010 03:39:33 +0000 (+0900) Subject: Cleanup XS X-Git-Tag: 0.77~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=05e658dc1915e54a27d218201b3a9d7314ccdabe;p=gitmo%2FMouse.git Cleanup XS --- diff --git a/mouse.h b/mouse.h index 0ce6916..ff5edf8 100644 --- a/mouse.h +++ b/mouse.h @@ -19,7 +19,6 @@ AV* mouse_mro_get_linear_isa(pTHX_ HV* const stash); #endif /* mro_get_package_gen */ extern SV* mouse_package; -extern SV* mouse_namespace; extern SV* mouse_methods; extern SV* mouse_name; extern SV* mouse_coerce; @@ -244,6 +243,7 @@ enum mouse_xa_flags_t{ MOUSEf_MOUSE_MASK = 0xFFFF /* not used */ }; - +/* Mouse::Meta::Class stuff */ +HV* mouse_get_namespace(pTHX_ SV* const meta); /* $meta->namespace */ #endif /* !MOUSE_H */ diff --git a/xs-src/Mouse.xs b/xs-src/Mouse.xs index b8951c1..db1365d 100644 --- a/xs-src/Mouse.xs +++ b/xs-src/Mouse.xs @@ -49,6 +49,15 @@ enum mouse_modifier_t { static MGVTBL mouse_xc_vtbl; /* for identity */ +HV* +mouse_get_namespace(pTHX_ SV* const meta) { + SV* const package = get_slot(meta, mouse_package); + if(!(package && SvOK(package))){ + croak("No package name defined for metaclass"); + } + return gv_stashsv(package, GV_ADDMULTI); +} + static AV* mouse_calculate_all_attributes(pTHX_ SV* const metaclass) { SV* const avref = mcall0s(metaclass, "_calculate_all_attributes"); @@ -151,21 +160,18 @@ mouse_get_xc(pTHX_ SV* const metaclass) { mg = mouse_mg_find(aTHX_ SvRV(metaclass), &mouse_xc_vtbl, 0x00); if(!mg){ - SV* const package = get_slot(metaclass, mouse_package); - STRLEN len; - const char* const pv = SvPV_const(package, len); - - stash = gv_stashpvn(pv, len, TRUE); + /* cache stash for performance */ + stash = mouse_get_namespace(aTHX_ metaclass); xc = newAV(); - mg = sv_magicext(SvRV(metaclass), (SV*)xc, PERL_MAGIC_ext, &mouse_xc_vtbl, pv, len); + mg = sv_magicext(SvRV(metaclass), (SV*)xc, PERL_MAGIC_ext, + &mouse_xc_vtbl, NULL, 0); SvREFCNT_dec(xc); /* refcnt++ in sv_magicext */ av_extend(xc, MOUSE_XC_last - 1); av_store(xc, MOUSE_XC_GEN, newSVuv(0U)); av_store(xc, MOUSE_XC_STASH, (SV*)stash); - SvREFCNT_inc_simple_void_NN(stash); } else{ @@ -464,11 +470,7 @@ HV* namespace(SV* self) CODE: { - SV* const package = get_slot(self, mouse_package); - if(!(package && SvOK(package))){ - croak("No package name defined"); - } - RETVAL = gv_stashsv(package, GV_ADDMULTI); + RETVAL = mouse_get_namespace(aTHX_ self); } OUTPUT: RETVAL @@ -539,14 +541,12 @@ void linearized_isa(SV* self) PPCODE: { - SV* const stash_ref = mcall0(self, mouse_namespace); /* $self->namespace */ - AV* linearized_isa; + /* MOUSE_xc_stash() is not available because the xc system depends on + linearized_isa() */ + HV* const stash = mouse_get_namespace(aTHX_ self); + AV* const linearized_isa = mro_get_linear_isa(stash); I32 len; I32 i; - if(!(SvROK(stash_ref) && SvTYPE(SvRV(stash_ref)) == SVt_PVHV)){ - croak("namespace() didn't return a HASH reference"); - } - linearized_isa = mro_get_linear_isa((HV*)SvRV(stash_ref)); len = AvFILLp(linearized_isa) + 1; EXTEND(SP, len); for(i = 0; i < len; i++){ diff --git a/xs-src/MouseAccessor.xs b/xs-src/MouseAccessor.xs index 0d0d448..3df9fda 100644 --- a/xs-src/MouseAccessor.xs +++ b/xs-src/MouseAccessor.xs @@ -342,7 +342,6 @@ XS(XS_Mouse_inheritable_class_accessor) { dMOUSE_self; SV* const slot = MOUSE_mg_slot((MAGIC*)XSANY.any_ptr); SV* value; - SV* stash_ref; HV* stash; if(items == 1){ /* reader */ @@ -357,11 +356,7 @@ XS(XS_Mouse_inheritable_class_accessor) { value = NULL; /* -Wuninitialized */ } - stash_ref= mcall0(self, mouse_namespace); - if(!(SvROK(stash_ref) && SvTYPE(SvRV(stash_ref)) == SVt_PVHV)) { - croak("namespace() didn't return a HASH reference"); - } - stash = (HV*)SvRV(stash_ref); + stash = mouse_get_namespace(aTHX_ self); if(!value) { /* reader */ value = get_slot(self, slot);