Skip to content

Commit 043a9f3

Browse files
committed
Perl_sv_grow_fresh - set SvLEN before calling malloc
The compiler stands a better chance of optimising the function this way around. (e.g. A gcc build reduces from 20 instructions down to 15.)
1 parent 08b6158 commit 043a9f3

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

sv.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,12 +1500,13 @@ Perl_sv_grow_fresh(pTHX_ SV *const sv, STRLEN newlen)
15001500
if (newlen < PERL_STRLEN_NEW_MIN)
15011501
newlen = PERL_STRLEN_NEW_MIN;
15021502

1503-
s = (char*)safemalloc(newlen);
1504-
SvPV_set(sv, s);
1505-
15061503
/* No PERL_UNWARANTED_CHUMMINESS_WITH_MALLOC here, since many strings */
15071504
/* will never be grown once set. Let the real sv_grow worry about that. */
15081505
SvLEN_set(sv, newlen);
1506+
1507+
s = (char*)safemalloc(newlen);
1508+
SvPV_set(sv, s);
1509+
15091510
return s;
15101511
}
15111512

0 commit comments

Comments
 (0)