From: Nicholas Clark Date: Sun, 12 Jun 2005 21:59:34 +0000 (+0000) Subject: Provide share_hek_hek, and use it for fast copying of shared string X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d1db91c62f7fa6ddc9f9a29f5ba20b5d381c9d4b;p=p5sagit%2Fp5-mst-13.2.git Provide share_hek_hek, and use it for fast copying of shared string scalars. p4raw-id: //depot/perl@24811 --- diff --git a/hv.h b/hv.h index ac4bdd3..6378a02 100644 --- a/hv.h +++ b/hv.h @@ -364,6 +364,13 @@ C. #define Perl_sharepvn(sv, len, hash) HEK_KEY(share_hek(sv, len, hash)) #define sharepvn(sv, len, hash) Perl_sharepvn(sv, len, hash) +#define share_hek_hek(hek) \ + (++(((struct shared_he *)(((char *)hek) \ + - STRUCT_OFFSET(struct shared_he, \ + shared_he_hek))) \ + ->shared_he_he.hent_val), \ + hek) + /* * Local variables: * c-indentation-style: bsd diff --git a/sv.c b/sv.c index 2f01005..db5a2e0 100644 --- a/sv.c +++ b/sv.c @@ -4562,15 +4562,12 @@ Perl_sv_setsv_flags(pTHX_ SV *dstr, register SV *sstr, I32 flags) #endif { /* SvIsCOW_shared_hash */ - UV hash = SvSHARED_HASH(sstr); DEBUG_C(PerlIO_printf(Perl_debug_log, "Copy on write: Sharing hash\n")); assert (SvTYPE(dstr) >= SVt_PV); - /* FIXME - would benefit from share_hek_hek */ SvPV_set(dstr, - sharepvn(SvPVX_const(sstr), - (sflags & SVf_UTF8?-cur:cur), hash)); + HEK_KEY(share_hek_hek(SvSHARED_HEK_FROM_PV(SvPVX_const(sstr))))); } SvLEN_set(dstr, len); SvCUR_set(dstr, cur); @@ -4708,11 +4705,9 @@ Perl_sv_setsv_cow(pTHX_ SV *dstr, SV *sstr) if (SvLEN(sstr) == 0) { /* source is a COW shared hash key. */ - UV hash = SvSHARED_HASH(sstr); DEBUG_C(PerlIO_printf(Perl_debug_log, "Fast copy on write: Sharing hash\n")); - /* FIXME - would benefit from share_hek_hek */ - new_pv = sharepvn(SvPVX_const(sstr), (SvUTF8(sstr)?-cur:cur), hash); + new_pv = HEK_KEY(share_hek_hek(SvSHARED_HEK_FROM_PV(SvPVX_const(sstr)))); goto common_exit; } SV_COW_NEXT_SV_SET(dstr, SV_COW_NEXT_SV(sstr));