Skip to content

Commit d648ffc

Browse files
syberFather Chrysostomos
syber
authored and
Father Chrysostomos
committed
Remove op_const_class; just use the name on the stack
Instead of storing the class name in the op_const_class field of the METHOP in addition to pushing it on to the stack, just use the item on the stack. This also makes $class->method faster if $class is already a shared hash string.
1 parent f5fdb02 commit d648ffc

File tree

3 files changed

+21
-47
lines changed

3 files changed

+21
-47
lines changed

op.c

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -861,16 +861,6 @@ Perl_op_clear(pTHX_ OP *o)
861861
pad_swipe(o->op_targ, 1);
862862
o->op_targ = 0;
863863
}
864-
#endif
865-
case OP_METHOD:
866-
#ifdef USE_ITHREADS
867-
if (cMETHOPx(o)->op_class_targ) {
868-
pad_swipe(cMETHOPx(o)->op_class_targ, 1);
869-
cMETHOPx(o)->op_class_targ = 0;
870-
}
871-
#else
872-
SvREFCNT_dec(cMETHOPx(o)->op_class_sv);
873-
cMETHOPx(o)->op_class_sv = NULL;
874864
#endif
875865
break;
876866
case OP_CONST:
@@ -4692,11 +4682,6 @@ S_newMETHOP_internal(pTHX_ I32 type, I32 flags, OP* dynamic_meth, SV* const_meth
46924682
methop->op_next = (OP*)methop;
46934683
}
46944684

4695-
#ifdef USE_ITHREADS
4696-
methop->op_class_targ = 0;
4697-
#else
4698-
methop->op_class_sv = NULL;
4699-
#endif
47004685
CHANGE_TYPE(methop, type);
47014686
methop = (METHOP*) CHECKOP(type, methop);
47024687

@@ -11592,7 +11577,7 @@ Perl_ck_subr(pTHX_ OP *o)
1159211577
OP *aop, *cvop;
1159311578
CV *cv;
1159411579
GV *namegv;
11595-
SV *const_class = NULL;
11580+
SV **const_class = NULL;
1159611581

1159711582
PERL_ARGS_ASSERT_CK_SUBR;
1159811583

@@ -11618,29 +11603,26 @@ Perl_ck_subr(pTHX_ OP *o)
1161811603
case OP_METHOD_NAMED:
1161911604
if (aop->op_type == OP_CONST) {
1162011605
aop->op_private &= ~OPpCONST_STRICT;
11621-
const_class = cSVOPx(aop)->op_sv;
11606+
const_class = &cSVOPx(aop)->op_sv;
1162211607
}
1162311608
else if (aop->op_type == OP_LIST) {
1162411609
OP * const sib = OP_SIBLING(((UNOP*)aop)->op_first);
1162511610
if (sib && sib->op_type == OP_CONST) {
1162611611
sib->op_private &= ~OPpCONST_STRICT;
11627-
const_class = cSVOPx(sib)->op_sv;
11612+
const_class = &cSVOPx(sib)->op_sv;
1162811613
}
1162911614
}
11630-
/* cache const class' name to speedup class method calls */
11631-
if (const_class) {
11615+
/* make class name a shared cow string to speedup method calls */
11616+
/* constant string might be replaced with object, f.e. bigint */
11617+
if (const_class && !SvROK(*const_class)) {
1163211618
STRLEN len;
11633-
SV* shared;
11634-
const char* str = SvPV(const_class, len);
11619+
const char* str = SvPV(*const_class, len);
1163511620
if (len) {
11636-
shared = newSVpvn_share(
11637-
str, SvUTF8(const_class) ? -len : len, 0
11621+
SV* const shared = newSVpvn_share(
11622+
str, SvUTF8(*const_class) ? -len : len, 0
1163811623
);
11639-
#ifdef USE_ITHREADS
11640-
op_relocate_sv(&shared, &cMETHOPx(cvop)->op_class_targ);
11641-
#else
11642-
cMETHOPx(cvop)->op_class_sv = shared;
11643-
#endif
11624+
SvREFCNT_dec(*const_class);
11625+
*const_class = shared;
1164411626
}
1164511627
}
1164611628
break;

op.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,6 @@ struct methop {
202202
OP* op_first; /* optree for method name */
203203
SV* op_meth_sv; /* static method name */
204204
} op_u;
205-
#ifdef USE_ITHREADS
206-
PADOFFSET op_class_targ; /* pad index for class name if threaded */
207-
#else
208-
SV* op_class_sv; /* static class name */
209-
#endif
210205
};
211206

212207
struct pmop {
@@ -446,8 +441,6 @@ struct loop {
446441
? cSVOPx(v)->op_sv : PAD_SVl((v)->op_targ))
447442
# define cSVOPx_svp(v) (cSVOPx(v)->op_sv \
448443
? &cSVOPx(v)->op_sv : &PAD_SVl((v)->op_targ))
449-
# define cMETHOPx_class(v) (cMETHOPx(v)->op_class_targ ? \
450-
PAD_SVl(cMETHOPx(v)->op_class_targ) : NULL)
451444
#else
452445
# define cGVOPx_gv(o) ((GV*)cSVOPx(o)->op_sv)
453446
# ifndef PERL_CORE
@@ -456,7 +449,6 @@ struct loop {
456449
# endif
457450
# define cSVOPx_sv(v) (cSVOPx(v)->op_sv)
458451
# define cSVOPx_svp(v) (&cSVOPx(v)->op_sv)
459-
# define cMETHOPx_class(v) (cMETHOPx(v)->op_class_sv)
460452
#endif
461453

462454
# define cMETHOPx_meth(v) cSVOPx_sv(v)

pp_hot.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,27 +3006,27 @@ S_method_common(pTHX_ SV* meth, U32* hashp)
30063006
SV* ob;
30073007
GV* gv;
30083008
HV* stash;
3009-
SV *packsv = NULL, *const_class, *sv;
3009+
SV *packsv = NULL;
30103010

3011-
PERL_ARGS_ASSERT_METHOD_COMMON;
3012-
3013-
if ((const_class = cMETHOPx_class(PL_op))) {
3014-
stash = gv_stashsv(const_class, GV_CACHE_ONLY);
3015-
if (stash) goto fetch;
3016-
}
3017-
3018-
sv = PL_stack_base + TOPMARK == PL_stack_sp
3011+
SV* const sv = PL_stack_base + TOPMARK == PL_stack_sp
30193012
? (Perl_croak(aTHX_ "Can't call method \"%"SVf"\" without a "
30203013
"package or object reference", SVfARG(meth)),
30213014
(SV *)NULL)
30223015
: *(PL_stack_base + TOPMARK + 1);
30233016

3017+
PERL_ARGS_ASSERT_METHOD_COMMON;
3018+
30243019
if (UNLIKELY(!sv))
30253020
undefined:
30263021
Perl_croak(aTHX_ "Can't call method \"%"SVf"\" on an undefined value",
30273022
SVfARG(meth));
30283023

3029-
SvGETMAGIC(sv);
3024+
if (UNLIKELY(SvGMAGICAL(sv))) mg_get(sv);
3025+
else if (SvIsCOW_shared_hash(sv)) { /* MyClass->meth() */
3026+
stash = gv_stashsv(sv, GV_CACHE_ONLY);
3027+
if (stash) goto fetch;
3028+
}
3029+
30303030
if (SvROK(sv))
30313031
ob = MUTABLE_SV(SvRV(sv));
30323032
else if (!SvOK(sv)) goto undefined;

0 commit comments

Comments
 (0)