summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Reisner <reisner.marc@gmail.com>2021-04-05 11:56:29 -0500
committerPaul Evans <leonerd@leonerd.org.uk>2021-04-15 00:12:27 +0100
commit5f65868c2ca80b3ca5d0cebbbaf7241caa69c65f (patch)
tree01f993f9ae4c9c4d6d2c2c20977dab639a0c9693
parent5611ffc345393211770ee36bf0e3782dc7b0dcef (diff)
downloadperl-5f65868c2ca80b3ca5d0cebbbaf7241caa69c65f.tar.gz
Add GV_NOUNIVERSAL flag to skip UNIVERSAL lookup
For the `isa` infix operator, we can fall back to `sv_derived_from_sv` instead of looking up UNIVERSAL::isa. Passing GV_NOUNIVERSAL will tell gv_fetchmeth_internal not to look at UNIVERSAL for the method, and instead return NULL. Then `Perl_sv_isa_sv` will skip the if block and check `sv_derived_from_sv` which does the same thing UNIVERSAL::isa would have done.
-rw-r--r--gv.c2
-rw-r--r--gv.h1
-rw-r--r--universal.c5
3 files changed, 3 insertions, 5 deletions
diff --git a/gv.c b/gv.c
index 861f65c237..4660003a53 100644
--- a/gv.c
+++ b/gv.c
@@ -890,7 +890,7 @@ S_gv_fetchmeth_internal(pTHX_ HV* stash, SV* meth, const char* name, STRLEN len,
}
/* Check UNIVERSAL without caching */
- if(level == 0 || level == -1) {
+ if((level == 0 || level == -1) && !(flags & GV_NOUNIVERSAL)) {
candidate = gv_fetchmeth_internal(NULL, meth, name, len, 1,
flags &~GV_SUPER);
if(candidate) {
diff --git a/gv.h b/gv.h
index 514bac1871..9b465a069d 100644
--- a/gv.h
+++ b/gv.h
@@ -245,6 +245,7 @@ Return the CV from the GV.
/* Flags for gv_fetchmeth_pvn and gv_autoload_pvn*/
#define GV_SUPER 0x1000 /* SUPER::method */
+#define GV_NOUNIVERSAL 0x2000 /* Skip UNIVERSAL lookup */
/* Flags for gv_autoload_*/
#define GV_AUTOLOAD_ISMETHOD 1 /* autoloading a method? */
diff --git a/universal.c b/universal.c
index b839e5151d..5932767bdf 100644
--- a/universal.c
+++ b/universal.c
@@ -216,10 +216,7 @@ Perl_sv_isa_sv(pTHX_ SV *sv, SV *namesv)
if(!SvROK(sv) || !SvOBJECT(SvRV(sv)))
return FALSE;
- /* TODO: Consider if we want a NOUNIVERSAL flag to skip the
- * UNIVERSAL lookup
- */
- isagv = gv_fetchmeth_pvn(SvSTASH(SvRV(sv)), "isa", 3, -1, 0);
+ isagv = gv_fetchmeth_pvn(SvSTASH(SvRV(sv)), "isa", 3, -1, GV_NOUNIVERSAL);
if(isagv) {
dSP;
CV *isacv = isGV(isagv) ? GvCV(isagv) : (CV *)isagv;