From: gfx Date: Thu, 27 Aug 2009 08:19:11 +0000 (+0900) Subject: Tweaks for less memory X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=19b618cb36eceaae24d62a32fab1108d6f2a7836;p=gitmo%2FClass-MOP.git Tweaks for less memory --- diff --git a/mop.h b/mop.h index d813ac0..7750264 100644 --- a/mop.h +++ b/mop.h @@ -79,30 +79,18 @@ typedef struct { const mop_instance_vtbl* mop_get_default_instance_vtbl(pTHX); -#define MOP_MI_SLOT 0 -#define MOP_MI_last 1 - -#define MOP_mg_mi(mg) ((mg)->mg_obj) +#define MOP_mg_obj(mg) ((mg)->mg_obj) #define MOP_mg_vtbl(mg) ((const mop_instance_vtbl*)(mg)->mg_ptr) #define MOP_mg_flags(mg) ((mg)->mg_private) -#define MOP_mg_miav(mg) ((AV*)MOP_mg_mi(mg)) - -#ifdef DEBUGGING -#define MOP_mi_access(mi, a) *mop_debug_mi_access(aTHX_ (mi) , (a)) -SV** mop_debug_mi_access(pTHX_ AV* const mi, I32 const attr_ix); -#else -#define MOP_mi_access(mi, a) AvARRAY((mi))[(a)] -#endif - -#define MOP_mi_slot(mi) MOP_mi_access((mi), MOP_MI_SLOT) +#define MOP_mg_slot(mg) MOP_mg_obj(mg) -#define MOP_mg_create_instance(mg) MOP_mg_vtbl(mg)->create_instance (aTHX_ MOP_mg_mi(mg)) -#define MOP_mg_has_slot(mg, o) MOP_mg_vtbl(mg)->has_slot (aTHX_ MOP_mg_mi(mg), (o)) -#define MOP_mg_get_slot(mg, o) MOP_mg_vtbl(mg)->get_slot (aTHX_ MOP_mg_mi(mg), (o)) -#define MOP_mg_set_slot(mg, o, v) MOP_mg_vtbl(mg)->set_slot (aTHX_ MOP_mg_mi(mg), (o), (v)) -#define MOP_mg_delete_slot(mg, o) MOP_mg_vtbl(mg)->delete_slot (aTHX_ MOP_mg_mi(mg), (o)) -#define MOP_mg_weaken_slot(mg, o) MOP_mg_vtbl(mg)->weaken_slot (aTHX_ MOP_mg_mi(mg), (o)) +#define MOP_mg_create_instance(mg, stash) MOP_mg_vtbl(mg)->create_instance (aTHX_ (stash)) +#define MOP_mg_has_slot(mg, o) MOP_mg_vtbl(mg)->has_slot (aTHX_ (o), MOP_mg_slot(mg)) +#define MOP_mg_get_slot(mg, o) MOP_mg_vtbl(mg)->get_slot (aTHX_ (o), MOP_mg_slot(mg)) +#define MOP_mg_set_slot(mg, o, v) MOP_mg_vtbl(mg)->set_slot (aTHX_ (o), MOP_mg_slot(mg), (v)) +#define MOP_mg_delete_slot(mg, o) MOP_mg_vtbl(mg)->delete_slot (aTHX_ (o), MOP_mg_slot(mg)) +#define MOP_mg_weaken_slot(mg, o) MOP_mg_vtbl(mg)->weaken_slot (aTHX_ (o), MOP_mg_slot(mg)) /* Class::MOP::Method::Accessor stuff */ diff --git a/xs/Instance.xs b/xs/Instance.xs index c490093..7d5f8c6 100644 --- a/xs/Instance.xs +++ b/xs/Instance.xs @@ -10,46 +10,46 @@ } STMT_END static SV* -mop_instance_create_instance(pTHX_ SV* const mi PERL_UNUSED_DECL) { - return newRV_noinc((SV*)newHV()); +mop_instance_create_instance(pTHX_ HV* const stash) { + return sv_bless( newRV_noinc((SV*)newHV()), stash ); } static bool -mop_instance_has_slot(pTHX_ SV* const mi, SV* const instance) { +mop_instance_has_slot(pTHX_ SV* const instance, SV* const slot) { CHECK_INSTANCE(instance); - return hv_exists_ent((HV*)SvRV(instance), MOP_mi_slot(mi), 0U); + return hv_exists_ent((HV*)SvRV(instance), slot, 0U); } static SV* -mop_instance_get_slot(pTHX_ SV* const mi, SV* const instance) { +mop_instance_get_slot(pTHX_ SV* const instance, SV* const slot) { HE* he; CHECK_INSTANCE(instance); - he = hv_fetch_ent((HV*)SvRV(instance), MOP_mi_slot(mi), FALSE, 0U); + he = hv_fetch_ent((HV*)SvRV(instance), slot, FALSE, 0U); return he ? HeVAL(he) : NULL; } static SV* -mop_instance_set_slot(pTHX_ SV* const mi, SV* const instance, SV* const value) { +mop_instance_set_slot(pTHX_ SV* const instance, SV* const slot, SV* const value) { HE* he; SV* sv; CHECK_INSTANCE(instance); - he = hv_fetch_ent((HV*)SvRV(instance), MOP_mi_slot(mi), TRUE, 0U); + he = hv_fetch_ent((HV*)SvRV(instance), slot, TRUE, 0U); sv = HeVAL(he); sv_setsv_mg(sv, value); return sv; } static SV* -mop_instance_delete_slot(pTHX_ SV* const mi, SV* const instance) { +mop_instance_delete_slot(pTHX_ SV* const instance, SV* const slot) { CHECK_INSTANCE(instance); - return hv_delete_ent((HV*)SvRV(instance), MOP_mi_slot(mi), 0, 0U); + return hv_delete_ent((HV*)SvRV(instance), slot, 0, 0U); } static void -mop_instance_weaken_slot(pTHX_ SV* const mi, SV* const instance) { +mop_instance_weaken_slot(pTHX_ SV* const instance, SV* const slot) { HE* he; CHECK_INSTANCE(instance); - he = hv_fetch_ent((HV*)SvRV(instance), MOP_mi_slot(mi), FALSE, 0U); + he = hv_fetch_ent((HV*)SvRV(instance), slot, FALSE, 0U); if(he){ sv_rvweaken(HeVAL(he)); } diff --git a/xs/MethodAccessor.xs b/xs/MethodAccessor.xs index e1114df..2e9a065 100644 --- a/xs/MethodAccessor.xs +++ b/xs/MethodAccessor.xs @@ -24,7 +24,6 @@ CV* mop_install_accessor(pTHX_ const char* const fq_name, const char* const key, I32 const keylen, XSPROTO(accessor_impl), const mop_instance_vtbl* vtbl){ CV* const xsub = newXS((char*)fq_name, accessor_impl, __FILE__); SV* const keysv = newSVpvn_share(key, keylen, 0U); - AV* const meta = newAV(); MAGIC* mg; if(!vtbl){ @@ -36,10 +35,8 @@ mop_install_accessor(pTHX_ const char* const fq_name, const char* const key, I32 sv_2mortal((SV*)xsub); } - mg = sv_magicext((SV*)xsub, (SV*)meta, PERL_MAGIC_ext, &mop_accessor_vtbl, (char*)vtbl, 0); - SvREFCNT_dec(meta); /* sv_magicext() increases refcnt in mg_obj */ - - av_store(meta, MOP_MI_SLOT, keysv); + mg = sv_magicext((SV*)xsub, keysv, PERL_MAGIC_ext, &mop_accessor_vtbl, (char*)vtbl, 0); + SvREFCNT_dec(keysv); /* sv_magicext() increases refcnt in mg_obj */ /* NOTE: * although we use MAGIC for gc, we also store mg to any slot for efficiency (gfx) @@ -80,16 +77,6 @@ mop_accessor_get_self(pTHX_ I32 const ax, I32 const items, CV* const cv) { return self; } -#ifdef DEBUGGING -SV** -mop_debug_mi_access(pTHX_ AV* const mi, I32 const attr_ix){ - assert(mi); - assert(SvTYPE(mi) == SVt_PVAV); - assert(AvMAX(mi) >= attr_ix); - return &AvARRAY(mi)[attr_ix]; -} -#endif - XS(mop_xs_simple_accessor) { dVAR; dXSARGS;