summaryrefslogtreecommitdiff
path: root/gv.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2013-08-28 22:00:54 +0200
committerNicholas Clark <nick@ccl4.org>2013-09-02 16:04:02 +0200
commite91d825996027800803ecf00fccacdcb821d3295 (patch)
tree1f9f89122222a764a475b6098ac52bbdbaafc05d /gv.c
parente1c60bf347fcb74764d4f3baf79980d3252ccf0a (diff)
downloadperl-e91d825996027800803ecf00fccacdcb821d3295.tar.gz
Store the match vars in mg_len instead of calling atoi() on mg_ptr.
The match variables $1, $2 etc, along with many other special scalars, have magic type PERL_MAGIC_sv, with the variable's name stored in mg_ptr. The look up in mg.c involved calling atoi() on the string in mg_ptr to get the capture buffer as an integer, which is passed to the regex API. To avoid this repeated use of atoi() at runtime, change the storage in the MAGIC structure for $1, $2 etc and $&. Set mg_ptr to NULL, and store the capture buffer in mg_len. Other code which manipulates magic ignores mg_len if mg_ptr is NULL, so this representation does not require changes outside of the routines which set up, read and write these variables. (Perl_gv_fetchpvn_flags(), Perl_magic_get() and Perl_magic_set())
Diffstat (limited to 'gv.c')
-rw-r--r--gv.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/gv.c b/gv.c
index d6edbfd01e..f6d4836365 100644
--- a/gv.c
+++ b/gv.c
@@ -1871,7 +1871,9 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
while (--end > name) {
if (!isDIGIT(*end)) goto add_magical_gv;
}
- goto magicalize;
+ sv_magic(GvSVn(gv), MUTABLE_SV(gv), PERL_MAGIC_sv, NULL,
+ strtoul(name, NULL, 10));
+ break;
}
}
}
@@ -1897,7 +1899,23 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
: SAWAMPERSAND_RIGHT;
}
#endif
- goto magicalize;
+ if (*name != '&')
+ goto magicalize;
+ /* FALL THROUGH */
+ case '1': /* $1 */
+ case '2': /* $2 */
+ case '3': /* $3 */
+ case '4': /* $4 */
+ case '5': /* $5 */
+ case '6': /* $6 */
+ case '7': /* $7 */
+ case '8': /* $8 */
+ case '9': /* $9 */
+ /* Flag the capture variables with a NULL mg_ptr
+ Use mg_len for the array index to lookup. */
+ sv_magic(GvSVn(gv), MUTABLE_SV(gv), PERL_MAGIC_sv, NULL,
+ *name == '&' ? 0 : *name - '0');
+ break;
case ':': /* $: */
sv_setpv(GvSVn(gv),PL_chopset);
@@ -1973,15 +1991,6 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
SvREADONLY_on(GvSVn(gv));
/* FALL THROUGH */
case '0': /* $0 */
- case '1': /* $1 */
- case '2': /* $2 */
- case '3': /* $3 */
- case '4': /* $4 */
- case '5': /* $5 */
- case '6': /* $6 */
- case '7': /* $7 */
- case '8': /* $8 */
- case '9': /* $9 */
case '^': /* $^ */
case '~': /* $~ */
case '=': /* $= */