summaryrefslogtreecommitdiff
path: root/pp_ctl.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2007-10-09 20:45:49 +0000
committerNicholas Clark <nick@ccl4.org>2007-10-09 20:45:49 +0000
commitb640a14ad99660810209db046b8d70831781c646 (patch)
tree1c1b1b07fe5b63ff535879914aed68984b810411 /pp_ctl.c
parent0786552a25399b1ea99930f794f6bf1973823a24 (diff)
downloadperl-b640a14ad99660810209db046b8d70831781c646.tar.gz
Replace Perl_sv_setpvf(aTHX_ namesv, "%s/%s", dir, name); in require's
loop over @INC with direct perl API calls that allocate sufficient memory up front, avoid the need to parse a format string, and avoid the need to call strlen() on either parameter. p4raw-id: //depot/perl@32087
Diffstat (limited to 'pp_ctl.c')
-rw-r--r--pp_ctl.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index d9251711ef..021307484f 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3222,6 +3222,7 @@ PP(pp_require)
#endif
{
namesv = newSV(0);
+ sv_upgrade(namesv, SVt_PV);
for (i = 0; i <= AvFILL(ar); i++) {
SV * const dirsv = *av_fetch(ar, i, TRUE);
@@ -3351,7 +3352,16 @@ PP(pp_require)
|| (*name == ':' && name[1] != ':' && strchr(name+2, ':'))
#endif
) {
- const char *dir = SvOK(dirsv) ? SvPV_nolen_const(dirsv) : "";
+ const char *dir;
+ STRLEN dirlen;
+
+ if (SvOK(dirsv)) {
+ dir = SvPV_const(dirsv, dirlen);
+ } else {
+ dir = "";
+ dirlen = 0;
+ }
+
#ifdef MACOS_TRADITIONAL
char buf1[256];
char buf2[256];
@@ -3379,7 +3389,26 @@ PP(pp_require)
"%s\\%s",
dir, name);
# else
- Perl_sv_setpvf(aTHX_ namesv, "%s/%s", dir, name);
+ /* The equivalent of
+ Perl_sv_setpvf(aTHX_ namesv, "%s/%s", dir, name);
+ but without the need to parse the format string, or
+ call strlen on either pointer, and with the correct
+ allocation up front. */
+ {
+ char *tmp = SvGROW(namesv, dirlen + len + 2);
+
+ memcpy(tmp, dir, dirlen);
+ tmp +=dirlen;
+ *tmp++ = '/';
+ /* name came from an SV, so it will have a '\0' at the
+ end that we can copy as part of this memcpy(). */
+ memcpy(tmp, name, len + 1);
+
+ SvCUR_set(namesv, dirlen + len + 1);
+
+ /* Don't even actually have to turn SvPOK_on() as we
+ access it directly with SvPVX() below. */
+ }
# endif
# endif
#endif