From 54ac81a4f8dd759b88b5a5104af99f6af2814215 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Wed, 7 Aug 2013 08:52:23 -0700 Subject: [PATCH] op.c: Force shared hash key optimisation for existing COWs MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit If COW scalars are becoming more prevalent (they are), the hash key optimisation will be less and less likely to kick in if it is skipped for anything already SvIsCOW. The assumption is that such a scalar is already a shared hash key sca- lar. That is not true for copy-on-write scalars made such by the new mechanism that allows existing non-COW scalar to be upgraded to such. The purpose of using shared hash keys scalars here is that the precom- puted hash is already stored in the scalar (ok, it points to it indi- rectly), speeding up hash lookup. New COW scalars don’t have that and offer no speedup here. So skip the optimisation only when the COW scalar is a shared hash key scalar. All of the above applies to methods as well. --- op.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/op.c b/op.c index a209110..f580783 100644 --- a/op.c +++ b/op.c @@ -1789,7 +1789,7 @@ S_finalize_op(pTHX_ OP* o) /* Make the CONST have a shared SV */ svp = cSVOPx_svp(((BINOP*)o)->op_last); - if ((!SvIsCOW(sv = *svp)) + if ((!SvIsCOW_shared_hash(sv = *svp)) && SvTYPE(sv) < SVt_PVMG && SvOK(sv) && !SvROK(sv)) { key = SvPV_const(sv, keylen); lexname = newSVpvn_share(key, @@ -9353,7 +9353,7 @@ Perl_ck_method(pTHX_ OP *o) const char * const method = SvPVX_const(sv); if (!(strchr(method, ':') || strchr(method, '\''))) { OP *cmop; - if (!SvIsCOW(sv)) { + if (!SvIsCOW_shared_hash(sv)) { sv = newSVpvn_share(method, SvUTF8(sv) ? -(I32)SvCUR(sv) : (I32)SvCUR(sv), 0); } else { -- 2.7.4