summaryrefslogtreecommitdiff
path: root/locale.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2022-07-28 16:46:18 -0600
committerKarl Williamson <khw@cpan.org>2022-08-22 06:52:08 -0600
commit692d08c5148904dec25634369d9e81ede7ff18ee (patch)
tree06ae654d810e65ec34a8e13358a821f26efbe6b1 /locale.c
parent0630bfb430250bb03e7cc017db4aae28541ff68a (diff)
downloadperl-692d08c5148904dec25634369d9e81ede7ff18ee.tar.gz
locale.c: Add branch prediction, comments
Diffstat (limited to 'locale.c')
-rw-r--r--locale.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/locale.c b/locale.c
index 184f698424..41f9ef1bdb 100644
--- a/locale.c
+++ b/locale.c
@@ -3913,8 +3913,13 @@ S_my_langinfo_i(pTHX_
const Size_t initial_size = 10;
Newx(floatbuf, initial_size, char);
+
+ /* 1.5 is exactly representable on binary computers */
Size_t needed_size = snprintf(floatbuf, initial_size, "%.1f", 1.5);
- if (needed_size >= initial_size) {
+
+ /* If our guess wasn't big enough, increase and try again, based on
+ * the real number that strnprintf() is supposed to return */
+ if (UNLIKELY(needed_size >= initial_size)) {
needed_size++; /* insurance */
Renew(floatbuf, needed_size, char);
Size_t new_needed = snprintf(floatbuf, needed_size, "%.1f", 1.5);
@@ -3941,7 +3946,7 @@ S_my_langinfo_i(pTHX_
}
/* Everything in between is the radix string */
- if (s < e) {
+ if (LIKELY(s < e)) {
*s = '\0';
retval = save_to_buffer(item_start,
(const char **) &PL_langinfo_buf,
@@ -3967,7 +3972,9 @@ S_my_langinfo_i(pTHX_
# endif
# ifdef HAS_SOME_LOCALECONV
- /* These items are available from localeconv(). */
+ /* These items are available from localeconv(). (To avoid using
+ * TS_W32_BROKEN_LOCALECONV, one could use GetNumberFormat and
+ * GetCurrencyFormat; patches welcome) */
case CRNCYSTR:
case THOUSEP: