Skip to content

Commit 615f3b4

Browse files
khwilliamsonLeont
authored andcommitted
vutil.c: Extract code into a macro
This is in preparation for future commits to call it from more than a single place.
1 parent 32ffb74 commit 615f3b4

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

vutil/vutil.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,26 @@ to force this SV to be interpreted as an "extended" version.
564564
=cut
565565
*/
566566

567+
/* Macro to do the meat of getting the PV of an NV version number. This is
568+
* macroized because can be called from several places */
569+
#define GET_NUMERIC_VERSION(ver, sv, tbuf, buf, len) \
570+
STMT_START { \
571+
\
572+
/* We earlier created 'sv' for very large version numbers, to rely \
573+
* on the specialized algorithms SV code has built-in for such \
574+
* values */ \
575+
if (sv) { \
576+
Perl_sv_setpvf(aTHX_ sv, "%.9" NVff, SvNVX(ver)); \
577+
len = SvCUR(sv); \
578+
buf = SvPVX(sv); \
579+
} \
580+
else { \
581+
len = my_snprintf(tbuf, sizeof(tbuf), "%.9" NVff, SvNVX(ver)); \
582+
buf = tbuf; \
583+
} \
584+
\
585+
} STMT_END
586+
567587
SV *
568588
#ifdef VUTIL_REPLACE_CORE
569589
Perl_upg_version2(pTHX_ SV *ver, bool qv)
@@ -693,15 +713,7 @@ Perl_upg_version(pTHX_ SV *ver, bool qv)
693713
/* Prevent recursed calls from trying to change back */
694714
LOCK_LC_NUMERIC_STANDARD();
695715
#endif
696-
if (sv) {
697-
Perl_sv_setpvf(aTHX_ sv, "%.9" NVff, SvNVX(ver));
698-
len = SvCUR(sv);
699-
buf = SvPVX(sv);
700-
}
701-
else {
702-
len = my_snprintf(tbuf, sizeof(tbuf), "%.9" NVff, SvNVX(ver));
703-
buf = tbuf;
704-
}
716+
GET_NUMERIC_VERSION(ver, sv, tbuf, buf, len);
705717

706718
#ifdef USE_LOCALE_NUMERIC
707719

0 commit comments

Comments
 (0)