Skip to content

toke.c - only try to shrink an SV buffer when conceivably possible #23293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: blead
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions toke.c
Original file line number Diff line number Diff line change
Expand Up @@ -4421,8 +4421,9 @@ S_scan_const(pTHX_ char *start)
SvUTF8_on(sv);
}

/* shrink the sv if we allocated more than we used */
if (SvCUR(sv) + 5 < SvLEN(sv)) {
/* shrink the sv if we allocated more than we used - and conceivably
* could actually shrink it */
if (SvCUR(sv) + 2 + PTRSIZE < SvLEN(sv)) {
SvPV_shrink_to_cur(sv);
}

Expand Down Expand Up @@ -9793,7 +9794,9 @@ Perl_yylex(pTHX)
PL_parser->lex_shared->re_eval_str = NULL;
SvCUR_set(sv,
PL_bufptr - PL_parser->lex_shared->re_eval_start);
SvPV_shrink_to_cur(sv);
if (SvCUR(sv) + PTRSIZE + 2 < SvLEN(sv)) {
SvPV_shrink_to_cur(sv);
}
}
else sv = newSVpvn(PL_parser->lex_shared->re_eval_start,
PL_bufptr - PL_parser->lex_shared->re_eval_start);
Expand Down Expand Up @@ -11348,7 +11351,7 @@ S_scan_heredoc(pTHX_ char *s)
SvREFCNT_dec_NN(newstr);
}

if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
if (SvCUR(tmpstr) + 2 + PTRSIZE < SvLEN(tmpstr)) {
SvPV_shrink_to_cur(tmpstr);
}

Expand Down Expand Up @@ -11877,8 +11880,7 @@ Perl_scan_str(pTHX_ char *start, int keep_bracketed_quoted, int keep_delims, int
PL_parser->herelines = herelines;

/* if we allocated too much space, give some back */
if (SvCUR(sv) + 5 < SvLEN(sv)) {
SvLEN_set(sv, SvCUR(sv) + 1);
if (SvCUR(sv) + 2 + PTRSIZE < SvLEN(sv)) {
SvPV_shrink_to_cur(sv);
}

Expand Down
Loading