summaryrefslogtreecommitdiff
path: root/toke.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-11-06 14:04:51 -0800
committerFather Chrysostomos <sprout@cpan.org>2011-11-06 14:23:49 -0800
commit0abcdfa4c5da571f9a31d50e4a121867868e8aaf (patch)
tree69628a02e27d839663e8073694d0c9a88a782905 /toke.c
parentbc344123285ead072c87437a15e486ff36fef609 (diff)
downloadperl-0abcdfa4c5da571f9a31d50e4a121867868e8aaf.tar.gz
Avoid redundant copies in string evals
Perl_lex_start copies the string passed to it unconditionally. Sometimes pp_entereval makes a copy before passing the string to lex_start. So in those cases we can pass a flag to avoid a redundant copy.
Diffstat (limited to 'toke.c')
-rw-r--r--toke.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/toke.c b/toke.c
index 6e88c8a25c..1431cc377d 100644
--- a/toke.c
+++ b/toke.c
@@ -726,16 +726,13 @@ Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, U32 flags)
if (line) {
s = SvPV_const(line, len);
- } else {
- len = 0;
- }
-
- if (!len) {
- parser->linestr = newSVpvs("\n;");
- } else {
- parser->linestr = newSVpvn_flags(s, len, SvUTF8(line));
+ parser->linestr = flags & LEX_START_COPIED
+ ? SvREFCNT_inc_simple_NN(line)
+ : newSVpvn_flags(s, len, SvUTF8(line));
if (s[len-1] != ';')
sv_catpvs(parser->linestr, "\n;");
+ } else {
+ parser->linestr = newSVpvs("\n;");
}
parser->oldoldbufptr =
parser->oldbufptr =