Skip to content

Commit 5a659e4

Browse files
committed
Perl_sv_setsv_flags: remove unreachable NULL/IV/NV code
The fast code at the top of Perl_sv_setsv_flags now handles all cases where both SVs are < SVt_NV / SVt_IV, depending on the size of NVs. This means that the subsequent code paths involving those combinations are unreachable and can be removed to streamline there function. Note: Doing this actually made a difference with gcc 12.2.0, which didn't seem to figure out that this was possible by itself. Similarly, sprinking some ASSUME() statements around didn't help.
1 parent fbebf96 commit 5a659e4

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

sv.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4310,17 +4310,15 @@ Perl_sv_setsv_flags(pTHX_ SV *dsv, SV* ssv, const I32 flags)
43104310
break;
43114311
case SVt_IV:
43124312
if (SvIOK(ssv)) {
4313+
/* Bodiless-SV code above should have handled these cases */
4314+
assert(dtype != SVt_NULL);
4315+
#if NVSIZE <= IVSIZE
4316+
assert(dtype != SVt_NV);
4317+
#endif
43134318
switch (dtype) {
4314-
case SVt_NULL:
4315-
/* For performance, we inline promoting to type SVt_IV. */
4316-
/* We're starting from SVt_NULL, so provided that define is
4317-
* actual 0, we don't have to unset any SV type flags
4318-
* to promote to SVt_IV. */
4319-
STATIC_ASSERT_STMT(SVt_NULL == 0);
4320-
SET_SVANY_FOR_BODYLESS_IV(dsv);
4321-
SvFLAGS(dsv) |= SVt_IV;
4322-
break;
4319+
#if NVSIZE > IVSIZE
43234320
case SVt_NV:
4321+
#endif
43244322
case SVt_PV:
43254323
sv_upgrade(dsv, SVt_PVIV);
43264324
break;
@@ -4341,17 +4339,21 @@ Perl_sv_setsv_flags(pTHX_ SV *dsv, SV* ssv, const I32 flags)
43414339
}
43424340
if (!SvROK(ssv))
43434341
goto undef_sstr;
4342+
#if NVSIZE > IVSIZE
43444343
if (dtype < SVt_PV && dtype != SVt_IV)
43454344
sv_upgrade(dsv, SVt_IV);
4345+
#endif
43464346
break;
43474347

43484348
case SVt_NV:
43494349
if (LIKELY( SvNOK(ssv) )) {
43504350
switch (dtype) {
4351+
#if NVSIZE > IVSIZE
43514352
case SVt_NULL:
43524353
case SVt_IV:
43534354
sv_upgrade(dsv, SVt_NV);
43544355
break;
4356+
#endif
43554357
case SVt_PV:
43564358
case SVt_PVIV:
43574359
sv_upgrade(dsv, SVt_PVNV);

0 commit comments

Comments
 (0)