Skip to content

Commit 35a285a

Browse files
committed
gv_magicalize: Quickly rule non-magical input out
This uses the data structure introduced in the previous commit to quickly test the input first character. If it isn't a potential magical one, it could apply to CORE, so move the block that checks for that to here, eliminating a conditional. In either case, no need to look further.
1 parent 5ed61ab commit 35a285a

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

gv.c

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,6 +2090,20 @@ S_gv_magicalize(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len,
20902090
return false;
20912091
}
20922092

2093+
if (! generic_isCC_(*name, CC_MAGICAL_)) {
2094+
2095+
/* If not a magical variable, it could be for CORE */
2096+
try_core:
2097+
if (len > 1 /* shortest is uc */ && HvNAMELEN_get(stash) == 4) {
2098+
/* Avoid null warning: */
2099+
const char * const stashname = HvNAME(stash); assert(stashname);
2100+
if (strBEGINs(stashname, "CORE"))
2101+
S_maybe_add_coresub(aTHX_ 0, gv, name, len);
2102+
}
2103+
2104+
goto ret;
2105+
}
2106+
20932107
if (stash != PL_defstash) { /* not the main stash */
20942108
/* We only have to check for a few names here: a, b, EXPORT, ISA
20952109
and VERSION. All the others apply only to the main stash or to
@@ -2127,31 +2141,8 @@ S_gv_magicalize(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len,
21272141
goto try_core;
21282142
}
21292143
goto ret;
2130-
try_core:
2131-
if (len > 1 /* shortest is uc */ && HvNAMELEN_get(stash) == 4) {
2132-
/* Avoid null warning: */
2133-
const char * const stashname = HvNAME(stash); assert(stashname);
2134-
if (strBEGINs(stashname, "CORE"))
2135-
S_maybe_add_coresub(aTHX_ 0, gv, name, len);
2136-
}
21372144
}
21382145
else if (len > 1) {
2139-
#ifndef EBCDIC
2140-
if (*name > 'V' ) {
2141-
NOOP;
2142-
/* Nothing else to do.
2143-
The compiler will probably turn the switch statement into a
2144-
branch table. Make sure we avoid even that small overhead for
2145-
the common case of lower case variable names. (On EBCDIC
2146-
platforms, we can't just do:
2147-
if (NATIVE_TO_ASCII(*name) > NATIVE_TO_ASCII('V') ) {
2148-
because cases like '\027' in the switch statement below are
2149-
C1 (non-ASCII) controls on those platforms, so the remapping
2150-
would make them larger than 'V')
2151-
*/
2152-
} else
2153-
#endif
2154-
{
21552146
switch (*name) {
21562147
case 'A':
21572148
if (memEQs(name, len, "ARGV")) {
@@ -2313,7 +2304,6 @@ S_gv_magicalize(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len,
23132304
goto storeparen;
23142305
}
23152306
}
2316-
}
23172307
} else {
23182308
/* Names of length 1. (Or 0. But name is NUL terminated, so that will
23192309
be case '\0' in this switch statement (ie a default case) */

0 commit comments

Comments
 (0)