From 0c09c4e2b5d2859815482daac87e8fa46a04c613 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 13 Apr 2025 20:23:57 +0200 Subject: [PATCH] vasnprintf: Optimize last commit. * lib/vasnprintf.c (VASNPRINTF): Optimize a few loops. --- ChangeLog | 3 +++ lib/vasnprintf.c | 31 ++++++++++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3415818382..c766cc9cca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2025-04-13 Bruno Haible + vasnprintf: Optimize last commit. + * lib/vasnprintf.c (VASNPRINTF): Optimize a few loops. + vasnprintf: Consider the grouping rule. Reported by Pádraig Brady. * lib/vasnprintf.c (grouping_rule, num_thousands_separators): New diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index d7e96ac5a6..949e14fb17 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -5247,9 +5247,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, int h = *g; if (h <= 0) abort (); - int i; - for (i = h; i > 0; i--) + int i = h; + do *--p = *digitp++; + while (--i > 0); # if WIDE_CHAR_VERSION *--p = thousep[0]; # else @@ -5572,9 +5573,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, int h = *g; if (h <= 0) abort (); - int i; - for (i = h; i > 0; i--) + int i = h; + do *--p = *digitp++; + while (--i > 0); # if WIDE_CHAR_VERSION *--p = thousep[0]; # else @@ -5846,9 +5848,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, int h = *g; if (h <= 0) abort (); - int i; - for (i = h; i > 0; i--) + int i = h; + do *--p = *digitp++; + while (--i > 0); # if WIDE_CHAR_VERSION *--p = thousep[0]; # else @@ -6179,9 +6182,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, int h = *g; if (h <= 0) abort (); - int i; - for (i = h; i > 0; i--) + int i = h; + do *--p = *digitp++; + while (--i > 0); # if WIDE_CHAR_VERSION *--p = thousep[0]; # else @@ -7555,14 +7559,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, int h = *g; if (h <= 0) abort (); - int i; - for (i = h; i > 0; i--) + int i = h; + do *--q = *--p; + while (--i > 0); # if WIDE_CHAR_VERSION && DCHAR_IS_TCHAR - *--q = *thousep; + *--q = *thousep; # else - q -= thousep_len; - memcpy (q, thousep, thousep_len); + q -= thousep_len; + memcpy (q, thousep, thousep_len); # endif insert--; if (insert == 0) -- 2.39.5