Skip to content

Commit 709d0a4

Browse files
committed
sv.c: newSV* functions now use sv_upgrade_fresh
Most of the various newSV* functions modified in this commit all aquire a new SV head and upgrade it to a specific PV type of choice. Changing the call from sv_upgrade(sv, type) to sv_upgrade_fresh(sv,type) allows for the inlining of only the relevant body allocation code into these functions. The exception to the above is Perl_newSV_type, which takes the target type as a parameter. For some callers, the target types may not be known until runtime. In this case, the entirety of Perl_sv_upgrade_fresh will be inlined. The growth in the size of the compiled perl binary is small (only about 40 bytes, at least on x64 using gcc or clang).
1 parent 8802b94 commit 709d0a4

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

sv.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5650,7 +5650,7 @@ Perl_newSV(pTHX_ const STRLEN len)
56505650

56515651
new_SV(sv);
56525652
if (len) {
5653-
sv_upgrade(sv, SVt_PV);
5653+
sv_upgrade_fresh(sv, SVt_PV);
56545654
sv_grow_fresh(sv, len + 1);
56555655
}
56565656
return sv;
@@ -9462,7 +9462,7 @@ Perl_newSVpvn_flags(pTHX_ const char *const s, const STRLEN len, const U32 flags
94629462
And we're new code so I'm going to assert this from the start. */
94639463
assert(!(flags & ~(SVf_UTF8|SVs_TEMP)));
94649464
new_SV(sv);
9465-
sv_upgrade(sv, SVt_PV);
9465+
sv_upgrade_fresh(sv, SVt_PV);
94669466
sv_setpvn_fresh(sv,s,len);
94679467

94689468
/* This code used to do a sv_2mortal(), however we now unroll the call to
@@ -9533,7 +9533,7 @@ Perl_newSVpv(pTHX_ const char *const s, const STRLEN len)
95339533
SV *sv;
95349534

95359535
new_SV(sv);
9536-
sv_upgrade(sv, SVt_PV);
9536+
sv_upgrade_fresh(sv, SVt_PV);
95379537
sv_setpvn_fresh(sv, s, len || s == NULL ? len : strlen(s));
95389538
return sv;
95399539
}
@@ -9556,7 +9556,7 @@ Perl_newSVpvn(pTHX_ const char *const buffer, const STRLEN len)
95569556
{
95579557
SV *sv;
95589558
new_SV(sv);
9559-
sv_upgrade(sv, SVt_PV);
9559+
sv_upgrade_fresh(sv, SVt_PV);
95609560
sv_setpvn_fresh(sv,buffer,len);
95619561
return sv;
95629562
}
@@ -9613,7 +9613,7 @@ Perl_newSVhek(pTHX_ const HEK *const hek)
96139613
SV *sv;
96149614

96159615
new_SV(sv);
9616-
sv_upgrade(sv, SVt_PV);
9616+
sv_upgrade_fresh(sv, SVt_PV);
96179617
SvPV_set(sv, (char *)HEK_KEY(share_hek_hek(hek)));
96189618
SvCUR_set(sv, HEK_LEN(hek));
96199619
SvLEN_set(sv, 0);
@@ -9661,7 +9661,7 @@ Perl_newSVpvn_share(pTHX_ const char *src, I32 len, U32 hash)
96619661
new_SV(sv);
96629662
/* The logic for this is inlined in S_mro_get_linear_isa_dfs(), so if it
96639663
changes here, update it there too. */
9664-
sv_upgrade(sv, SVt_PV);
9664+
sv_upgrade_fresh(sv, SVt_PV);
96659665
SvPV_set(sv, sharepvn(src, is_utf8?-len:len, hash));
96669666
SvCUR_set(sv, len);
96679667
SvLEN_set(sv, 0);
@@ -9867,7 +9867,7 @@ Perl_newSV_type(pTHX_ const svtype type)
98679867
new_SV(sv);
98689868
ASSUME(SvTYPE(sv) == SVt_FIRST);
98699869
if(type != SVt_FIRST)
9870-
sv_upgrade(sv, type);
9870+
sv_upgrade_fresh(sv, type);
98719871
return sv;
98729872
}
98739873

0 commit comments

Comments
 (0)